Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Help
  8. {
  9. class Program
  10. {
  11. class Player
  12. {
  13. public string name;
  14. public int winCount;
  15. public int lastRoll;
  16. public bool turn;
  17.  
  18. public Player(string Name)
  19. {
  20. name = Name;
  21. }
  22. }
  23. class TennisGame
  24. {
  25. static Random rand = new Random();
  26. private bool game;
  27. private int wins;
  28. private Player winner;
  29.  
  30. public static int GetScore()
  31. {
  32. int score = rand.Next(7);
  33. return score;
  34. }
  35.  
  36. public Player Game(Player player1, Player player2)
  37. {
  38. player1.turn = true;
  39. player2.turn = false;
  40.  
  41. game = true;
  42. while (game == true)
  43. {
  44. if (player1.turn == true && player2.turn == false && wins != 5)
  45. {
  46. var roll = GetScore();
  47.  
  48. if (roll==6)
  49. {
  50. player1.winCount++;
  51. wins++;
  52.  
  53. Console.WriteLine(player1.name + " " + roll + " " + " - " + " " + player2.lastRoll + " " + player2.name);
  54. }
  55.  
  56. player1.lastRoll = roll;
  57. player1.turn = false;
  58. player2.turn = true;
  59.  
  60. }
  61.  
  62. if (player2.turn == true && player1.turn == false && wins != 5)
  63. {
  64. var roll = GetScore();
  65.  
  66. if (roll == 6)
  67. {
  68. player2.winCount++;
  69. wins++;
  70.  
  71. if (wins == 5)
  72. {
  73. game = false;
  74. }
  75.  
  76. Console.WriteLine(player1.name + " " + player1.lastRoll + " " + " - " + " " + roll + " " + player2.name);
  77. }
  78.  
  79. player2.lastRoll = roll;
  80. player2.turn = false;
  81. player1.turn = true;
  82. }
  83.  
  84. if(wins == 5)
  85. {
  86. if (player1.winCount > player2.winCount)
  87. {
  88. Console.WriteLine(player1.name + " Won!");
  89. winner = player1;
  90. }
  91. else
  92. {
  93. Console.WriteLine(player2.name + " Won!");
  94. winner = player2;
  95. }
  96.  
  97.  
  98. game = false;
  99.  
  100. }
  101. }
  102. return winner;
  103. }
  104.  
  105.  
  106.  
  107. static void Main(string[] args)
  108. {
  109. var p1 = 0;
  110. var p2 = 0;
  111.  
  112. for (int i = 0; i < 1000; i++)
  113. {
  114. TennisGame game = new TennisGame();
  115. var player = game.Game(new Player("Nitcho"), new Player("Mathias"));
  116.  
  117. if (player.name == "Nitcho")
  118. p1++;
  119. else
  120. p2++;
  121. }
  122.  
  123. Console.WriteLine("Nitcho: " + p1 + " - " + p2 + " Mathias");
  124.  
  125. Console.ReadLine();
  126. }
  127. }
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement