generated from Code-Institute-Org/python-essentials-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
98 lines (81 loc) · 2.82 KB
/
run.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
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
"""
Main Python terminal for the 'Fury' game.
This file contains the main logic and entry point for the 'Fury' game. It
imports various modules to handle game functionality such as displaying the
game logo, simulating a typewriter effect, displaying prompts to the user,
loading game data, displaying the main menu, processing user input, and
interacting with Google Sheets to store high scores.
"""
import sys
import time
from colorama import Fore, Style
from art import MAIN_LOGO, LOGO_2, LINE
from modules.main_menu import process_main_menu_choice
from modules.google_sheets import get_highscores_worksheet
from utils.cs import clear_screen
GREEN = Fore.GREEN
CYAN = Fore.CYAN
YELLOW = Fore.YELLOW
RED = Fore.RED
BOLD = Style.BRIGHT
RESET = Style.RESET_ALL
def typewriter(text, delay=0.05):
"""
Simulates a typewriter effect by printing out the characters
in the given text string one by one with a specified delay.
"""
for char in text:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(delay)
print()
def continue_prompt():
"""
Displays a prompt asking the user if they want to continue, and returns
True if the user enters 'y', and False if they enter 'n'.
If the user enters an invalid input, the prompt will be repeated until
a valid input is given.
"""
while True:
print(f"{BOLD}{GREEN}READY TO PLAY?{RESET} (y/n): ", end="")
user_input = input(f"{BOLD}{CYAN}\n>>> {RESET}").lower()
if user_input == 'y':
clear_screen()
return True
if user_input == 'n':
clear_screen()
return False
print(f"{RED}Invalid input. Please try again.{RESET}")
def load_game():
"""
Simulates loading game data by printing out a series of loading messages
with a typewriter effect.
"""
print(LOGO_2)
print(LINE)
loading_messages = [
f"{YELLOW}Loading game data{RESET}...",
f"{YELLOW}Loading fury tanks{RESET}...",
f"{YELLOW}Loading battle coordinates{RESET}..."
]
for message in loading_messages:
typewriter(message)
if __name__ == "__main__":
print(MAIN_LOGO)
if continue_prompt():
load_game()
highscores_worksheet = get_highscores_worksheet()
GAME_LOADED = False
while True:
if not GAME_LOADED:
game_loaded_msg = (
f"{BOLD}{GREEN}Game has loaded successfully!{RESET}"
)
typewriter(game_loaded_msg + "\n")
GAME_LOADED = True
clear_screen()
process_main_menu_choice(highscores_worksheet)
else:
typewriter(f"\n{YELLOW}Shutting down the system...{RESET}\n")
print(f"Press {BOLD}{RED}'RESTART GAME'{RESET} button")
print("at the top of the screen to start again.")