求助:简单游戏DCI应用设计

12-10-24 kyngtak
看了几个月觉得已经懂了, 下手写的时候发现还是一头雾水.

我想做一个简单的三连消去游戏(3-Match, 我想大家都知道是什么样游戏吧). 试着做了一下抽象得出结论:
"依照某种规则移动棋盘中的棋子",
另一句描述"连续的三个或以上棋子则消去", 前半句属于算法规则, "消去"属于移动, 所以这一句就没加入设计.

依据DDD分析:
role: "棋子", "规则", "棋盘"(棋子集合)
mi: "棋子移动", "规则审核"

但做DCI设计编写的时候却比DDD多了数据角色
role:棋子, 棋子集合简版(审核用), 棋子集合完全版(移动用), 规则块

data: 棋子

ackage scenarios.datas.vo
{
	public dynamic class VOPiece
	{
		public var id:int;
		
		public var color:int;
		
		public var state:int;
		
		public var alter:String = "???";
		
		public var target:Object;
	}
}
<p class="indent">


data: 棋子集合简版:(例子)

private var grid:Array = 
<p class="indent">[
	[1,2,3,4,3,4,6,3],
	[4,5,2,3,6,3,2,3],
	...
	...
	...
]
<p class="indent">


data: 棋子集合完全版:(例子)

private var grid:Array = 
<p class="indent">[
	[VOPiece,VOPiece,VOPiece,VOPiece,VOPiece,VOPiece,VOPiece,VOPiece],
	[...],
	...
	...
	...
]
<p class="indent">


规则块自身没数据

所以上下文也多了
context:"棋子移动", "棋子集合依照规则审批", "棋子集合数据的扩充与分配"

代码写到这, 已经找不出"什么人以什么样的角色"这种分析条件了, 到底这个移动规则审核是不是应该独立出现, 如果不独立出现又应该载入那个场景呢

附代码段, as3可以看成java化的js

审核:

package scenarios.audit.contexts 
{
	import ****;

	public class ContextAudit implements IConAudit
	{
		private var $core:IProxCore;
		
		private var $audit:IModAudit;
		
		public function ContextAudit():void { this.init(); }
		
		private function init():void
		{
			this.$core = UtilMap.acquire(ProxCore) as IProxCore;
			
			this.$audit = UtilMap.acquire(ModAudit) as IModAudit; 
		}
		
		//-----------------------------------------
		
		public function build():void 
		{ 
			this.$core.queue = $audit.build();
		}
		
		public function updata(value:Array):void { }
	}
}
<p class="indent">


分配:

package scenarios.assign.contexts 
{
	import ***

	public class ContextAssign implements IConAssign
	{
		private var $core:IProxCore;
		
		private var $list:IProxPieceList;
		
		private var $assign:IModAssign;
		
		private var $mediator:MedBroad;
		
		//-----------------------------------------
		
		public function ContextAssign():void { this.init(); }
		
		private function init():void
		{
			this.$core = UtilMap.acquire(ProxCore) as IProxCore;
			
			this.$list = UtilMap.acquire(ProxPieceList) as IProxPieceList;
			
			this.$assign = UtilMap.acquire(ModAssign) as IModAssign;
			
			this.$mediator = UtilMap.acquire(MedBroad) as MedBroad;
		}
		
		//-----------------------------------------
		
		public function updata():void 
		{ 
			if ($core.length) 
			{ 
				this.$assign.updata($core.queue, $list.pieces);
			}
			
			else {}
		}
		
	}
}
<p class="indent">


移动: 不止包含移动还有其他形式变化

package scenarios.alter.contexts 
{
	import ***
	
	public class ContextAlter implements IConAlter
	{
		public static var ALTERS:Object = { "build":FunShift, "move":FunShift, "easing":FunShift, "alpha":FunShift };//等扩展
		
		public static var OPERANDS:Object = 
		[
			new BitmapData(50, 50, true, 0xFFFFFFFF), 
			new BitmapData(50, 50, true, 0xFF00FFFF), 
			new BitmapData(50, 50, true, 0xFFFF00FF), 
			new BitmapData(50, 50, true, 0xFFFFFF00), 
			new BitmapData(50, 50, true, 0xFF0000FF), 
			new BitmapData(50, 50, true, 0xFFFF0000), 
			new BitmapData(50, 50, true, 0xFFAAAAAA), 
		];    //颜色更换
		
		//---------------------------------------------------------------------
		
		private var $source:MedBroad;    //mediator
		
		private var $core:VOPiece = null;    //数据
		
		private var $alter:IFunAlter = null;	//更换不同的alter组件 实现不同的操作功能
		
		private var $operand:DisplayObject = null;    //操作试图
		
		public function active(value:VOPiece):void 
		{
			this.$core = value;
			
			this.configOperand();
			
			this.configAlter();
			
			this.$alter.core = $core;
			this.$alter.operand = $operand;
			this.$alter.callback = callback;
			
			this.$alter.active();
		}
		
		//---------------------------------------------------------------------
		
		private function configAlter():void
		{
			var alter:String = $core.alter;
			
			if ($alter) { this.$alter.clean(); }
			
			this.$alter = new FunShift();
		}
		
		private function configOperand():void
		{
			var color:int = $core.color;
			
			var bitmapdata:BitmapData = ContextAlter.OPERANDS[color];
			
			var source:Array = (UtilMap.acquire(MedBroad) as MedBroad).group;
			
			var container:Container = source[$core.id];
			
			container.content = (new Image(Texture.fromBitmapData(bitmapdata)));
			
			this.$operand = container;
		}
		
		private function callback():void
		{
			
		}
	}
}
<p class="indent">


希望得到高手们的指点, 在此先谢过.

[该贴被kyngtak于2012-10-24 11:11修改过]

[该贴被kyngtak于2012-10-24 11:17修改过]

[该贴被kyngtak于2012-10-24 11:34修改过]

banq
2012-10-25 16:59
规则审核属于一种规格specification模式吧,属于一种约束输出,虽然有行为,但是不是重点,重点规则上,属于结构性方面,可以建立一个棋子规则的代理对象,类似DDD中的Cargo案例的运输目的Goal.

kyngtak
2012-10-25 19:20
非常感谢banq兄的指点, 我照这个例子思考一下该怎么写.

主要是纯前端出身不做server而且还改去做项目管理了, 理解有点吃力.

[该贴被kyngtak于2012-10-25 19:52修改过]

猜你喜欢