-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
89 lines (49 loc) · 1.93 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
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
import os
from typing import Final
from sceneManager import *
#SETUP
#from coloredText import *
SCENE_DIR: Final[str] = "scenes"
#scenes = readScenes(SCENE_DIR)
globalctx = GlobalContext(SCENE_DIR, "global", "start")
#globalctx.setActiveScene("start")
#UTILITY FUNCTIONS
#clears the screen and prints the active scene
def printActiveScene():
#clears the terminal
os.system('cls')
#selects the text for the available interactions
interactions_list = list(globalctx.active_scene.nextInteractions().keys())
#print prompt
print(globalctx.active_scene.nextPrompt().text)
print("\n")
#print interactions
for i in range(len(interactions_list)):
print(f"{i+1}: {interactions_list[i]}")
#activates interactions in current scene based on number input
def interact(interaction_number):
# the try/except/else block will handle any bad inputs because it will only run if a valid number choice is entered,
# otherwise it will just refresh the screen. If an error arises at another point
# it will still allow that error through for debugging purposes
try:
interaction_number = int(interaction_number)
#gets interactions that fit requirements
interactions_list = list(globalctx.active_scene.nextInteractions().values())
except:
return None
else:
if ((interaction_number > 0) and (interaction_number <= len(interactions_list))):
updateStates(interactions_list[interaction_number-1], globalctx)
else:
return None
#GAMELOOP
while True:
#clears the screen and prints the active scene
printActiveScene()
interact(input())
#IDEAS
"""
DONE BY JACK!!!!!!!!!!!!! Add support for if the player inputs something other than a number or an out of range number
DONE BY GABO!!!!!!!!!!!!!! impletment changing of states with global.active_scene
add support for math operators in interaction requirements
"""