-
Notifications
You must be signed in to change notification settings - Fork 0
/
BackupMain.txt
225 lines (209 loc) · 7.93 KB
/
BackupMain.txt
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
__author__ = 'Slayton'
# Classes
class entity(object):
def idSetter(self):
self.ID = "";
def nameSetter(self):
self.name = "";
class archive(object):
def currentRoomSetter(self):
self.currentRoom = "room0";
def eventsDict(self):
self.events = {};
def nodesDict(self):
self.nodes = {};
def scenesDict(self):
self.scenes = {};
def roomsDict(self):
self.rooms = {};
# room - room inherits from entity giving it a name and an id. Rooms are what the player interacts
# with directly. They contain scenes which the player sees. For example, room1 may be called "The Grato"
# in the first scene of "The Grato" the player encounters a gang of pirates, in the second scene of
# The Grato the player may have dealt with the pirates and now the Grato is empty.
class room(entity):
def sceneSetter(self):
self.roomScenes = [];
def currentSceneSetter(self):
self.currentScene = 0;
# scene - scene inherits from entity giving it a name and an id. It contains a list of nodes which the player
# can interact with, as well as a description of the room it takes place in.
class scene(entity):
def textSetter(self):
self.text = "";
def nodeSetter(self):
self.sceneNodes = [];
def examSetter(self):
self.examine = "";
class node(entity):
def eventsSetter(self):
self.nodeEvents = [];
def activateNode(self, arch):
for i in range(len(self.nodeEvents)):
self.nodeEvents[i].activate(arch);
class event(entity):
def activeSetter(self):
self.active = "";
def activate(self, arch):
# Test in Code
parsedEffect = self.active.split();
# swap roomID sceneID
if parsedEffect[0] == "swap":
roomRef = arch.rooms[parsedEffect[1]];
roomRef.currentScene = int(parsedEffect[2]);
if parsedEffect[0] == "goto":
arch.currentRoom = parsedEffect[1];
if parsedEffect[0] == "print":
print(parsedEffect[1]);
if parsedEffect[0] == "node":
# node roomID sceneID nodeNumber eventNum NewEventID
roomRef = arch.rooms[parsedEffect[1]];
activeNode = roomRef.roomScenes[int(parsedEffect[2])].sceneNodes[int(parsedEffect[3])];
activeNode.name = self.name;
activeNode.nodeEvents[int(parsedEffect[4])] = arch.events[parsedEffect[5]];
# Methods
def main():
console = "";
arch = archive();
arch.currentRoomSetter();
arch.events = eventScrivner();
arch.nodes = nodeScrivner(arch);
arch.scenes = sceneScrivner(arch);
arch.rooms = roomScrivner(arch);
while console != "q":
load(arch,arch.currentRoom);
console = input("\nWhat do you do?\n");
try:
choiceNum = int(console);
# playerChoice translates choice num into the
# index of the option the player selected.
playerChoice = int(choiceNum) - 1;
theScene = arch.rooms[arch.currentRoom].roomScenes[arch.rooms[arch.currentRoom].currentScene]
if playerChoice == len(theScene.sceneNodes):
print(theScene.examine);
console = input("\tcontinue...");
else:
theScene.sceneNodes[playerChoice].activateNode(arch);
except ValueError:
if console != "q":
print("Sorry, please enter a number or 'q' to quit.");
except IndexError:
print("The range was off. There is/are only "+str(len(theScene.sceneNodes))+" choices in this scene, not including an examine option.");
def load(loadArch, loadArchRoom):
thisRoom = loadArch.rooms[loadArchRoom];
thisScene = thisRoom.roomScenes[thisRoom.currentScene];
print(thisScene.name);
print(thisScene.text);
num = 1;
for i in range(0,len(thisScene.sceneNodes)):
print("\t"+str(i+1)+": "+thisScene.sceneNodes[i].name);
num += 1;
if thisScene.examine != "":
print("\t"+str(num)+": Examine.");
# eventScrivner - returns a dictionary of events, events read from a file called events.txt
def eventScrivner():
inFile = open("events.txt","r");
line = inFile.readline().rstrip();
events = {};
while line != "ENDEVENTS":
line = inFile.readline().rstrip();
tempEvent = event();
tempEvent.idSetter();
tempEvent.nameSetter();
tempEvent.activeSetter();
while line != "endevent" and line != "ENDEVENTS":
# print(line);
if line[0:5] == "id :":
tempEvent.ID = line[6:];
if line[0:5] == "name:":
tempEvent.name = line[6:];
if line[0:5] == "acti:":
tempEvent.active = line[6:];
line = inFile.readline().rstrip();
events[tempEvent.ID] = tempEvent;
inFile.close();
return events;
# nodeScrivner - returns a dictionary of nodes.
def nodeScrivner(archNodes):
inFile = open("nodes.txt","r");
line = inFile.readline().rstrip();
nodes = {};
while line != "ENDNODES":
# print(line);
line = inFile.readline().rstrip();
tempNode = node();
tempNode.idSetter();
tempNode.nameSetter();
tempNode.eventsSetter();
while line != "endnode" and line != "ENDNODES":
if line[0:5] == "id :":
tempNode.ID = line[6:];
if line[0:5] == "name:":
tempNode.name = line[6:];
if line[0:5] == "even:":
line = inFile.readline().rstrip();
while line != "endeven":
#print(line);
tempNode.nodeEvents.append(archNodes.events[line]);
line = inFile.readline().rstrip();
line = inFile.readline().rstrip();
nodes[tempNode.ID] = tempNode;
inFile.close();
return nodes;
def sceneScrivner(archScenes):
inFile = open("scenes.txt","r");
line = inFile.readline().rstrip();
scenes = {};
while line != "ENDSCENES":
line = inFile.readline().rstrip();
tempScene = scene();
tempScene.idSetter();
tempScene.nameSetter();
tempScene.textSetter();
tempScene.nodeSetter();
tempScene.examSetter();
while line != "endscene" and line != "ENDSCENES":
if line[0:5] == "id :":
tempScene.ID = line[6:];
if line[0:5] == "name:":
tempScene.name = line[6:];
if line[0:5] == "text:":
tempScene.text = line[6:];
if line[0:5] == "exam:":
tempScene.examine = line[6:];
if line[0:5] == "node:":
line = inFile.readline().rstrip();
while line != "endnodes":
# print(line);
tempScene.sceneNodes.append(archScenes.nodes[line]);
line = inFile.readline().rstrip();
line = inFile.readline().rstrip();
scenes[tempScene.ID] = tempScene;
inFile.close();
return scenes;
def roomScrivner(archRooms):
inFile = open("rooms.txt","r");
line = inFile.readline().rstrip();
rooms = {};
while line != "ENDROOMS":
line = inFile.readline().rstrip();
tempRoom = room();
tempRoom.idSetter();
tempRoom.nameSetter();
tempRoom.sceneSetter();
tempRoom.currentSceneSetter();
while line != "endroom" and line != "ENDROOMS":
if line[0:5] == "id :":
tempRoom.ID = line[6:];
if line[0:5] == "name:":
tempRoom.name = line[6:];
if line[0:5] == "scen:":
line = inFile.readline().rstrip();
while line != "endscenes":
# print(line);
tempRoom.roomScenes.append(archRooms.scenes[line]);
line = inFile.readline().rstrip();
line = inFile.readline().rstrip();
rooms[tempRoom.ID] = tempRoom;
inFile.close();
return rooms;
main();