public static void PlayGame() { Player p1 = new Player(); Player p2 = new Player(); string player1; string player2; ConsoleOutput.DisplayTitle(); player1 = ConsoleInput.GetPlayerOneName(); p1.SetName(player1); player2 = ConsoleInput.GetPlayerTwoName(); p2.SetName(player2); Console.Clear(); p1.PlaceShipOnBoard(); Console.Clear(); p2.PlaceShipOnBoard(); int whoseTurn = _rng.Next(1, 3); do { if (whoseTurn == 1) { Console.Clear(); p2.DisplayBoard(p1); p2.FireShotAtBoard(p1); whoseTurn = 2; } else { Console.Clear(); p1.DisplayBoard(p2); p1.FireShotAtBoard(p2); whoseTurn = 1; } Console.ReadLine(); } while (!p1.GetWonGame() && !p2.GetWonGame()); }
private ReturnType SetupPlayer(Player myPlayer, string myPlayerName) { //Setup a SPECIFIC PLAYER - Do not use currentPlayer object here!!! //Does the player have a name from before? if (myPlayer.Name.Length == 0) { bool skipError = true; while (myPlayerName.Length == 0) { //Prompt user for name Console.Clear(); if (skipError != true) { Console.WriteLine("Invalid Entry, try again... \n\n"); } skipError = false; Console.WriteLine("Enter a name for this player: \n\nPress ENTER to continue, (Q/q) to quit..."); myPlayerName = Console.ReadLine(); if (myPlayerName.ToUpper() == "Q") { return(ReturnType.Quit); } } myPlayer.SetName(myPlayerName); } //ReInit if (myPlayer.PlayerStatus == PlayerStatus.FinishedGame || myPlayer.PlayerStatus == PlayerStatus.Initialized) { //No current need to do any other kind of other cleanup (SetupPlayerBoard method initializes a new board each time) } myPlayer.SetPlayerStatus(PlayerStatus.Uninitialized); //Going to reset the player's board, uninitialized until SetupPlayerBoard returns true //StubSetupPlayerBoard(myPlayer) can alternately be used for UI testing -- non-interactive board setup if (SetupPlayerBoard(myPlayer) == ReturnType.Success) { myPlayer.SetPlayerStatus(PlayerStatus.Initialized); } else { return(ReturnType.Error); } Console.Clear(); Console.WriteLine($"Great! Your board is now completely setup, {myPlayer.Name}! \nIt is setup as shown below:"); _grid.Grid(myPlayer, BoardViewType.ShipPositions); if (P1.PlayerStatus == PlayerStatus.Uninitialized || P2.PlayerStatus == PlayerStatus.Uninitialized) { Console.WriteLine("\nSwitch Seats with the other player, and let them set up their board. :-)"); } else if (P1.PlayerStatus == PlayerStatus.Initialized && P2.PlayerStatus == PlayerStatus.Initialized) { Console.WriteLine("\nThe game is now ready to play. :-)"); } else { //Something unexpected is happening to PlayerStatus - you need to debug and refactor... } Console.WriteLine("Press any key to continue..."); if (Console.ReadKey().Key == ConsoleKey.Q) { return(ReturnType.Quit); } return(ReturnType.Success); }