Beispiel #1
0
 private static void Main()
 {
     MainLogic.Logic();
     MainLogic.AsciiArt();
 }
        public void Move(Ocean playerBoard,
                         Ocean enemyEmptyBoard,
                         Ocean enemyShipsBoard,
                         Dictionary <string, Ship> enemyShips)
        {
            int coordX;
            int coordY;

            if (this.PlayerShips.Count != 5)
            {
                for (int i = 0; i < 5; i++)
                {
                    bool placed;
                    do
                    {
                        Ship newShip;
                        bool direction;
                        if (this.Name != "AI")
                        {
                            (coordX, coordY) = GetTheCoords("Place your ships!");
                            newShip          = ShipType();
                            direction        = ShipDirection();
                        }
                        else
                        {
                            (coordX, coordY) = AI.AiGetCoords();
                            newShip          = AI.AiGetShipType();
                            direction        = AI.AiGenerateShipDirection();
                        }
                        placed = SHIP.Ship.PlaceShip(coordX,
                                                     coordY,
                                                     direction,
                                                     playerBoard.ArrayOfSquares,
                                                     newShip);
                        if (placed)
                        {
                            this.PlayerShips.Add(newShip.ShipSign, newShip);
                            if (this.Name == "AI")
                            {
                                AI.shipTypes.Remove(newShip.ShipSign.Trim());
                            }
                        }
                    } while (placed is false);
                    Console.Clear();
                    MainLogic.AsciiArt();
                    Console.WriteLine($"This is {this.Name} turn.");
                    if (this.Name != "AI")
                    {
                        Ocean.PrintBoard(playerBoard, enemyEmptyBoard);
                    }
                }
            }
            else
            {
                bool wasItHit;
                bool isItSunk;
                do
                {
                    if (this.Name != "AI")
                    {
                        (coordX, coordY) = GetTheCoords("FIRE!");
                    }
                    else
                    {
                        (coordX, coordY) = AI.AiGetCoords();
                    }
                    (wasItHit, isItSunk) = Square.Shoot(coordX,
                                                        coordY,
                                                        enemyEmptyBoard.ArrayOfSquares,
                                                        enemyShipsBoard.ArrayOfSquares,
                                                        enemyShips);
                    Console.Clear();
                    MainLogic.AsciiArt();
                    if (this.Name != "AI")
                    {
                        Ocean.PrintBoard(playerBoard, enemyEmptyBoard);
                        if (isItSunk)
                        {
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.WriteLine("THIS ONE IS DOWN!");
                            Console.ResetColor();
                        }
                    }
                } while (wasItHit is true && enemyShips.Count != 0);
            }
        }