forked from joniszk/Beyond-The-Surface
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
63 lines (49 loc) · 1.6 KB
/
game.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
import PySimpleGUI as sg
import json
# Theme for GUI
sg.theme("DarkBlue14")
def load_questions(level_file):
with open(level_file, 'r') as file:
data = json.load(file)
return data.get("questions", [])
# Layout for level selection screen
level_layout = [
[sg.Text("Choose a level to play:")],
[sg.Button("Level 1"), sg.Button("Level 2"), sg.Button("Level 3")],
[sg.Button("Exit")]
]
# Window for level selection
level_window = sg.Window("Beyond the Surface", level_layout)
selected_level = None
while True:
event, _ = level_window.read()
if event in (sg.WINDOW_CLOSED, "Exit"):
level_window.close()
if event in ("Level 1", "Level 2", "Level 3"):
selected_level = f"{event.lower().replace(' ', '')}.json"
break
level_window.close()
#Load questions based on the selected level
questions = load_questions(selected_level)
#Question Layout
question_layout = [
[sg.Text("Question:", font=("Helvetica", 16), key="-QUESTION-")],
[sg.Button("Next"), sg.Button("Exit")]
]
# Window for prompting questions
question_window = sg.Window("Beyond the Surface", question_layout, finalize=True)
question_index = 0
if questions:
question_window["-QUESTION-"].update(questions[question_index])
while True:
event, _ = question_window.read()
if event in (sg.WINDOW_CLOSED, "Exit"):
break
if event == "Next":
question_index += 1
if question_index < len(questions):
question_window["-QUESTION-"].update(questions[question_index])
else:
sg.popup("You have completed the level!")
break
question_window.close()