forked from jladdjr/lord-of-the-rings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
executable file
·45 lines (38 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python
from parser import Parser
import game_loader
class Game(object):
"""
Prepares and executes turn-based game.
"""
def __init__(self):
"""
Initializes new game.
"""
#Initializes game objects
self._world = game_loader.getWorld()
startingInventory = game_loader.getStartingInventory()
self._player = game_loader.getPlayer(self._world, startingInventory)
self._commandList = game_loader.getCommandList(self._player)
#Creates parser
self._parser = Parser(self._commandList)
def play(self):
"""
Executes main game loop.
"""
print "Welcome to Lord of the Rings Adventure Game!"
print "(Type 'help' for a list of available commands)"
print ""
while(True):
self._nextTurn()
def _nextTurn(self):
"""
Executes next turn.
"""
nextCommand = self._parser.getNextCommand()
if nextCommand is not None:
nextCommand.execute()
print ""
else:
errorMsg = "Failed to receive command from parser."
raise AssertionError(errorMsg)