|
| 1 | +using System; |
| 2 | +using System.Threading.Tasks; |
| 3 | + |
| 4 | +namespace Website.Games.Dice_Game; |
| 5 | + |
| 6 | +public class Dice_Game |
| 7 | +{ |
| 8 | + public readonly BlazorConsole Console = new(); |
| 9 | + |
| 10 | + public async Task Run() |
| 11 | + { |
| 12 | + int playerPoints = 0; |
| 13 | + int rivalPoints = 0; |
| 14 | + |
| 15 | + Random random = new(); |
| 16 | + |
| 17 | + await Console.WriteLine("Dice Game"); |
| 18 | + await Console.WriteLine(); |
| 19 | + await Console.WriteLine("In this game you and a computer Rival will play 10 rounds"); |
| 20 | + await Console.WriteLine("where you will each roll a 6-sided dice, and the player"); |
| 21 | + await Console.WriteLine("with the highest dice value will win the round. The player"); |
| 22 | + await Console.WriteLine("who wins the most rounds wins the game. Good luck!"); |
| 23 | + await Console.WriteLine(); |
| 24 | + await Console.Write("Press any key to start..."); |
| 25 | + await Console.ReadKey(true); |
| 26 | + await Console.WriteLine(); |
| 27 | + await Console.WriteLine(); |
| 28 | + for (int i = 0; i < 10; i++) |
| 29 | + { |
| 30 | + await Console.WriteLine($"Round {i + 1}"); |
| 31 | + int rivalRandomNum = random.Next(1, 7); |
| 32 | + await Console.WriteLine("Rival rolled a " + rivalRandomNum); |
| 33 | + await Console.Write("Press any key to roll the dice..."); |
| 34 | + await Console.ReadKey(true); |
| 35 | + await Console.WriteLine(); |
| 36 | + int playerRandomNum = random.Next(1, 7); |
| 37 | + await Console.WriteLine("You rolled a " + playerRandomNum); |
| 38 | + if (playerRandomNum > rivalRandomNum) |
| 39 | + { |
| 40 | + playerPoints++; |
| 41 | + await Console.WriteLine("You won this round."); |
| 42 | + } |
| 43 | + else if (playerRandomNum < rivalRandomNum) |
| 44 | + { |
| 45 | + rivalPoints++; |
| 46 | + await Console.WriteLine("The Rival won this round."); |
| 47 | + } |
| 48 | + else |
| 49 | + { |
| 50 | + await Console.WriteLine("This round is a draw!"); |
| 51 | + } |
| 52 | + await Console.WriteLine($"The score is now - You : {playerPoints}. Rival : {rivalPoints}."); |
| 53 | + await Console.Write("Press any key to continue..."); |
| 54 | + await Console.ReadKey(true); |
| 55 | + await Console.WriteLine(); |
| 56 | + await Console.WriteLine(); |
| 57 | + } |
| 58 | + await Console.WriteLine("Game over."); |
| 59 | + await Console.WriteLine($"The score is now - You : {playerPoints}. Rival : {rivalPoints}."); |
| 60 | + if (playerPoints > rivalPoints) |
| 61 | + { |
| 62 | + await Console.WriteLine("You won!"); |
| 63 | + } |
| 64 | + else if (playerPoints < rivalPoints) |
| 65 | + { |
| 66 | + await Console.WriteLine("You lost!"); |
| 67 | + } |
| 68 | + else |
| 69 | + { |
| 70 | + await Console.WriteLine("This game is a draw."); |
| 71 | + } |
| 72 | + await Console.Write("Press any key to exit..."); |
| 73 | + await Console.ReadKey(true); |
| 74 | + await Console.Clear(); |
| 75 | + await Console.Write("Dice Game was closed."); |
| 76 | + await Console.Refresh(); |
| 77 | + } |
| 78 | +} |
0 commit comments