1、编写一个简单的鼠标打飞碟(Hit UFO)游戏
游戏内容要求:
- 游戏有 n 个 round,每个 round 都包括10 次 trial;
- 每个 trial 的飞碟的色彩、大小、发射位置、速度、角度、同时出现的个数都可能不同。它们由该 round 的 ruler 控制;
- 每个 trial 的飞碟有随机性,总体难度随 round 上升;
- 鼠标点中得分,得分规则按色彩、大小、速度不同计算,规则可自由设定。
游戏的要求:
- 使用带缓存的工厂模式管理不同飞碟的生产与回收,该工厂必须是场景单实例的!具体实现见参考资源 Singleton 模板类
- 近可能使用前面 MVC 结构实现人机交互与游戏模型分离
如果你的使用工厂有疑问,参考:弹药和敌人:减少,重用和再利用;参考:Unity对象池(Object Pooling)理解与简单应用 代码质量较低,比较凌乱
游戏设计
同样地,这次作业用的框架跟上一次作业一样,大抵可将除了与游戏对象相关以及Judgement(在这里游戏轮次我直接在FirstController的update里面实现了,Judgement暂时来看是不需要的了)之外的代码都复制过去,稍作修改。
首先,先修改的是IUserAction,以往对船以及人的移动接口已经是不需要了。
public interface IUserAction
{
// void MoveBoat();
// void MoveRole(RoleModel roleModel);
void Restart();
//void Check();
}
其次就到FirstController,
public class FirstController : MonoBehaviour, ISceneController, IUserAction {
private bool isRuning;
public UFOFactory ufoFactory;
private int[] roundUFOs;
private int score;
private int round;
private int trial;
private float sendTime;
// the first scripts
void Awake () {
SSDirector director = SSDirector.getInstance ();
director.setFPS (60);
director.currentSceneController = this;
director.currentSceneController.LoadResources ();
this.gameObject.AddComponent<UserGUI>();
this.gameObject.AddComponent<CCActionManager>();
ufoFactory=UFOFactory.getInstance();
roundUFOs=new int[]{2,3,3,4,4,4,5,5,5,5};
score=round=trial=0;
sendTime=0;
}
// loading resources for the first scence
public void LoadResources () {
isRuning=true;
}
public void SendUFO(){
GameObject ufo=ufoFactory.GetUFO(round);
ufo.transform.position=new Vector3(ufo.GetComponent<UFOData>().direction.x>0? -9:9,UnityEngine.Random.Range(0f,8f),0);
ufo.SetActive(true);
this.gameObject.GetComponent<CCActionManager>().Fly(ufo,ufo.GetComponent<UFOData>().speed,ufo.GetComponent<UFOData>().direct