编程实践——Priests and Devils 动作分离版
Priests and Devils is a puzzle game in which you will help the Priests and Devils to cross the river within the time limit. There are 3 priests and 3 devils at one side of the river. They all want to get to the other side of this river, but there is only one boat and this boat can only carry two persons each time. And there must be one person steering the boat from one side to the other side. In the flash game, you can click on them to move them and click the go button to move the boat to the other direction. If the priests are out numbered by the devils on either side of the river, they get killed and the game is over. You can try it in many > ways. Keep all priests alive! Good luck!
-
游戏中提及的事物有:河岸Coast(包括起始河岸和目的河岸),河River,3个牧师Priests,3个魔鬼Devils,船。
-
玩家动作表:
事物 牧师/魔鬼 从河岸上船 牧师/魔鬼 从船上河岸 船 从河岸行驶到另一河岸 -
预制游戏中的对象:
-
在 GameObjects 中创建 长方形、正方形、球 及其色彩代表游戏中的对象:
我用金色的方块代表牧师,红色的球代表恶魔,蓝色的细长长方体代表河流,带有纹理的方块代表河岸,方块代表船,游戏效果图如下:
本次实践依然是采用MVC结构实现,与上一次无动作分离版的区别在于,之前对于动作的管理是实现了一个动作类,当鼠标点击船或是人物时,相当于是控制器让船或人物的实例调用动作类来实现运动。这次实践中将船或人物与动作分离开来,单独实现了一个动作管理器,鼠标点击船或是人物时,相当于是控制器直接将动作请求传给动作管理器,动作管理器来实现船或人物的运动。
接下来介绍动作管理器的实现:
-
SSActionManager
(动作管理基类)
管理SequenceAction
和SSAction
,可以给它们传递游戏对象,让游戏对象做动作或是一连串的动作,控制动作的切换。SSActionManager
继承了ISSActionCall