-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.py
31 lines (24 loc) · 1.18 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
import Misc
class Game(object):
def __init__(self, rooms, player, global_commands = {}):
self.rooms = rooms
self.global_commands = global_commands
self.player = player
def gameLoop(self):
self.lastCommand = ""
while True:
self.player.loc.printDetails()
self.lastCommand = input()
if self.lastCommand == "!exit!":
print("Game Ended")
break
if self.lastCommand in self.player.loc.commands.keys():
exec(self.player.loc.commands[self.lastCommand])
elif self.lastCommand in self.player.loc.connections.keys():
exec("self.player.goto(self.rooms[\'" + str(self.player.loc.connections[self.lastCommand]) + "\'])")
elif self.lastCommand in self.global_commands.keys():
exec(self.global_commands[self.lastCommand])
elif self.lastCommand.split(' ', 1)[0] in self.global_commands.keys():
exec(self.global_commands[self.lastCommand.split(' ', 1)[0]].replace("!x!", self.lastCommand.split(' ', 1)[1]))
else:
print("Sorry, I don't understand what you mean")