public void Run() { Player player1; Player player2; Board board1; Board board2; do { //splash screen mehtod UserIO.SplashScreen(); //dec player1 = new Player(); player2 = new Player(); board1 = new Board(); board2 = new Board(); //players will take turns entering name and placing ships UserIO.GameSetup(player1, player2, board1, board2); } while (Turn.TurnMain(player1, player2, board1, board2) && Turn.PlayAgain() == true); Console.WriteLine("Press any key to exit game."); Console.ReadKey(); Environment.Exit(0); //display board2 for player1 //get player1 coords for shot at board2 //determine result of shot //clear //prompt and readline to start player 2 turn //display board1 for player2 //get player2 coords for shot at board1 //determine result of shot //clear //loop back and forth between players for shots //check for victory //back to player1 shot }
public static bool TurnMain(Player player1, Player player2, Board board1, Board board2) { bool goesNext = UserIO.GoesFirst(player1, player2); Player currentPlayer = new Player(); Board currentBoard = new Board(); ShotStatus shotStatus; while (true) //set condition to victory == false? { if (goesNext == true) { currentPlayer = player1; currentBoard = board2; goesNext = false; } else { currentPlayer = player2; currentBoard = board1; goesNext = true; } //start current player's turn shotStatus = PlayerTurn(currentPlayer, currentBoard); //\\check for victory? if (shotStatus == ShotStatus.Victory) { return(true); } Console.WriteLine($"Press any key to end {currentPlayer.Name}'s turn"); Console.ReadKey(true); Console.Clear(); } }
public static void PlaceShips(Board board) { foreach (var item in Enum.GetValues(typeof(ShipType))) { while (true) { Console.WriteLine($"\nPlace your {item}"); PlaceShipRequest request = new PlaceShipRequest { Coordinate = UserIO.EnterCoordinates(), Direction = UserIO.Direction(), ShipType = (ShipType)item, //set up loop to rotate current ship }; ShipPlacement response = new ShipPlacement(); response = board.PlaceShip(request); switch (response) { case ShipPlacement.NotEnoughSpace: Console.Clear(); Console.WriteLine($"Could not place {item}: Not enough space.\nPlease try again."); continue; case ShipPlacement.Overlap: Console.Clear(); Console.WriteLine($"Could not place {item}: Ship overlap.\nPlease try again"); continue; case ShipPlacement.Ok: break; } break; } Console.Clear(); } }
public Player() { Name = UserIO.SetName(); ShipSetup(); }
public void Run() { do { UserIO.SplashScreen(); Player player1 = new Player(); Player player2 = new Player(); UserIO.setUpPlayer(player1); UserIO.destroyerPlacement(player1); UserIO.submarinePlacement(player1); UserIO.cruiserPlacement(player1); UserIO.battleshipPlacement(player1); UserIO.carrierPlacement(player1); UserIO.setUpPlayer(player2); UserIO.destroyerPlacement(player2); UserIO.submarinePlacement(player2); UserIO.cruiserPlacement(player2); UserIO.battleshipPlacement(player2); UserIO.carrierPlacement(player2); UserIO.twoPlayerGame(player1, player2); bool play = false; do { string playAgain = ""; Console.WriteLine("Would you like to play again? (1 = Yes, 2 = No)"); playAgain = Console.ReadLine(); if (playAgain == "2") { Console.WriteLine("Thanks for playing!"); Console.WriteLine("Press enter to exit"); Console.ReadLine(); Environment.Exit(0); } else if (playAgain == "1") { Console.Clear(); play = true; } } while (play == false); } while (true); }