Advertisement
mralasic

mralasic

Sep 11th, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ClashOfGiantsConsole
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. // Point 1
  15. // variables that stores information about rolled pips in each round
  16.  
  17.  
  18. // Point 1.1
  19. // variables that stores amounts of win rounds
  20.  
  21.  
  22. // Point 1.2
  23. // rounds' counter, it is used to create end game condition
  24.  
  25.  
  26. // Point 1.3
  27. // print out information that the game is starting
  28.  
  29.  
  30.  
  31. // Point 1.4
  32. // read key freezes the application until user press any key
  33.  
  34.  
  35. // clear method removes everything from the console
  36. Console.Clear();
  37.  
  38. //to repeat game until somebody wins, do while loop can be used
  39. do
  40. {
  41. // Point 2
  42. // increment rounds counter
  43.  
  44.  
  45. Console.WriteLine($"Round: {round}");
  46. Console.WriteLine($"Your turn");
  47. Console.ReadKey();
  48. Console.Clear();
  49.  
  50. // draw number of pips rolled by player
  51. playerPips = RollDice();
  52. Console.WriteLine($"Your score: {playerPips}");
  53. Console.ReadKey();
  54. Console.Clear();
  55.  
  56. Console.WriteLine($"Round: {round}");
  57. Console.WriteLine($"My turn :)");
  58. Console.ReadKey();
  59. Console.Clear();
  60.  
  61. // now opponent's turn
  62. opponentPips = RollDice();
  63. Console.WriteLine($"My score: {opponentPips}");
  64. Console.ReadKey();
  65. Console.Clear();
  66.  
  67. // let's proceed to winner checking
  68. // if somebody won, update points
  69. // in case of a draw, nobody gets any points
  70. Console.WriteLine($"Let's see who won this round...");
  71. Console.ReadKey();
  72. Console.Clear();
  73.  
  74. // Point 3
  75. //first, check if player won
  76.  
  77. // Point 3.1
  78. //check if computer won
  79.  
  80. // Point 3.2
  81. //nobody won - it is a draw
  82.  
  83.  
  84. Console.WriteLine($"Current score: You - {playerWins} : {computerWins} - Me");
  85. Console.ReadKey();
  86. Console.Clear();
  87.  
  88. // check, if it is 5th round
  89. // if so, check who have won and display appropriate message
  90. // if no, game go on
  91. if (round == 5)
  92. {
  93. if (playerWins > computerWins)
  94. {
  95. Console.WriteLine("Congratulations, you have won!");
  96. }
  97. else if (playerWins < computerWins)
  98. {
  99. Console.WriteLine("Unfortunately, you have lost!");
  100. }
  101. else
  102. {
  103. Console.WriteLine("It's a draw!");
  104. }
  105. Console.ReadKey();
  106. }
  107. } while (round < 5);
  108. }
  109.  
  110. //method to draw number of points in one roll
  111. //you can mention that this piece of code is common for the player an the opponent so you don't have to write the same method 2 times
  112. private static int RollDice()
  113. {
  114. //say a few words about Random class - it is a pseudo-random numbers generator
  115. //explain that drawn numbers are based on the system's time
  116. Random random = new Random();
  117.  
  118. //create a helper variable to store a result
  119. //the Next method takes minimum and maximum number from drawing range
  120. //however, it's important that maximum is not included in this range
  121. //players roll three dice so min = 3 and max = 19
  122. int drawnPoints = random.Next(3, 19);
  123.  
  124. return drawnPoints;
  125. }
  126. }
  127. }
  128.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement