Exemple #1
0
        static void GameStart(Board playerBoard, Board aiBoard)
        {
            string lastShotStatus = "Miss.";
            Point  lastShot;
            Random rnd = new Random();

            playerBoard.PrintBoard(true); //playerboard and aiboard
            aiBoard.PrintBoard(false);

            for (int i = 0; i < 60; i++)
            {
                if (lastShotStatus == "Hit")
                {
                }
                else
                {
                    Point currentShot = new Point(rnd.Next(0, 5), rnd.Next(0, 5));
                    playerBoard.TakeShot(currentShot, out string playerShipStatus); //takeshot on playerboard logic
                    lastShotStatus = playerShipStatus;
                    lastShot       = currentShot;
                    Console.WriteLine(playerShipStatus);
                }



                aiBoard.PrintBoard(false);                            // add argument that toggles display of ships
                if (aiBoard.IsGameOver() || playerBoard.IsGameOver()) //update so that game ends when one board reaches end state
                {
                    Console.WriteLine("Game Over!");
                    break;
                }
            }

            Console.WriteLine("Press any key to exit. . .");

            Console.ReadKey();
        }