Beispiel #1
0
        private static void Main(string[] args)
        {
            var board = new Board();
            var game  = new Game(board);

            game.Initialize();
            var turn = 1;

            while (true)
            {
                Console.WriteLine($"Turn: {turn}");
                board.PrintBoard();
                var input = Console.ReadLine();
                if (input != "Exit")
                {
                    var result = game.Shot(input);
                    Console.WriteLine(result);
                    if (result.Equals("Won!"))
                    {
                        break;
                    }
                    turn++;
                }
                else
                {
                    Console.WriteLine("Exiting...");
                    break;
                }
            }

            Console.ReadKey();
        }
Beispiel #2
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();
        }