Now that the player has chosen a number, the computer will generate a random one.
The GameUtilities include a
function
to help with that:
๐ป C#
// Generates a number between 1 and 10.
GameRandom.Number(1, 10);It generates a random number within the range passed in the arguments.
Like we did with the player number, we need to store it in a variable and print it in the console.
โ What to Do
๐ฏ Expected Outcome
๐จ๏ธ Console
+--------------------------------+
+-- Welcome to Odds and Evens! --+
+--------------------------------+
--> Choose 1 for Odds or 2 for Evens:
1
# You chose Odds
# Computer is Evens
--> Choose a number between 1 and 2:
1
# You chose: 1
# Computer chose: 2
โ๏ธ Program.cs - Changes
// Computer randomly generates a number between 1 and 2.
++ int computerNumber = GameRandom.Number(1, 2);
++ GamePrint.Message("Computer chose: " + computerNumber);๐๏ธ Program.cs - Final
(...)
// Computer randomly generates a number between 1 and 2.
int computerNumber = GameRandom.Number(1, 2);
GamePrint.Message("Computer chose: " + computerNumber);
(...)