-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
40 lines (33 loc) · 979 Bytes
/
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
import os
import random
import sys
import time
import colorama
class Game:
def __init__(self):
self.history = []
self.plays = [
(colorama.Fore.RED + 'Red', 'r'),
(colorama.Fore.YELLOW + 'Yellow', 'y'),
(colorama.Fore.GREEN + 'Green', 'g'),
(colorama.Fore.BLUE + 'Blue', 'b')
]
def show_level(self):
self.clear()
for h in self.history:
print(h[0], end=' ')
sys.stdout.flush()
time.sleep(1)
self.clear()
def add_move(self):
self.history.append(random.choice(self.plays))
def test_player(self):
print(colorama.Fore.WHITE + "{} moves:".format(len(self.history)))
for t, v in self.history:
guess = input("Next [r, g, b, y]: ")
if guess != v:
return False
return True
# noinspection PyMethodMayBeStatic
def clear(self):
os.system('cls')