-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
57 lines (42 loc) · 1.38 KB
/
main.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
import os
import signal
from rich.console import Console
from rich.prompt import Prompt
from board import Board
from helper import A, B, C
def clear():
os.system("cls" if os.name == "nt" else "clear")
def timer(signum, frame):
raise Exception("Time's up!")
def timed_round():
board = Board()
signal.alarm(60 * TIME_LIMIT)
msg = ""
while True:
try:
clear()
board.display()
if msg:
console.print(f" {msg} ", end="", style="dark_red on white")
console.print("\nGuess a word: ", end="", style="bold orange4")
guess = input().upper().strip().replace("QU", "Q")
msg = board.guess(guess)
except Exception as exc:
console.print(exc, style="bold white on dark_red")
console.print("Your final score was ", style="navajo_white1", end="")
console.print(f" {board.score} ", style="bold white on dark_red")
break
TIME_LIMIT = 3
signal.signal(signal.SIGALRM, timer)
console = Console()
clear()
console.print(A, style="bold navajo_white1")
console.print(B, style="bold orange4")
console.print(C, style="bold red")
while True:
log = Prompt.ask("\nWhat do you want to do?", choices=["start", "quit"])
if log == "quit":
console.print("[magenta]Goodbye\n")
break
if log == "start":
timed_round()