牧师与魔鬼

作业内容

1、简答并用程序验证【建议做】

  • 游戏对象运动的本质是什么?
  • 请用三种方法以上方法,实现物体的抛物线运动。(如,修改Transform属性,使用向量Vector3的方法…)
  • 写一个程序,实现一个完整的太阳系, 其他星球围绕太阳的转速必须不一样,且不在一个法平面上。

2、编程实践

  • 阅读以下游戏脚本

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!

程序需要满足的要求:

  • play the game ( http://www.flash-game.net/game/2535/priests-and-devils.html )
  • 列出游戏中提及的事物(Objects)
  • 用表格列出玩家动作表(规则表),注意,动作越少越好
  • 请将游戏中对象做成预制
  • 在 GenGameObjects 中创建 长方形、正方形、球 及其色彩代表游戏中的对象。
  • 使用 C# 集合类型 有效组织对象
  • 整个游戏仅 主摄像机 和 一个 Empty 对象, 其他对象必须代码动态生成!!! 。 整个游戏不许出现 Find 游戏对象, SendMessage 这类突破程序结构的 通讯耦合 语句。 违背本条准则,不给分
  • 请使用课件架构图编程,不接受非 MVC 结构程序
  • 注意细节,例如:船未靠岸,牧师与魔鬼上下船运动中,均不能接受用户事件!

首先列出游戏中提及的事物,他们是牧师,魔鬼,水流,船,河岸(还有光照和摄像头)

随后列出玩家的动作表

动作参数结果
启动游戏游戏初始界面
点击角色船的位置,船的状态结束/未结束
点击船船上人数结束/未结束
程序设计

不妨把这个游戏想象成一场电影的拍摄。

首先我们需要一个总导演SSDirector,导演啥也不干,就和其他负责人交接。当然导演只能有一个,我们使用单例模式来实例化导演,这样导演就能轻易协调各部分的工作

那么这样的负责人是谁呢,就是ISceneController(接口),我们称他为场记。

只有场记还不行,还得有一个动作表来告诉场记自己需要做什么,这个动作表就是IUserAction(接口).

那么我们现在就招募到了一个知道自己该做什么的场记,我们称他为FirstController,这是我们的首号场记(继承了ISceneController和IUserAction)。

首号场记表示不能所有的活都自己干,得招募一些小弟。比如说当前这个场景,要招募3个人,分别负责船,角色和岸边。他们分别是BoatController,MycharaController,CoastController,我们称他们为船夫,人事经理,地母

这时船夫和人事经理说,自己管理的东西/人都需要移动,那我们必须给他们一个工具,只要输入目的地的位置,就可以移动了,这个工具就叫做Moveable.

有了上面这些人,我们就可以操控用户界面(UserGUI)中的物体了。

为上面的每一个人明确好任务之后,就可以画出UML图:

在这里插入图片描述

只要关系明确了,代码并不难写(尤其是在可以抄的情况下)。这样的话我就简单介绍三位地位低下的工具人。在此之前,我们需要知道为了减少代码的耦合性,三位工具人必须分工明确,明确自己的任务是什么。

BoatController的任务大体来说有四个:

  • 移动船(使用给出的工具Moveable即可)

    		public void Move() {
    			if (to_or_from == -1) {
    				moveableScript.setDestination(fromPosition);
    				to_or_from = 1;
    			} else {
    				moveableScript.setDestination(toPosition);
    				to_or_from = -1;
    			}
    		}
    
  • 装货 (有空位就装,没空位拉倒)

    		public void GetOnBoat(MyCharacterController characterCtrl) {
    			int index = getEmptyIndex ();
    			passenger [index] = characterCtrl;
    		}
    
  • 卸货(从货仓搬出去)

    		public MyCharacterController GetOffBoat(string passenger_name) {
    			for (int i = 0; i < passenger.Length; i++) {
    				if (passenger [i] != null && passenger [i].getName () == passenger_name) {
    					MyCharacterController charactorCtrl = passenger [i];
    					passenger [i] = null;
    					return charactorCtrl;
    				}
    			}
    			Debug.Log ("Cant find passenger in boat: " + passenger_name);
    			return null;
    		}
    
  • 配合首号场记

MyCharaController的任务大体有三个:

  • 上船(想上船必须先认亲,不然船夫不带自己走)

    		public void getOnBoat(BoatController boatCtrl) {
    			character.transform.parent = boatCtrl.getGameobj().transform;
    			moveableScript.setDestination(boatCtrl.getEmptyPosition());
    			_isOnBoat = true;
    		}
    
  • 下船(一下船立刻断绝关系,不然船夫回去的时候还带着自己)

    		public void getOffBoat(Vector3 des_pos) {
    			character.transform.parent = null;
    			moveableScript.setDestination(des_pos);
    			_isOnBoat = false;
    		}
    
  • 配合首号场记

CoastController的任务大体有三个:

  • 装货

    		public void getOnCoast(MyCharacterController characterCtrl) {
    			int index = getEmptyIndex ();
    			if(index != -1)
    				passengerPlaner [index] = characterCtrl;
    		}
    
  • 卸货

    		public MyCharacterController getOffCoast(string passenger_name) {	// 0->priest, 1->devil
    			for (int i = 0; i < passengerPlaner.Length; i++) {
    				if (passengerPlaner [i] != null && passengerPlaner [i].getName () == passenger_name) {
    					MyCharacterController charactorCtrl = passengerPlaner [i];
    					passengerPlaner [i] = null;
    					return charactorCtrl;
    				}
    			}
    			Debug.Log ("cant find passenger on coast: " + passenger_name);
    			return null;
    		}
    
  • 配合首号场记

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值