Ejemplo n.º 1
0
        public void HandleGame(bool playerTwoFirst)
        {
            Player[] players = new Player[3] {
                Player1, Player2, Player1
            };
            int whoseTurn = playerTwoFirst ? 1 : 0;

            while (HandlePlayerTurn(players[whoseTurn], players[whoseTurn + 1]))
            {
                whoseTurn++;
                whoseTurn %= 2;
                UserIO.Continue();
            }
            UserIO.WriteLine($"Congratulations on your victory, {players[whoseTurn].Name}!");
        }
Ejemplo n.º 2
0
        public void ShipSetup()
        {
            ResetBoard();
            UserIO.WriteLine($"Alright {Name}, let's setup your ships.");
            ShipType currentShip;

            for (int i = 0; i < 5; i++)
            {
                currentShip = (ShipType)i;
                UserIO.WriteLine($"Place your {currentShip.ToString()}.");

                PlaceShipRequest request = new PlaceShipRequest()
                {
                    Coordinate = UserIO.GetCoord(),
                    Direction  = UserIO.GetDirection(),
                    ShipType   = currentShip
                };

                ShipPlacement spotValidity = board.PlaceShip(request);
                switch (spotValidity)
                {
                case ShipPlacement.NotEnoughSpace:
                    i--;
                    UserIO.WriteLine("Not enough space to place a ship there!");
                    continue;

                case ShipPlacement.Overlap:
                    i--;
                    UserIO.WriteLine("This spot overlaps with another ship!");
                    break;

                case ShipPlacement.Ok:
                    UserIO.WriteLine("Ship placement works!");
                    break;

                default:
                    break;
                }
            }
            UserIO.Continue();
        }