//main game method public void PlayGame() { board.Display(hacks); while (allShipsSunk == false) { Console.WriteLine("Where do you want to target Capitan?"); Console.WriteLine("Enter two numbers 0-9 seperated by space, or enter hacks to toggle hacks"); string input = Console.ReadLine(); if ((input == "hacks")) //Toggle hacks. { if (hacks == true) { hacks = false; } else if (hacks == false) { hacks = true; } board.Display(hacks); Console.WriteLine($"hacks are {hacks}"); } else { string[] values = input.Split(' '); int targetX = int.Parse(values[0]); int targetY = int.Parse(values[1]); Shoot(targetX, targetY); } allShipsSunk = AllSunk();//check if all ships are sunk; } if (allShipsSunk == true) { Console.WriteLine("You Have won Capitan!"); Console.WriteLine("Would you like to play again? Y/N"); string input = Console.ReadLine(); if (input == "Y" || input == "y") { board = new Gameboard(); hacks = false; carrier = PlaceShip(5, "carrier"); battleship = PlaceShip(4, "battleship"); submarine1 = PlaceShip(3, "Submarine"); submarine2 = PlaceShip(3, "Submarine"); destroyer1 = PlaceShip(2, "Destroyer"); destroyer2 = PlaceShip(2, "Destroyer"); shipList.Add(carrier); shipList.Add(battleship); shipList.Add(submarine1); shipList.Add(submarine2); shipList.Add(destroyer1); shipList.Add(destroyer2); } else if (input == "n" || input == "N") { Console.WriteLine("Goodbye"); } } }
//constructors public Game() { board = new Gameboard(); hacks = false; carrier = PlaceShip(5, "carrier"); battleship = PlaceShip(4, "battleship"); submarine1 = PlaceShip(3, "Submarine"); submarine2 = PlaceShip(3, "Submarine"); destroyer1 = PlaceShip(2, "Destroyer"); destroyer2 = PlaceShip(2, "Destroyer"); shipList.Add(carrier); shipList.Add(battleship); shipList.Add(submarine1); shipList.Add(submarine2); shipList.Add(destroyer1); shipList.Add(destroyer2); }