From 46e4fe111a531ed84ba88048005d6ade9f987150 Mon Sep 17 00:00:00 2001 From: Willem Battey <115966859+willbtty@users.noreply.github.com> Date: Sun, 15 Sep 2024 21:21:32 -0500 Subject: [PATCH] Added comments to Game.cs --- BlazorBattleship/GameClassLib/Game.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/BlazorBattleship/GameClassLib/Game.cs b/BlazorBattleship/GameClassLib/Game.cs index 5788858..aabde59 100644 --- a/BlazorBattleship/GameClassLib/Game.cs +++ b/BlazorBattleship/GameClassLib/Game.cs @@ -2,23 +2,32 @@ { class Game { + // The Start method initializes the game and manages the game loop. public void Start() { + // Display a welcome message to the players. Console.WriteLine("Welcome to Battleship!"); + // Prompt the user to choose the number of ships. Console.WriteLine("Choose the number of ships you want to play with: "); + // Read the user's input and convert it to an integer representing the number of ships. int shipNum = Convert.ToInt32(Console.ReadLine()); + // Create two Player instances with the specified number of ships and assign names. var player1 = new Player(shipNum, "Player 1"); var player2 = new Player(shipNum, "Player 2"); + // Start the main game loop. while (true) { + // Player 1 takes a turn attacking Player 2. player1.TakeTurn(player2); + // Check if Player 2 has no ships (life) remaining. if (player2.life == 0) { Console.WriteLine("Player 1 wins!"); - break; + break; // Exit the game loop. } player2.TakeTurn(player1); + // Check if Player 1 has no ships (life) remaining. if (player1.life == 0) { Console.WriteLine("Player 2 wins!"); @@ -27,4 +36,4 @@ public void Start() } } } -} \ No newline at end of file +}