-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.py
More file actions
80 lines (63 loc) · 2.38 KB
/
game.py
File metadata and controls
80 lines (63 loc) · 2.38 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
from sequence import Sequence
from player import Player
import time
import os
class Game:
def __init__(self):
self.display = None
self.sequence = Sequence()
self.player = Player()
def initialize_player(self):
"""insert player's attributes in game"""
self.player.user_name()
#def initialize_sequence(self):
#self.sequence.random_sequence()
def launch_sequence(self):
"""get and display simon's sequences in amount of time"""
self.random_difficulty()
self.sequence.random_sequence()
for i in self.sequence.number:
print(i)
time.sleep(self.display_difficulty())
self.clear_screen()
def clear_screen(self):
"""erase display on screen"""
os.system('clear' if os.name =='posix' else 'cls')
def player_turn(self):
"""get input from the player"""
try:
return int(input("Your turn !: "))
except ValueError:
print("Wrong entry, retry.")
self.player_turn()
def comparison(self):
"""simon's rules: check if the input is the same than sequence"""
for element in self.sequence.number:
player_choice = self.player_turn()
self.clear_screen()
if player_choice != element:
self.sequence.number = []
return False
def level_difficulty(self):
self.difficulty = input("Choose the difficulty : easy, medium, hard: \n").lower()
try:
assert self.difficulty == "easy" or self.difficulty == "medium" or self.difficulty == "hard"
except AssertionError as a:
self.level_difficulty()
def display_difficulty(self):
"""set the speed of display"""
if self.difficulty == "easy":
self.display = 3
if self.difficulty == "medium":
self.display = 2
if self.difficulty == "hard":
self.display = 1
return self.display
def random_difficulty(self): # set the range of self.number
if self.difficulty == "easy":
self.sequence.last_number = 10
if self.difficulty == "medium":
self.sequence.last_number = 50
if self.difficulty == "hard":
self.sequence.last_number = 100
return self.sequence.last_number