-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
126 lines (103 loc) · 3.69 KB
/
Copy pathcli.py
File metadata and controls
126 lines (103 loc) · 3.69 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"""
Silicon Valley Trail — entry point.
Run with:
python cli.py
"""
from enum import IntEnum
from silicon_valley_trail.models.game_state import GameState
from silicon_valley_trail.engine.game_loop import run_game
from silicon_valley_trail.storage import save_game, load_game, delete_save
class MenuOption(IntEnum):
NEW_GAME = 1
LOAD_GAME = 2
QUIT = 3
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
def _get_choice(max_option: int) -> int:
while True:
try:
raw = input(f"\nEnter choice (1-{max_option}): ").strip()
value = int(raw)
if 1 <= value <= max_option:
return value
except (ValueError, EOFError):
pass
print(f"Please enter a number between 1 and {max_option}.")
def _press_enter() -> None:
try:
input("\nPress Enter to continue...")
except EOFError:
pass
# ---------------------------------------------------------------------------
# Intro
# ---------------------------------------------------------------------------
def _show_intro() -> None:
print()
print("=" * 60)
print(" SILICON VALLEY TRAIL")
print("=" * 60)
print()
print(" Your scrappy startup team is heading from San Jose")
print(" to San Francisco to pitch for Series A funding!")
print()
print(" Manage your resources wisely:")
print(" Cash — don't run out")
print(" Morale — keep the team happy")
print(" Coffee — essential fuel (2 days without = game over)")
print(" Hype — public interest in your startup")
print(" Bugs — keep them under control (20 = game over)")
print()
print(" Your team:")
print(" Kay [backend] — core founder, never leaves")
print(" Hanna [frontend] — design & UI, watch out for poaching")
print(" Leo [product] — full-stack visionary, burns out if pushed")
print()
print(" Good luck, founder!")
print("=" * 60)
_press_enter()
# ---------------------------------------------------------------------------
# Main menu
# ---------------------------------------------------------------------------
def _main_menu() -> None:
while True:
print()
print("=" * 60)
print(" SILICON VALLEY TRAIL")
print("=" * 60)
print(" 1. New Game")
print(" 2. Load Game")
print(" 3. Quit")
choice = MenuOption(_get_choice(len(MenuOption)))
if choice == MenuOption.NEW_GAME:
_show_intro()
name = input("Enter your name for the leaderboard: ").strip() or "Anonymous"
state = GameState(player_name=name)
run_game(
state,
save_callback=save_game,
quit_callback=lambda: None,
)
delete_save()
elif choice == MenuOption.LOAD_GAME:
state = load_game()
if state is None:
print("\nNo saved game found.")
_press_enter()
continue
print("\nGame loaded successfully!")
_press_enter()
run_game(
state,
save_callback=save_game,
quit_callback=lambda: None,
)
delete_save()
elif choice == MenuOption.QUIT:
print("\nSee you on the trail!\n")
break
# ---------------------------------------------------------------------------
# Entry point
# ---------------------------------------------------------------------------
if __name__ == "__main__":
_main_menu()