-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole_main.py
67 lines (52 loc) · 1.65 KB
/
console_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
58
59
60
61
62
63
64
65
66
67
import os
import sys
from Console.console_controller import ConsoleController
from Console.console_field import ConsoleField
from Model.ball_generator import BallGenerator
from Model.score_board import ScoreBoard
from utils import create_parser
def cls():
os.system('cls' if os.name == 'nt' else 'clear')
def main():
parser = create_parser()
game_field = ConsoleField(parser.size)
controller = ConsoleController(
game_field,
ScoreBoard.load_from(parser.records, parser.hint_mode),
parser.debug)
BallGenerator.place_balls(ConsoleField(parser.size),
controller,
BallGenerator.generate_balls(10, parser.debug,
False))
cls()
print("""Hello there!
to start playing print 'start'
use 'help' to get other commands
Good luck!""")
while not controller.is_over:
try:
run_command(controller)
except (KeyboardInterrupt, EOFError):
print("\nTo stop the game type 'exit'")
while 1:
cls()
print("""Game Over
You scored {} points
Please input your name
""".format(controller.current_score))
try:
controller.score_table.set_name(input())
break
except ValueError as e:
print(e)
controller.score_table.save()
def run_command(controller):
cmd = input()
cls()
try:
controller.execute(cmd)
except Exception as e:
print(e, file=sys.stderr)
print("Use \"help\" for help", file=sys.stderr)
if __name__ == '__main__':
main()