forked from JamesB-byte/pythonApps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoll_The_Dice.py
214 lines (157 loc) · 5.08 KB
/
Roll_The_Dice.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
from __future__ import print_function
import random, time, sys
'''
A simple game of craps
'''
player_bet = 0
player_money = 2000
number = 0
D1 = 0
D2 = 0
point = 0
dice_total = 0
dice = 25
#main program
def header():
print("*==========================================================*")
print("To start a round, the player makes a come out roll. *")
print("If the come out roll is a 2, 3, or 12, then the round ends.*")
print("If the come out roll is a 7 or 11, player wins the bet. *")
print("If the roll is 4, 5, 6, 8, 9, or 10 it becomes the point *")
print("If the point is rolled before rolling 7 or 11,player wins. *")
print("*==========================================================*")
def main():
global D1
global D2
global dice_total
global player_money
while player_money > 0 :
D1 = dice_shuffle()
D2 = dice_shuffle()
betting()
come_out()
else:
print("\n")
print("Oh, Im sorry. You're all out of money")
user_input = raw_input("Do you want to play again? (Y/N)")
if user_input in ["Y", "y"]:
player_money = 2000
main()
else:
print("Good bye")
os._exit(1)
def dice_shuffle():
random_list = [1,2,3,4,5,6]
random.shuffle(random_list)
number = random.choice(random_list)
return number
def roller():
global dice
roller = lambda:random.choice('123456')
print("")
for i in range(1,15):
time.sleep(.2)
print('|'.join([roller(),roller()]), end = "\r")
print("*****", end = "\r")
# place the bet
def betting():
global player_bet
print("\n")
print("*============*")
print( "You have $%d " % player_money)
print( "Minumum: $1 ")
print( "Maximum: None")
print( "*============*")
print( "\n")
try:
player_bet = int(raw_input("How much do you want to bet? "))
if player_bet > player_money:
print( "")
print( "You cant bet more than you have.")
print( "Betting maximum amount available")
player_bet = player_money
if player_bet is not int(player_bet):
print( "Please enter a numeric value.")
betting()
else:
player_bet = int(player_bet)
except ValueError:
print( "Please enter a numeric Value")
main()
except IOError:
print( "I/O Error")
def come_out():
global player_bet
global player_money
global D1
global D2
global dice_total
global point
game = True
while game == True:
print( "Lets begin!")
print( "")
raw_input("Press any button to roll your dice. ")
roller()
print("")
dice_total = D1 + D2
print( "*=================================================*")
print( "Your dice rolls are %d and %d." %(D1, D2,))
print( "*=================================================*")
if dice_total in [7,11]:
print("")
print( "$$$$$$$$")
print( "Winner!$")
print( "$$$$$$$$")
player_money = player_money + (player_bet * 2)
D1 = 0
D2 = 0
main()
elif dice_total in [2,3,12]:
player_money = player_money - player_bet
print( "")
print( "!!!!!!")
print( "Craps!")
print( "!!!!!!")
main()
elif dice_total in [4,5,6,8,9,10]:
point = dice_total
if point > 0:
dice_point()
def dice_point():
global D1
global D2
global dice_total
global point
global player_bet
global player_money
print( "*==============*")
print( "The point is %d *" % point)
print( "*==============*")
game = True
while game == True:
user_input = raw_input("Hit any button to roll again ")
roller()
D1 = dice_shuffle()
D2 = dice_shuffle()
dice_total = D1 + D2
print( "*=================================================*")
print( "Your dice rolls are %d and %d for a total of %d." %(D1, D2, dice_total))
print( "*=================================================*")
if dice_total == point:
player_money = player_money + (player_bet * 2)
print( "$$$$$$$$")
print( "Winner!$")
print( "$$$$$$$$")
D1 = 0
D2 = 0
main()
elif dice_total == 7 or dice_total == 11:
player_money = player_money - player_bet
print( "")
print( "!!!!!!")
print( "Craps!")
print( "!!!!!!")
main()
header()
main()