[go: up one dir, main page]

Menu

[899825]: / Game.py  Maximize  Restore  History

Download this file

38 lines (29 with data), 1.1 kB

 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
import logging
from Context import *
from CommandFactory import *
class Game:
logger = logging.getLogger("taco")
currentRoom = None
factory = None
def __init__(self, userDetails, startRoom, rooms):
self.context = Context(userDetails, startRoom, rooms)
self.rooms = rooms
self.factory = CommandFactory()
self.__displayOpeningText()
self.__displayStartingRoomInfo()
self.__run()
def __displayOpeningText(self):
print "\n"
print "Welcome to Foo adventure, ",self.context.getUserDetails().getName()
print "\n"
def __displayStartingRoomInfo(self):
self.context.getCurrentRoom().printInfo()
self.context.getCurrentRoom().getDirections().printInfo()
def __run(self):
self.logger.debug("Running, querying for user input")
playerInput = raw_input("\n? ")
self.logger.debug("Mapping user input to a command")
cmd = self.factory.create(self.context, playerInput)
self.logger.debug("Executing command: " + str(cmd))
cmd.execute(self.context, playerInput)
self.__run()