-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_logic.py
39 lines (31 loc) · 1020 Bytes
/
game_logic.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
import random
class Game:
def __init__(self):
self.number = random.randint(1, 11)
self.num_guesses = 0
self.guessed = False
self.guess_status = ""
def guess(self, guess):
if guess < self.number:
self.num_guesses += 1
self.guess_status = "Your guess is too low"
elif guess > self.number:
self.num_guesses += 1
self.guess_status = "Your guess is too high"
else:
self.num_guesses += 1
self.guessed = True
self.guess_status = "Your guess is correct"
def check_win(self):
if self.guessed is True and self.num_guesses <= 3:
return "win"
else:
if self.guessed is False and self.num_guesses < 3:
return "play"
else:
return "lose"
def reset(self):
self.number = random.randint(1, 11)
self.num_guesses = 0
self.guessed = False
self.guess_status = ""