public void CharacterClicked(GameObject character) { if (!Movement.movable) { return; } //找出点击角色的Controller Controller.MyGameObject.MyCharacterController characterCtrl = null; for (int i = 0; i < characters.Length; i++) { if (characters[i].getName() == character.name) { characterCtrl = characters[i]; } } if (characterCtrl == null) { return; //UNFINISHED 异常处理 } if (characterCtrl.isOnBoat()) { Controller.MyGameObject.LandController whichCoast; if (boat.get_to_or_from() == -1) { // to->-1; from->1 whichCoast = toCoast; } else { whichCoast = fromCoast; } boat.GetOffBoat(characterCtrl.getName()); characterCtrl.moveToPosition(whichCoast.getEmptyPosition()); characterCtrl.getOnCoast(whichCoast); whichCoast.getOnLand(characterCtrl); } else { // character on coast Controller.MyGameObject.LandController whichCoast = characterCtrl.getCoastController(); if (boat.getEmptyIndex() == -1) { // boat is full return; } if (whichCoast.get_type() != boat.get_to_or_from()) // boat is not on the side of character { return; } whichCoast.getOffLand(characterCtrl.getName()); characterCtrl.moveToPosition(boat.getEmptyPosition()); characterCtrl.getOnBoat(boat); boat.GetOnBoat(characterCtrl); } gameState = check_game_over(); }
public void LoadResources() { //加载各种游戏资源 Vector3 water_pos = new Vector3(0, 0, 0); GameObject water = Instantiate(Resources.Load("pf_water", typeof(GameObject)), water_pos, Quaternion.identity, null) as GameObject; water.name = "water"; fromCoast = new Controller.MyGameObject.LandController("from"); toCoast = new Controller.MyGameObject.LandController("to"); boat = new Controller.MyGameObject.BoatController(); characters = new Controller.MyGameObject.MyCharacterController[6]; for (int i = 0; i < 3; i++) { //UNFINISHED:为什么要浪费空间新建一个示例呢?不能直接修改吗 Controller.MyGameObject.MyCharacterController cha = new Controller.MyGameObject.MyCharacterController("priest"); cha.setName("priest" + i); cha.setPosition(fromCoast.getEmptyPosition()); cha.getOnCoast(fromCoast); fromCoast.getOnLand(cha); characters[i] = cha; } for (int i = 0; i < 3; i++) { Controller.MyGameObject.MyCharacterController cha = new Controller.MyGameObject.MyCharacterController("devil"); cha.setName("devil" + i); cha.setPosition(fromCoast.getEmptyPosition()); cha.getOnCoast(fromCoast); fromCoast.getOnLand(cha); characters[i + 3] = cha; } }