求助:簡單遊戲DCI應用設計

kyngtak發表於2012-10-24
看了幾個月覺得已經懂了, 下手寫的時候發現還是一頭霧水.

我想做一個簡單的三連消去遊戲(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修改過]

相關文章