forked from MicrosoftDocs/mslearn-python-oo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rock-paper-scissor-2.py
59 lines (56 loc) · 1.69 KB
/
rock-paper-scissor-2.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
class Participant:
def __init__(self, name):
self.name = name
self.points = 0
self.choice = ""
def choose(self):
self.choice = input("{name}, select rock, paper or scissor: ".format(name=self.name))
print("{name} selects {choice}".format(name=self.name, choice=self.choice))
def toNumericalChoice(self):
switcher = {
"rock": 0,
"paper": 1,
"scissor": 2
}
return switcher[self.choice]
def incrementPoint(self):
self.points += 1
class GameRound:
def __init__(self, p1, p2):
self.rules = [
[0, -1, 1],
[1, 0, -1],
[-1, 1, 0]
]
p1.choose()
p2.choose()
result = self.compareChoices(p1, p2)
print("Round resulted in a {result}".format(result=self.getResultAsString(result)))
if result > 0:
p1.incrementPoint()
elif result < 0:
p2.incrementPoint()
def compareChoices(self, p1, p2):
return self.rules[p1.toNumericalChoice()][p2.toNumericalChoice()]
def awardPoints(self):
print("implement")
def getResultAsString(self, result):
res = {
0: "draw",
1: "win",
-1: "loss"
}
return res[result]
class Game:
def __init__(self):
self.endGame = False
self.participant = Participant("Spock")
self.secondParticipant = Participant("Kirk")
def start(self):
game_round = GameRound(self.participant, self.secondParticipant)
def checkEndCondition(self):
print("implement")
def determineWinner(self):
print("implement")
game = Game()
game.start()