forked from techphenom/casino-games
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Casino.py
90 lines (76 loc) · 2.32 KB
/
Casino.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
import blackjackTable
import videoPoker
class Player(object):
def __init__(self, name, bankroll=0):
self.name = name
self.bankroll = bankroll
def __str__(self):
return "{}'s bankroll = ${}".format(self.name, self.bankroll)
def getName(self):
return self.name
def getBankroll(self):
return self.bankroll
def increaseBankroll(self, amount):
self.bankroll += amount
def decreaseBankroll(self, amount):
self.bankroll -= amount
def getHighScore():
try:
f = open('highscore.txt', 'r')
except:
return "No high score yet."
highScore = f.read().split(':')
f.close()
return "Current High Score = " + highScore[0] + " - $" + highScore[1]
def updateHighScore(name, highScore):
'''Check if new score is better than old high
score and update the results.'''
try:
f = open('highscore.txt', 'r+')
oldHighScore = f.read().split(':')
if int(oldHighScore[1]) < highScore:
f.seek(0)
f.write(name+":"+str(highScore))
f.close()
else:
f.close()
except IOError:
f = open('highscore.txt', 'w+')
f.write(name+":"+str(highScore))
f.close()
def setDifficulty(difficulty, name):
if difficulty.lower() == 'novice' or difficulty == '3000':
return Player(name, 3000)
elif difficulty.lower() == 'weekend gambler' or difficulty == '2000':
return Player(name, 2000)
elif difficulty.lower() == 'pro' or difficulty == '1000':
return Player(name, 1000)
def main():
print("Welcome to the casino! May the odds be ever in your favor.")
name = input("What is your name? ")
difficulty = input("What type of gambler are you? Novice($3000), Weekend Gambler ($2000), Pro ($1000)? ")
player = setDifficulty(difficulty, name)
while True:
mainChoice = input('''Now, what would you like to do?
Check High Score = 1
Check Current Bankroll = 2
Play Blackjack = 3
Play Video Poker = 4
Go home = 5\n''')
if mainChoice == '1':
print(getHighScore())
elif mainChoice == '2':
print("Your current bankroll = $" + str(player.getBankroll()))
elif mainChoice == '3':
blackjackTable.main(player)
elif mainChoice == '4':
videoPoker.main(player)
elif mainChoice == '5':
updateHighScore(player.getName(), player.getBankroll())
break
else:
print(mainChoice, "wasn't one of your options")
continue
print("Thank you for playing and come again soon!")
if __name__ == '__main__':
main()