forked from puruagarwal1/hacktoberfest-2022-directory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrolling the dice (2-player dice game).py
88 lines (71 loc) · 2.15 KB
/
rolling the dice (2-player dice 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
import random
def roll():
return random.choice([1,2,3,4,5,6])
class player(object):
def __init__(self, name, age, colour):
self.name = name
self.age = age
self.colour = colour
def score(self, score):
self.score = score
def getscore(self):
return self.score
def getname(self):
return self.name
def __str__(self):
return 'NAME: ' + self.name + '\nCOLOUR: ' + self.colour + '\nSCORE: ' + str(self.score)
class game(object):
def __init__(self, playr, trails):
self.trails = trails
self.playr = playr
def gaming(self):
throw = 0
score = 0
for i in range(self.trails):
throw = roll()
if throw == 6:
throw = throw + roll()
score = throw + score
return score
def __str__(self):
return self.playr.getname() + str(self.score)
tri = 123
zack = player('zack', 24, 'green')
johny = player('johny', 25, 'yellow')
kina = player('kina', 14, 'red')
usher = player('usher', 13, 'blue')
print("-----------LETs PLAy THIs GAMe--------------\n" )
#zack.score(88)
#print(zack)
zackscr = game(zack, tri)
johnyscr = game(johny, tri)
kinascr = game(kina, tri)
usherscr = game(usher, tri)
scr = []
scr.append(zackscr.gaming())
scr.append(johnyscr.gaming())
scr.append(kinascr.gaming())
scr.append(usherscr.gaming())
scrsort = sorted(scr)
for el in scrsort:
print(el)
zack.score(scr[0])
usher.score(scr[3])
kina.score(scr[2])
johny.score(scr[1])
#players = []
#players.append(zack.getscore())
#players.append(usher.getscore())
#players.append(kina.getscore())
#players.append(johny.getscore())
# =============================================================================
# =============================================================================
# =============================================================================
# # # = = = = = = == = = = == = = == = = = == = = == = = == = = == == = == == =
#for el in players:
# print('--', el)
#print(scr[0])
print(zack, '\n')
print(kina, '\n')
print(johny, '\n')
print(usher, '\n')