/* * * Returns an objet with information about the missile. If enemy_tank is set to false * the missile of your own player will be returned otherwise its the enemys missile. * * If no missile exists the function will still return a missile object but it will be null. * To get the other field you need to use getter methods wich are just the name of the field you want to get. * * Se the game documentation for details about the different fields. * * example: * consoden.tankgame.Missile missile = gm.GetMissile(false); * if(missile != null){ * System.out.println("enemy missile head position is " + missile.headPosX().getVal() + "," + missile.headPosY().getVal() ); * } */ public Consoden.TankGame.Missile GetMissile(bool enemy_tank) { int id = 0; if (enemy_tank) { id = (tankId + 1) % 2; } else { id = tankId; } for (int i = 0; i < this.gameState.Missiles.Count; i++) { if (gameState.Missiles [i].IsNull()) { continue; } Consoden.TankGame.Missile missile = gameState.Missiles [i].Obj; if (missile.TankId.Val == id) { return(missile); } } return(null); }
//Print game state public void PrintState() { Console.WriteLine("Game board"); PrintMap(); Console.WriteLine("Own position {0},{1}", OwnPosition.X, OwnPosition.Y); Console.WriteLine("Enemy position {0},{1}", EnemyPosition.X, EnemyPosition.Y); Console.WriteLine("Active missiles"); for (int i = 0; i < this.gameState.Missiles.Count; i++) { if (gameState.Missiles [i].IsNull()) { continue; } Consoden.TankGame.Missile missile = gameState.Missiles [i].Obj; Position head = new Position(missile.HeadPosX.Val, missile.HeadPosY.Val); Position tail = new Position(missile.TailPosX.Val, missile.TailPosY.Val); Consoden.TankGame.Direction.Enumeration direction = missile.Direction.Val; Console.WriteLine("Missile position - head {0},{1}", head.X, head.Y); Console.WriteLine("Missile position - tail {0},{1}", tail.X, tail.Y); Console.Write("Missile direction "); switch (direction) { case Consoden.TankGame.Direction.Enumeration.Left: Console.WriteLine("Left"); break; case Consoden.TankGame.Direction.Enumeration.Right: Console.WriteLine("Right"); break; case Consoden.TankGame.Direction.Enumeration.Up: Console.WriteLine("Up"); break; case Consoden.TankGame.Direction.Enumeration.Down: Console.WriteLine("Down"); break; case Consoden.TankGame.Direction.Enumeration.Neutral: Console.WriteLine("Neutral"); break; } Console.WriteLine(); } Console.WriteLine(); }
//Is there a missile in this square public bool IsMissileInPosition(Position p) { for (int i = 0; i < this.gameState.Missiles.Count; i++) { if (gameState.Missiles [i].IsNull()) { continue; } Consoden.TankGame.Missile missile = gameState.Missiles [i].Obj; if ((p.X == missile.HeadPosX.Val && p.Y == missile.HeadPosY.Val) || (p.X == missile.TailPosX.Val && p.Y == missile.TailPosY.Val)) { return(true); } } return(false); }