-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
106 lines (92 loc) · 3.02 KB
/
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
from enum import Enum
import random
class Choice(Enum):
NONE = 0
ROCK = 1
PAPER = 2
SCISSORS = 3
class MatchResult(Enum):
LOSE = 0
WIN = 1
class Game:
def __init__(self, window):
self.round = 1
self.updateCount = 0
self._delay = False
self.aiHand = Choice.NONE
self._continue = True
self._isEnded = False
self.window = window
def update(self, playerHand):
# print(self.updateCount == 201)
if self._delay:
self.updateCount += 1
if self._isEnded:
if self.updateCount == 70:
self.window.winlose.setText(f"{self.round - 2}점")
if self.updateCount >= 200:
self._delay = False
self.updateCount = 0
self.window.gameEnd()
else:
if self.updateCount >= 60:
self._delay = False
self.updateCount = 0
self.window.updateToQ()
return
self.window.updateTime()
if self._continue:
self.updateCount += 1
if self.updateCount >= 50: # CheckHand
if playerHand == Choice.NONE:
self._continue = False
else:
self.window.updateWinLose(self.match(playerHand))
self.updateCount = 0
self._delay = True
self.round += 1
else:
if playerHand == Choice.NONE:
return
else:
self._continue = True
self.window.updateWinLose(self.match(playerHand))
self.updateCount = 0
self._delay = True
self.round += 1
def match(self, playerHand):
if self.round <= 3: # 기본으로 3점 주고 시작하자
if playerHand == Choice.ROCK:
self.aiHand = Choice.SCISSORS
elif playerHand == Choice.PAPER:
self.aiHand = Choice.ROCK
else:
self.aiHand = Choice.PAPER
self.window.updateAiImage()
return MatchResult.WIN
while True:
self.aiHand = Choice(random.randrange(1, 4))
if playerHand == self.aiHand:
continue
else:
break
self.window.updateAiImage()
if playerHand == Choice.ROCK:
if self.aiHand == Choice.PAPER:
return MatchResult.LOSE
else:
return MatchResult.WIN
elif playerHand == Choice.PAPER:
if self.aiHand == Choice.SCISSORS:
return MatchResult.LOSE
else:
return MatchResult.WIN
else: # SCISSOR
if self.aiHand == Choice.ROCK:
return MatchResult.LOSE
else:
return MatchResult.WIN
def gameEnd(self):
self.updateCount = 0
self._delay = True
self._isEnded = True