-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDados.py
More file actions
104 lines (92 loc) · 2.74 KB
/
Dados.py
File metadata and controls
104 lines (92 loc) · 2.74 KB
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
from pickle import TRUE
import random
class Dice:
def __init__(self, f):
self.value = 0
self.faces = int(f)
def lanzar(self):
self.value = random.randint(1,self.faces)
class Player:
def __init__(self, name):
self.name = name
self.score = 0
self.wins = 0
class Game:
def __init__(self, dices, rounds, p, f):
self.dices = int(dices)
self.rounds = int(rounds)
self.p = int(p)
self.players = []
self.dice = Dice(f)
def register(self):
print("Welcome, what's your name?: ")
pname = input()
player = Player(pname)
print("\nThank you " + pname + ", Good luck!\n")
self.players.append(player)
def Players(self):
for ply in range(0, self.p):
self.register()
def roundWin(self, scores):
Max = max(scores)
for ply in self.players:
if ply.score == Max:
ply.wins += 1
def winner(self):
Scores = [];
for ply in self.players:
Scores.append(ply.wins)
Max = max(Scores)
for ply in self.players:
if ply.wins == Max:
print("With a total of "+str(ply.wins)+" wins "+ply.name + " is the winner, congratulations!\n")
def play(self):
for rnd in range(0, self.rounds):
scores = [];
print("ROUND "+str(rnd)+"\n")
for ply in self.players:
ply.score = 0
print("It's "+ply.name+"'s turn\n")
for d in range(0, self.dices):
self.dice.lanzar()
ply.score += self.dice.value
print("Scored: "+str(ply.score)+"\n")
scores.append(ply.score)
self.roundWin(scores)
print("Welcome to KrazyDizes\n")
p = True
while p:
players = input("How many players will play: ")
for i in players:
if i not in "1234567890":
print("Invalid input, please try again\n")
else:
p = False
r = True
while r:
rounds = input("\nHow many rounds do you want to play: ")
for i in rounds:
if i not in "1234567890":
print("Invalid input, please try again\n")
else:
r = False
d = True
while d:
dices = input("\nHow many dices per round: ")
for i in dices:
if i not in "1234567890":
print("Invalid input, please try again\n")
else:
d = False
f = True
while f:
faces = input("How many faces per dice: ")
for i in faces:
if i not in "1234567890":
print("Invalid input, please try again\n")
else:
f = False
game = Game(dices, rounds, players, faces)
game.Players()
game.play()
game.winner()