Advertisement
DevUModerator

Untitled

Nov 11th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. namespace ChallengeCasino
  2. {
  3. public partial class Default : System.Web.UI.Page
  4. {
  5. Random randomLocationValue = new Random();
  6.  
  7. protected void Page_Load(object sender, EventArgs e)
  8. {
  9. if (!Page.IsPostBack)
  10. {
  11. DisplayFirstImage();
  12. DisplaySecondImage();
  13. DisplayThirdImage();
  14. }
  15. }
  16. protected void okButton_Click(object sender, EventArgs e)
  17. {
  18. DisplayFirstImage();
  19. DisplaySecondImage();
  20. DisplayThirdImage();
  21. DisplayWinOrLoss();
  22. DisplayPlayerBalance();
  23.  
  24. }
  25. protected string ImageAddress(int randomLocationValue)
  26. {
  27. string myImage;
  28. string[] imageLocation = new string[] { "Images/Bar.png", "Images/Bell.png", "Images/Cherry.png", "Images/Clover.png", "Images/Diamond.png",
  29. "Images/HorseShoe.png", "Images/Lemon.png", "Images/Orange.png", "Images/Plum.png", "Images/Seven.png", "Images/Strawberry.png", "Images/Watermellon.png"};
  30. return myImage = imageLocation[randomLocationValue];
  31. }
  32. protected int FirstImageLocation()
  33. {
  34. int firstImage = randomLocationValue.Next(0, 11);
  35. return firstImage;
  36. }
  37. protected int SecondImageLocation()
  38. {
  39. int secondImage = randomLocationValue.Next(0, 11);
  40. return secondImage;
  41. }
  42. protected int ThirdImageLocation()
  43. {
  44. int thirdImage = randomLocationValue.Next(0, 11);
  45. return thirdImage;
  46. }
  47. protected int DisplayFirstImage()
  48. {
  49. int myFirstImage = FirstImageLocation();
  50. firstImage.ImageUrl = ImageAddress(myFirstImage);
  51. firstImagePositionResultLabel.Text = String.Format("First Image location {0}", myFirstImage);
  52. return myFirstImage;
  53. }
  54. protected int DisplaySecondImage()
  55. {
  56. int mySecondImage = SecondImageLocation();
  57. secondImage.ImageUrl = ImageAddress(mySecondImage);
  58. secondImagePositionResultLabel.Text = String.Format("Second Image location {0}", mySecondImage);
  59. return mySecondImage;
  60. }
  61. protected int DisplayThirdImage()
  62. {
  63. int myThirdImage = ThirdImageLocation();
  64. thirdImage.ImageUrl = ImageAddress(myThirdImage);
  65. thirdImagePositionResultLabel.Text = String.Format("Third Image location {0}", myThirdImage);
  66. return myThirdImage;
  67. }
  68. protected int PlayerStartingMoney()
  69. {
  70. return 100;
  71. }
  72. protected int BetAmount()
  73. {
  74. int betValue = int.Parse(yourBetTextBox.Text);
  75. return betValue;
  76. }
  77. protected bool CheckForBar()
  78. {
  79. bool validateForBar = false;
  80. if (DisplayFirstImage() == 0 || DisplaySecondImage() == 0 || DisplayThirdImage() == 0)
  81. {
  82. validateForBar = true;
  83. }
  84. return validateForBar;
  85. }
  86. protected bool CheckForSeven()
  87. {
  88. bool validateForSeven = false;
  89. if (DisplayFirstImage() == 9 && DisplaySecondImage() == 9 && DisplayThirdImage() == 9)
  90. {
  91. validateForSeven = true;
  92. }
  93. return validateForSeven;
  94. }
  95. protected bool CheckForCherry()
  96. {
  97. bool validateForCherry = false;
  98. if (DisplayFirstImage() == 2 || DisplaySecondImage() == 2 || DisplayThirdImage() == 2)
  99. {
  100. validateForCherry = true;
  101. }
  102. return validateForCherry;
  103. }
  104. protected int BarReturnValue()
  105. {
  106. return 0;
  107. }
  108. protected int SevenReturnValue()
  109. {
  110. return 100 * BetAmount();
  111. }
  112. protected int CherryMultiplier()
  113. {
  114. int multiplier = 0;
  115. if (DisplayFirstImage() == 2) multiplier++;
  116. if (DisplaySecondImage() == 2) multiplier++;
  117. if (DisplayThirdImage() == 2) multiplier++;
  118. return multiplier * BetAmount();
  119. }
  120. protected int CalculateWinAmount()
  121. {
  122. if (CheckForBar() == true)
  123. {
  124. return BarReturnValue();
  125. }
  126. else if (CheckForSeven() == true)
  127. {
  128. return SevenReturnValue();
  129. }
  130. else if (CheckForCherry() == true)
  131. {
  132. return CherryMultiplier();
  133. }
  134. else
  135. {
  136. return 0;
  137. }
  138. }
  139. protected void DisplayWinOrLoss()
  140. {
  141. int winningAmount = CalculateWinAmount();
  142. if (winningAmount > 0)
  143. {
  144. resultLabel.Text = String.Format("You bet {0:C} and won {1:C}", BetAmount(), winningAmount);
  145. }
  146. else
  147. {
  148. resultLabel.Text = String.Format("Sorry, you lost {0:C}. Better luck next time.", BetAmount());
  149. }
  150. }
  151. static int balance = 100;
  152.  
  153. protected int PlayerBalance()
  154. {
  155.  
  156. int winAmount = CalculateWinAmount();
  157. if (winAmount > 0)
  158. {
  159. balance += winAmount;
  160. }
  161. else
  162. {
  163. int betAmount = BetAmount();
  164. balance -= betAmount;
  165. }
  166.  
  167. return balance;
  168. }
  169. protected double ValidateForOkButton()
  170. {
  171. int myBalane = PlayerBalance();
  172. return myBalane;
  173. }
  174. protected void DisplayPlayerBalance()
  175. {
  176. int myBalance = PlayerBalance();
  177. playerTotalAmountLabel.Text = myBalance.ToString();
  178. if (myBalance <= 0)
  179. {
  180. okButton.Enabled = false;
  181. }
  182. }
  183.  
  184. }
  185. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement