-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
199 lines (179 loc) · 6.11 KB
/
main.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#NOTE: idea for fixing the break to title or brake to main functions without needing to use exception calls.
# Use genertors. Like in a previus version of this project, have a yield statement on every call that invokes game.update.
# Problem 1: What will the generators yield? Just a "everything is ok here"-true boolean?
# problem 2: What about sub-processes that invoke game.update?
# 1: void. It should not matter what the yield it, as long as the chain can be broken in the game loop.
# 2: Their function can be yielded to the game loop, where they will be put on a stack and ran as the current function.
#!!! ding ding! There it is. I just re-invented the call stack. But this might just be what I need.
# The outer game loop would work thusly:
# * Get place (function / generator)
# * end game with error if not found
# * Check for game over
# * end game if game over
# * start new call-stack
# * insert place-generator in stack
# * start inner game loop
# The inner game loop would work like this:
# * Check if stack is empty
# * if so, break out of inner loop (return)
# * try
# * fetch next element in current function
# * check if element is a generator.
# * if so, add element to top of stack
# * check if break to main or break to title is triggured
# * if so, break out of inner game loop (return)
# * catch/except - end of function error
# * remove current function from stack.
#
# But what if I could access the call stack directly? If I could, then maybe I won't even need to make generator functions.
# Must be reseached!
import os
import time
import random
import json
import types
#from tkinter import *
import tkinter as TK
from tkinter import messagebox as TKmsg
import ui
import Game
import Storyloader
from untitled_const import ReturnToMain
from untitled_const import ReturnToTitle
import room_apartment
import middlering
import Bathrooms
import Ladder
import Core
import Cafeteria
import outer
import inner
#version number. Major, minor, hotfix.
VERSION = [1, 4, 1]
#if dev is on, some debug info may be displayed in the game
DEV = True
def start():
tkRoot = TK.Tk(screenName="UNTITLED! The adventure game")
tkRoot.geometry("1600x900")
game = Game.Game(tkRoot, VERSION, "english")
while True:
try:
titleMenu(game)
except ReturnToTitle:
continue
except SystemExit:
break
def _testloop(game:Game, Testcall:callable, Datacall:callable, name:str):
frags = {'_NAME':name}
Datacall()
game.rolltext("""
-----------------------------------------------
THIS IS A MODULE TEST FOR {_NAME}.
FOR FULL PLAY, PLEASE RUN FROM main.py INSTEAD.
-----------------------------------------------""",frags=frags)
while True:
try:
Testcall(game)
except (SystemExit):
break
game.rolltext("""
------------------------------------
END OF MODULE TEST FOR {_NAME}.
------------------------------------""",frags=frags)
if game.yesno(message="REPEAT TEST?"):
if game.yesno(message="CLEAN THE SAVEDATA?"):
Datacall()
else:
break
def game_loop(game:Game):
world = {
"apartment" : room_apartment.Start,
"core" : Core.Core,
"inner" : inner.Start,
"middle" : middlering.Start,
"outer" : outer.Start,
"ladder" : Ladder.Start,
"bathrooms" : Bathrooms.Start,
"cargobay" : Core.Cargobay,
"cafeteria" : Cafeteria.Start
}
while True:
placeReq = game.place
if(placeReq == None): #newgame location
placeReq = "apartment"
#space to check for special conditions
game_over = game.getGameover()
if(game_over):
game.showtext("""
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾\\_GAME_OVER_/‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
{0}
_________________________________________________
""".format(game_over))
break
#general rule
place = None
try:
place = world[placeReq]
except:
place = None
if(place):
game.EnableMenu()
try:
place(game)
except (ReturnToMain):
#ReturnToMain is called when new game or load game is called from outside the title menu.
continue
game_over = game.getGameover()
else:
game.showtext("""
|---------------------- !!! ----------------------|
| Sorry, something went wrong. |
| The game could not find {0} |
| The game will now end. |
| Do you wish to save the game first? |
|---------------------- !!! ----------------------|
""".format(placeReq))
if(game.yesno("Save game?")):
game.savegame()
break
#end game loop
#end game loop function
def titleMenu(game:Game.Game):
game.DisableMenu()
navdata = game.Navdata
navdata.AreaName = "TITLE MENU"
navdata.closed = True
titleroll = "WELCOME TO\n\n"
f = open("title.txt", 'r', encoding="utf-8")
titleroll += f.read()
f.close()
rollwtime = 0.05
menu = [
["NEWGAME", "{TITLE_STARTNEW}"],
["LOADGAME", "{TITLE_LOADASAVE}"],
["ABOUT", "{TITLE_RUNCREDITS}"],
["EXIT", "{TITLE_EXITGAME}"],
]
game.rolltext(titleroll, rollwtime)
while True:
game.choose(menu, "{TITLE_WELCOME}", False)
etype, data = game.wait()
if etype != "action":
continue
r = data[0] #button press from user
if r == "EXIT":
game.quit()
return
if r == "ABOUT":
game.runGeneral("credits")
continue
if r == "LOADGAME":
if game.loadgame(fromTitle = True):
game_loop(game)
return
if r == "NEWGAME":
game.newgame()
game_loop(game)
return
if __name__ == "__main__":
start()