Guest User

Untitled

a guest
May 26th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 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. using System.Collections;
  7.  
  8. namespace Game
  9. {
  10. class Game
  11. {
  12. double balance;
  13. History history = new History();
  14.  
  15. public Game(double balance) {
  16. this.balance = balance;
  17. }
  18. public bool checkResult(int playerNumIsEven, int resultNum)
  19. {
  20. return (playerNumIsEven + resultNum) % 2 == 0;
  21. }
  22. public bool changeBalance(bool result, double bet)
  23. {
  24. balance += result ? bet : -bet;
  25. return balance > 0;
  26. }
  27. public int generateNum () {
  28. return new Random().Next();
  29. }
  30. public void printInfo(bool b ,bool d) {
  31. if (b)
  32. Console.WriteLine("You are win, your balance {0}n", balance);
  33. else
  34. Console.WriteLine("You are lose, your balance {0}n", balance);
  35.  
  36. if (!d) {
  37. Console.WriteLine("balance is emptyn");
  38. theEnd();
  39. }
  40.  
  41. }
  42. public void theEnd() {
  43. history.printInfo();
  44. Console.WriteLine("Enter to exit...");
  45. Console.ReadLine();
  46. Environment.Exit(0);
  47. }
  48.  
  49. public void play() {
  50. while (true)
  51. {
  52. Console.WriteLine("input odd or even, or smt else for exit.");
  53. string forecast = Console.ReadLine().ToLower();
  54. if (forecast != "even" && forecast != "odd")
  55. {
  56. theEnd();
  57. }
  58. else {
  59. double bet;
  60. while (true)
  61. {
  62. Console.WriteLine("input your bet");
  63. while (true) {
  64. bet = double.Parse(Console.ReadLine());
  65. if (bet > 0)
  66. break;
  67. else {
  68. Console.WriteLine("your input is incorrect, please input correct num");
  69. }
  70. }
  71.  
  72.  
  73. if (bet > balance)
  74. Console.WriteLine("incorrect");
  75. else
  76. break;
  77. }
  78. int random = generateNum();
  79. Console.WriteLine("generated num: {0}", random);
  80. bool result = checkResult(forecast == "even" ? 0 : 1, random);
  81. bool ended = changeBalance(result, bet);
  82. history.addToHistory(result, balance);
  83. printInfo(result, ended);
  84. }
  85. }
  86. }
  87. }
Add Comment
Please, Sign In to add comment