Exemplo n.º 1
0
 private void WeHaveAWinner()
 {
     Console.Clear();
     Console.WriteLine(this.BattleShips.GetBattleShipsGameBoardView());
     Console.WriteLine("Tillykke Kaptajn " + BattleShips.player[BattleShips.battleShipCurrentPlayer].name + "!\nDu har vundet spillet!\nTryk en tast for at komme tilbage til menuen");
     Console.ReadKey();
     BattleShips = null;
 }
Exemplo n.º 2
0
 private void StartBattleShipsNormalGame()
 {
     Console.Clear();
     BattleShips = new BattleShips();
     for (int i = 0; i < BattleShips.player.Length; i++)
     {
         BattleShips.player[BattleShips.battleShipCurrentPlayer].name = BattleShips.GetPlayerName();
         for (int j = 0; j < BattleShips.player[BattleShips.battleShipCurrentPlayer].shipNames.Length; j++)
         {
             bool shouldPickNewCoordinates = true;
             do
             {
                 int xKoordinat;
                 int yKoordinat;
                 Console.WriteLine(BattleShips.GetBattleShipsGameBoardView());
                 Console.WriteLine();
                 Console.WriteLine("Du er ved, at placere " + BattleShips.player[BattleShips.battleShipCurrentPlayer].shipNames[j] + ", som er " + BattleShips.player[BattleShips.battleShipCurrentPlayer].shipLengths[j] + " felter langt.");
                 Console.WriteLine("Skriv skibets x-koordinat");
                 xKoordinat = BattleShips.GetNumberFromPlayer();
                 Console.WriteLine("Skriv skibets y-koordinat");
                 yKoordinat = BattleShips.GetNumberFromPlayer();
                 bool isEastClear  = BattleShips.ValidateShipDirection(xKoordinat, yKoordinat, BattleShips.player[BattleShips.battleShipCurrentPlayer].shipLengths[j], 'e');
                 bool isWestClear  = BattleShips.ValidateShipDirection(xKoordinat, yKoordinat, BattleShips.player[BattleShips.battleShipCurrentPlayer].shipLengths[j], 'w');
                 bool isNorthClear = BattleShips.ValidateShipDirection(xKoordinat, yKoordinat, BattleShips.player[BattleShips.battleShipCurrentPlayer].shipLengths[j], 'n');
                 bool isSouthClear = BattleShips.ValidateShipDirection(xKoordinat, yKoordinat, BattleShips.player[BattleShips.battleShipCurrentPlayer].shipLengths[j], 's');
                 if (isSouthClear || isWestClear || isNorthClear || isEastClear)
                 {
                     if (isEastClear)
                     {
                         Console.WriteLine("Tryk 1 for at placere skibet mod øst");
                     }
                     if (isWestClear)
                     {
                         Console.WriteLine("Tryk 2 for at placere skibet mod vest");
                     }
                     if (isNorthClear)
                     {
                         Console.WriteLine("Tryk 3 for at placere skibet mod nord");
                     }
                     if (isSouthClear)
                     {
                         Console.WriteLine("Tryk 4 for at placere skibet mod syd");
                     }
                     int  shipDirection;
                     bool shouldTypeNewCoord = true;
                     do
                     {
                         shipDirection = BattleShips.GetNumberFromPlayer();
                         if (shipDirection > 0 && shipDirection < 5)
                         {
                             if ((shipDirection == 1 && isEastClear) || (shipDirection == 2 && isWestClear) || (shipDirection == 3 && isNorthClear) || (shipDirection == 4 && isSouthClear))
                             {
                                 shouldTypeNewCoord = false;
                             }
                         }
                     } while (shouldTypeNewCoord);
                     BattleShips.PlaceShip(xKoordinat, yKoordinat, BattleShips.player[BattleShips.battleShipCurrentPlayer].shipLengths[j], shipDirection, BattleShips.player[BattleShips.battleShipCurrentPlayer].shipChar[j]);
                     Console.Clear();
                     shouldPickNewCoordinates = false;
                 }
                 else
                 {
                     Console.WriteLine("Der er ikke plads til skibet her. Vælg et nyt koordinatsæt");
                     Console.ReadKey();
                     Console.Clear();
                 }
             } while (shouldPickNewCoordinates);
         }
         BattleShips.SmokeScreen();
         BattleShips.EndTurn();
         Console.Clear();
     }
     this.PlayerShootsAtShips();
 }