Skip to content

Commit

Permalink
Added comments to Game.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
willbtty authored Sep 16, 2024
1 parent 912fddf commit 46e4fe1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions BlazorBattleship/GameClassLib/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand All @@ -27,4 +36,4 @@ public void Start()
}
}
}
}
}

0 comments on commit 46e4fe1

Please sign in to comment.