The next step states that:
💻 C#
// Repeat rounds until one of the players wins two times.The following statements represents a single round:
💻 C#
// Player enters a number between 1 and 2.
GamePrint.Input("Choose a number between 1 and 2");
int playerNumber = GameInput.Number(1, 2);
GamePrint.Message("You chose: " + playerNumber);
// Computer randomly generates a number between 1 and 2.
int computerNumber = GameRandom.Number(1, 2);
GamePrint.Message("Computer chose: " + computerNumber);
// Add the two numbers.
int sum = playerNumber + computerNumber;
GamePrint.Message("Sum is: " + sum);
// Check if the sum is odd or even.
bool sumIsEvens = sum % 2 == 0;
// Decide the round winner.
bool playerIsEvens = playerSide == 2;
if (playerIsEvens == sumIsEvens)
{
GamePrint.Success("You win this round!");
}
else
{
GamePrint.Error("Computer wins this round!");
}Each player chooses a number, we do the calculations and declare the round winner.
Now, we need to repeat this, until one of the players wins two rounds.
Here we have two different questions to deal with:
Before dealing with each step, let’s demarcate the round code so it’s easier to identify it.
✅ What to Do
✏️ Program.cs - Changes
++ // Round starts here.
// Player enters a number between 1 and 2.
GamePrint.Input("Choose a number between 1 and 2");
int playerNumber = GameInput.Number(1, 2);
GamePrint.Message("You chose: " + playerNumber);
// Computer randomly generates a number between 1 and 2.
int computerNumber = GameRandom.Number(1, 2);
GamePrint.Message("Computer chose: " + computerNumber);
// Add the two numbers.
int sum = playerNumber + computerNumber;
GamePrint.Message("Sum is: " + sum);
// Check if the sum is odd or even.
bool sumIsEvens = sum % 2 == 0;
// Decide the round winner.
bool playerIsEvens = playerSide == 2;
if (playerIsEvens == sumIsEvens)
{
GamePrint.Success("You win this round!");
}
else
{
GamePrint.Error("Computer wins this round!");
}
++ // Round ends here.🗒️ Program.cs - Final
(...)
// Round starts here.
// Player enters a number between 1 and 2.
GamePrint.Input("Choose a number between 1 and 2");
int playerNumber = GameInput.Number(1, 2);
GamePrint.Message("You chose: " + playerNumber);
// Computer randomly generates a number between 1 and 2.
int computerNumber = GameRandom.Number(1, 2);
GamePrint.Message("Computer chose: " + computerNumber);
// Add the two numbers.
int sum = playerNumber + computerNumber;
GamePrint.Message("Sum is: " + sum);
// Check if the sum is odd or even.
bool sumIsEvens = sum % 2 == 0;
// Decide the round winner.
bool playerIsEvens = playerSide == 2;
if (playerIsEvens == sumIsEvens)
{
GamePrint.Success("You win this round!");
}
else
{
GamePrint.Error("Computer wins this round!");
}
// Round ends here.