public void Attak() { if ((this.state == SAFE)) { holder.Hit(); this.state = HIT; } }
/// <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"); } }
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); }