标签:fir instance this oss sse net message static 变量
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!
程序要求:
Priests, devils, stone, river, boat
实现思路:
Model: Coast, Boat, Character
View: UserGUI
Controller: BoatController, CoastController, CharacterController, FirstController, Director
给定 Model 属性和值域
枚举变量是很好的状态标记辅助变量,可以避免记忆整数标识的状态,而采用易懂的变量名替代。
1 | public enum Location { left, right } |
View 实现
实现各 Controller 和 Director
Director 采取单例模式
1 | public class Director : System.Object { |
Controller 代码见 github。
其中,需要注意,上下船动作虽然简单,但也应该分解为,人物上/下船,船上/下人物,人物上/下岸,岸上/下人物。因为这个动作的结果会对三个 GameObject 造成影响,所以我们要通知三个 GameObject 让其进行状态更新。 这一点尤其要注意。
GameObject 运动脚本
实现参考博客
原文:大专栏 Unity-牧师与魔鬼
标签:fir instance this oss sse net message static 变量
原文地址:https://www.cnblogs.com/wangziqiang123/p/11618283.html