-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainMenu.py
43 lines (36 loc) · 1.57 KB
/
MainMenu.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
import TicTacToe, Hangman, SpaceInvaders, RockPaperScissors, Blackjack, LightCycle
def choose_option(filename):
"""
1) Takes in a text file's name as a string (e.g. "settings.txt")
- First line in text file should contain dialogue to be displayed
- Subsequent lines should contain the list of options, with one line for each option
- Each option should have a Displayed value followed by an Actual value. Both are to be
seperated by the character "|"
2) Prompts user for input with a dialogue consisting of first line in text file + each option's
Displayed value and the corresponding input to select it.
3) Repeats step 2 until a valid input is received
4) Executes the Actual value of the option corresponding to selected input
"""
options, dialogue2 = [], ""
# read file, generate dialogue
with open(filename, "r") as f:
dialogue1 = f.readline().strip()
for index, line in enumerate(f):
opt = line.split("|")
options.append(opt)
dialogue2 += f"\n'{index+1}' for {opt[0]}"
f.close()
selected_opt = 0
# prompts user for input until a valid input is received
while selected_opt == 0:
selection = input(f"\n{dialogue1} {dialogue2}\n")
if selection.upper() == "EXIT":
return
elif 0 < int(selection) <= len(options):
selected_opt = options[int(selection)-1][1]
else:
print("Invalid input!\n")
print("")
exec(selected_opt)
choose_option("gamelist.txt")
choose_option("gamelist.txt")