forked from shivangdubey/HacktoberFest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdie_game.py
148 lines (139 loc) · 4.54 KB
/
die_game.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
import random
import pandas as pd
def leaderboard():
data = pd.read_csv('Players.csv')
data["Rank"] = data["Points Per Game"].rank(ascending = False)
data.sort_values("Points Per Game",ascending = False,inplace = True)
print(data)
def update():
pass
def menu():
print('-'*20)
print("Welcome To DIE Game Menu")
print("TO play - 1")
print("TO see Leaderboard -2")
print("To exit press anything else !")
print('-'*20)
choice = input()
if choice == '1':
input('Press anything to start the game')
stage=1
StartGame(stage)
if user1.tot_score > user2.tot_score :
winner = user1.name
elif user1.tot_score < user2.tot_score :
winner = user2.name
else :
print("Scores are tied so each of you roll a single die until either of you wins ")
winner = tiegame()
print(winner," Won!")
update()
menu()
elif choice == '2':
leaderboard()
else :
quit()
class Die:
def roll_die(self):
self.roll = random.randint(1,7)
class User:
def __init__(self,name):
self.name = name
self.score = [0,0,0,0,0]
self.tot_score = 0
print("-"*25)
print(" "*9,"LOGIN")
name1 = input("Player 1 Name ")
df = pd.read_csv('Players.csv')
if len(df[df.Player == name1]) :
auth = 1
name2 = input("Player 2 Name ")
if len(df[df.Player == name2]) :
auth = 2
if auth == 2 :
user1=User(name1)
user2=User(name2)
menu()
else :
print("Sorry You are not authorised to play this game")
quit()
def StartGame(stage):
if(stage<=5):
print(stage," Dice roll of ",user1.name)
input("Press any key to roll dice")
die1=Die()
die2=Die()
die1.roll_die()
die2.roll_die()
sum1 = die1.roll + die2.roll
print("DIE-1 : ",die1.roll,"\nDIE-2 : ",die2.roll)
if (sum1 % 2 == 0):
sum1 = sum1 + 10
if(die1.roll == die2.roll):
print("YAAY you rolled doubles.So you get to roll one die again")
input("Press any key to roll die")
die1.roll_die()
sum1 = sum1 + die1.roll
else:
sum1 = sum1 - 5
user1.score[stage-1]=sum1
user1.tot_score=user1.tot_score+sum1
if (user1.tot_score < 0 ):
user1.tot_score = 0
print(stage,"round score of ",user1.name," is ",sum1)
print("Total Score of ",user1.name," :",user1.tot_score)
###########################################################################################
print(stage," Dice roll of ",user2.name)
input("Press any key to roll die")
die1 = Die()
die2 = Die()
die1.roll_die()
die2.roll_die()
sum2 = die1.roll + die2.roll
print("DIE-1 : ",die1.roll,"\nDIE-2 : ",die2.roll)
if (sum2 % 2 == 0):
sum2 = sum2 + 10
if(die1.roll == die2.roll):
print("YAAY you rolled doubles.So you get to roll one die again")
input("Press any key to roll die")
die1.roll_die()
sum2 = sum2 + die1.roll
else:
sum2 = sum2 - 5
user2.score[stage - 1] = sum2
user2.tot_score = user2.tot_score + sum2
if (user2.tot_score < 0 ):
user2.tot_score = 0
print(stage,"round score of ",user2.name," is ",sum2)
print("Total Score of ",user2.name," :",user2.tot_score)
print(' '*10,"SCORE BOARD")
print('-'*20)
print("PLAYER NAME ",' '*5,"ROUND-1 "," Round-2 "," Round-3 "," Round-4 "," Round-5 "," Total Score")
print(user1.name,' '*5,user1.score[0],user1.score[1],user1.score[3],user1.score[4],user1.tot_score)
print(user2.name,' '*5,user2.score[0],user2.score[1],user2.score[3],user2.score[4],user2.tot_score)
stage = stage + 1
StartGame(stage)
else:
return 0
def tiegame() :
specialdie = Die()
specialdie.roll_die()
input("Press a key to roll die")
sum1 = specialdie.roll
user1.tot_score = user1.tot_score + sum1
print("You rolled ",sum1)
print(user1.name," Toatal score is ",user1.tot_score)
specialdie.roll_die()
input("Press a key to roll die")
sum2 = specialdie.roll
user2.tot_score = user2.tot_score + sum1
print("You rolled ",sum2)
print(user2.name," Toatal score is ",user2.tot_score)
if(sum1 > sum2):
return user1.name
elif(sum2 > sum1):
return user2.name
else :
tiegame()
if __name__=="__main__":
pass