Advertisement
Guest User

CRAPS!

a guest
Feb 28th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. ####################################
  2. # Author: Anthony Romero
  3. # Date: 2/23/2017
  4. ####################################
  5.  
  6. #This program will simulate a game involving rolling dice.
  7. #This program will simulate a game of Craps. It will roll the pair of dice three times. It will keep score for the “house” (the computer), and for the player.
  8. #It will then display these scores each time the dice are rolled based on the rules listed below. It will lastly display a final winner at the end of the game.
  9.  
  10. # First, we have our general variables.
  11.  
  12. Number_of_Rolls = 0
  13.  
  14. Dice1 = 0
  15.  
  16. Dice2 = 0
  17.  
  18. Is_Craps = 0
  19.  
  20. h_score = 0
  21.  
  22. p_score = 0
  23.  
  24. total_h = 0
  25.  
  26. total_p = 0
  27.  
  28. Start_Game = True #Keeps Game in Loop
  29.  
  30. #Now we create our functions.
  31.  
  32. def Check(): # Runs all scenarios.
  33. Craps()
  34. Dble_Evn()
  35. Dble_Odd()
  36. Low()
  37. High()
  38.  
  39. def Craps(): #Logic for CRAPS dice.
  40. global h_score
  41. global Dice1
  42. global Dice2
  43. if Dice1 + Dice2 == 7 or 11:
  44. print ("\nCRAPS!")
  45. h_score += 2
  46. Is_Craps = 1
  47.  
  48. def Dble_Evn(): # Logic for Dble_Evn.
  49. global p_score
  50. global Dice1
  51. global Dice2
  52. if Dice1 == Dice2:
  53. if Dice1 % 2 == 0:
  54. if Dice2 % 2 == 0:
  55. p_score += 2
  56. print ('\nDouble and Even!')
  57.  
  58. def Dble_Odd(): # Logic for Dble_Odd.
  59. global h_score
  60. global Dice1
  61. global Dice2
  62. if Dice1 == Dice2:
  63. if Dice1 % 2 >= 1:
  64. if Dice2 % 2 >= 1:
  65. h_score += 2
  66. print ('\nDouble and Odd!')
  67.  
  68. def Low(): #Logic for lower than seven.
  69. global h_score
  70. global Dice1
  71. global Dice2
  72. if Dice1 != Dice2:
  73. if Dice1 + Dice2 < 7:
  74. if Is_Craps == 0:
  75. h_score += 2
  76. Is_Craps = 0
  77. print ("\nLow!")
  78.  
  79. def High(): # Logic for higher than seven.
  80. global p_score
  81. global Dice1
  82. global Dice2
  83. if Dice1 != Dice2:
  84. if Dice1 + Dice2 > 7:
  85. if Dice1 + Dice2 != 11:
  86. p_score += 2
  87. print ("\nHigh!")
  88.  
  89. def Roll_Dice(): # Logic for the main functioning of the program.
  90. start_dice = 1
  91. global h_score
  92. global p_score
  93. global Dice1
  94. global Dice2
  95. global Number_Of_Rolls
  96. while start_dice == 1: # Begins dice rolling.
  97. Number_Of_Rolls += 1
  98. Dice1 = randint(1, 6)
  99. Dice2 = randint(1, 6)
  100. if Number_Of_Rolls == 1: # Roll 1.
  101. print('Roll 1\n\nDice 1 = {0}\nDice 2 = {1}'.format(Dice1, Dice2))
  102. Check() # checks winner
  103. print('\nYour score: \t{}\nHouse score: \t{}\n'.format(p_score, h_score))
  104. if Number_Of_Rolls == 2: # Roll 2.
  105. input ('Press Enter to continue.')
  106. print('Roll 2\n\nDice 1 = {0}\nDice 2 = {1}'.format(Dice1, Dice2))
  107. Check()# checks winner
  108. print('\nYour score: \t{}\nHouse score: \t{}\n'.format(p_score, h_score))
  109. if Number_Of_Rolls == 3: #Roll 3.
  110. input ('Press Enter to continue.')
  111. print('Roll 3\n\nDice 1 = {0}\nDice 2 = {1}'.format(Dice1, Dice2))
  112. Check()# Checks winner.
  113. print('\nYour score: \t{}\nHouse score: \t{}'.format(p_score, h_score))
  114. start_dice = 0 # Ends rolls after three rolls.
  115.  
  116.  
  117. ################################################################
  118. # Time to begin the game.
  119. ################################################################
  120.  
  121.  
  122.  
  123. input ('Welcome to CRAPS. Press ENTER to begin.')
  124. ### Program begins.
  125. from random import randint # turn on random
  126.  
  127. Start_Game = True # keeps game in loop
  128. while Start_Game is True:
  129. Number_Of_Rolls = 0 #resets last games scores
  130. p_score = 0
  131. h_score = 0
  132. Roll_Dice() # <------ Most of the program is ran by this function
  133. if p_score > h_Score:
  134. total_p += 1 # Player wins
  135. input('\nYou Win!\n\nYour total wins: {}\t House total wins: {}' \
  136. '\n\nPress Enter to start a new game: '.format(total_p, total_h))
  137. if h_score > p_score:
  138. total_h += 1 # House wins
  139. input('\nHouse Wins!\n\nYour total wins: {}\t House total wins: {}' \
  140. '\n\nPress Enter to start a new game: '.format(total_p, total_h))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement