Beispiel #1
0
 public void Attak()
 {
     if ((this.state == SAFE))
     {
         holder.Hit();
         this.state = HIT;
     }
 }
Beispiel #2
0
 /// <summary>
 /// Shoot allows a tile to be shot at, and if the tile has been hit before
 /// it will give an error
 /// </summary>
 internal void Shoot()
 {
     if ((false == Shot))
     {
         Shot = true;
         if (_Ship != null)
         {
             _Ship.Hit();
         }
     }
     else
     {
         throw new ApplicationException("You have already shot this square");
     }
 }
Beispiel #3
0
        public PlayerAction PlayTurn()
        {
            PlayerAction action = null;

            while (action == null)
            {
                int x = Rand.Next(0, GameEngine.GridSize);
                int y = Rand.Next(0, GameEngine.GridSize);

                if (AttackingPlayer.FiringGrid.IsEmpty(x, y))
                {
                    action = new PlayerAction(this.AttackingPlayer.Name, x, y);

                    // Take the shot
                    Shot shot = new Shot();

                    Ship ship = DefendingPlayer.GetShip(x, y);
                    if (ship != null)
                    {
                        ship.Hit(x, y);
                        shot.ShipClassification = ship.Classification;

                        action.Hit = true;
                        action.ShipClassification = ship.Classification;
                        action.Sunk = ship.IsSunk();
                    }

                    AttackingPlayer.FiringGrid.Map[x, y] = shot;
                }
            }

            this.AttackingPlayer.Actions.Add(action);

            if (this.DefendingPlayer.AreAllShipsSunk())
            {
                this.GameOver = true;
            }
            else
            {
                // Flip the attacking and defending players..
                var temp = AttackingPlayer;
                AttackingPlayer = DefendingPlayer;
                DefendingPlayer = temp;
            }

            return(action);
        }