Beispiel #1
0
        //player chooses where to place their ships
        //must not overlap
        //must rotate?
        //ships are destroyer (2) Submarine(3) Battleship(4) carrier(5)
        //for each turn, show opponents board, obscured to their knowledge (and their own board?)
        //keep score by tracking which ships have been destroyed


        public void Start()
        {
            Console.SetWindowSize(100, 56);
            Console.SetWindowPosition(0, 0);
            Board Board1 = new Board();

            Board1.DrawBoard(2, 1);
            Board1.DrawBoard(2, 26);
            Board1.SetShipLocations();
            Console.ReadKey();
        }
Beispiel #2
0
        private void PlayerShoot()
        {
            Console.WriteLine("Here's your board");
            Board.DrawBoard(player.Grid);
            Console.WriteLine("Your enemy's board");
            Board.DrawBoard(player.EnemyGrid);
            Console.WriteLine("\nNow shoot!");
            Console.WriteLine();
            Console.WriteLine("Enter x");
            string readLineResult = Console.ReadLine();

            if (!int.TryParse(readLineResult, out int x))
            {
                Console.WriteLine("It's not a number!");
                Console.WriteLine("Press any key to exit the game...");
                Console.ReadKey();
                Environment.Exit(0);
            }
            Console.WriteLine("Enter y");
            readLineResult = Console.ReadLine();
            if (!int.TryParse(readLineResult, out int y))
            {
                Console.WriteLine("It's not a number!");
                Console.WriteLine("Press any key to exit the game...");
                Console.ReadKey();
                Environment.Exit(0);
            }
            player.Shoot(botPlayer, x, y);
        }
Beispiel #3
0
 private void LostMessage()
 {
     Console.WriteLine("Here's your board");
     Board.DrawBoard(player.Grid);
     Console.WriteLine("Your enemy's board");
     Board.DrawBoard(player.EnemyGrid);
     Console.WriteLine("You lost :(");
     Console.WriteLine("!!! BETTER LUCK NEXT TIME !!!");
     Console.WriteLine();
     Console.WriteLine("Press any key to exit...");
     Console.ReadKey();
 }
Beispiel #4
0
 private void WonMesssage()
 {
     Console.WriteLine("Here's your board");
     Board.DrawBoard(player.Grid);
     Console.WriteLine("Your enemy's board");
     Board.DrawBoard(player.EnemyGrid);
     Console.WriteLine("You won!");
     Console.WriteLine("!!! CONGRATULATIONS !!!");
     Console.WriteLine();
     Console.WriteLine("Press any key to exit...");
     Console.ReadKey();
 }
Beispiel #5
0
        private void PlantShips()
        {
            Board.DrawBoard(player.Grid);
            Console.WriteLine("Enter starting position of your ship");
            Console.WriteLine("Enter x");
            string readLineResult = Console.ReadLine();

            if (!int.TryParse(readLineResult, out int x))
            {
                Console.WriteLine("It's not a number!");
                Console.WriteLine("Press any key to exit the game...");
                Console.ReadKey();
                Environment.Exit(0);
            }
            Console.WriteLine("Enter y");
            readLineResult = Console.ReadLine();
            if (!int.TryParse(readLineResult, out int y))
            {
                Console.WriteLine("It's not a number!");
                Console.WriteLine("Press any key to exit the game...");
                Console.ReadKey();
                Environment.Exit(0);
            }
            Console.WriteLine("Enter ending position of your ship");
            Console.WriteLine("Enter x");
            readLineResult = Console.ReadLine();
            if (!int.TryParse(readLineResult, out int a))
            {
                Console.WriteLine("It's not a number!");
                Console.WriteLine("Press any key to exit the game...");
                Console.ReadKey();
                Environment.Exit(0);
            }
            Console.WriteLine("Enter y");
            readLineResult = Console.ReadLine();
            if (!int.TryParse(readLineResult, out int b))
            {
                Console.WriteLine("It's not a number!");
                Console.WriteLine("Press any key to exit the game...");
                Console.ReadKey();
                Environment.Exit(0);
            }

            int addShipsResult = shipController.AddShip(x, y, a, b);

            if (addShipsResult != 0)
            {
                if (addShipsResult == 1)
                {
                    Console.WriteLine("Ship can't be placed diagonally");
                }
                else if (addShipsResult == 2)
                {
                    Console.WriteLine("Ship's length can't be equal 1");
                }
                else if (addShipsResult == 3)
                {
                    Console.WriteLine("Ship can't be placed on occupied tile");
                }
                else if (addShipsResult == 4)
                {
                    Console.WriteLine("Unknown error");
                }

                Console.ReadKey();
                return;
            }
            player.Grid    = new List <List <char> >(shipController.Grid);
            botPlayer.Grid = new List <List <char> >(shipController.Grid);
            player.SetWinningShotNumber(x, y, a, b);
            botPlayer.SetWinningShotNumber(x, y, a, b);
        }