Exemplo n.º 1
0
 public static void SetUpComputerShips(ComputerPlayer player)
 {
     foreach (string ship in player.ships)
     {
         bool isValidChoice2 = false;
         bool isValidChoice3 = false;
         int  shipLength     = (ship.ToLower() == "scout") ? 2 : 4;
         Game.SelectShip(ship, player);
         string[] coordSet = player.ChooseCoordinateSet().Split(',');
         int[]    coords   = new int[2] {
             int.Parse(coordSet[0]), int.Parse(coordSet[1])
         };
         while (!isValidChoice2)
         {
             try
             {
                 isValidChoice2 = Game.PlaceShip(String.Format("{0},{1}", coordSet[0], coordSet[1]), player);
             }
             catch (Exception) {}
         }
         while (!isValidChoice3)
         {
             try
             {
                 string direction = player.ChooseDirection();
                 isValidChoice3 = player.board.SetShipDirection(coords[0], coords[1], direction, shipLength, player);
             }
             catch (Exception) {}
         }
     }
 }
Exemplo n.º 2
0
        public static void Attack(ComputerPlayer player)
        {
            bool   wasTurnSuccessful = false;
            string coords            = (findingHitShip) ? player.ChoiceAfterAHit() : player.ChooseCoordinateSet();

            do
            {
                wasTurnSuccessful = Game.PlayerAttack(player, Game.player1, coords);
            } while (!wasTurnSuccessful);
            findingHitShip = (findingHitShip) ? true : false;
            findingHitShip = player.CheckIfJustHit(coords);
        }