Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Behavior():
- def receiveCommand(self,command):
- playerCoordinates = self.game.getPlayerCoordinates()
- x = playerCoordinates[0]
- y = playerCoordinates[1]
- availableBehaviors = self.behaviors[x][y]
- if command in list(availableBehaviors.keys()):
- actionFunc = availableBehaviors[command]
- actionFunc()
- else:
- if command in ['north','east','west','south']:
- # the direction wasn't an applied behavior
- self.game.invalidDirection()
- else:
- # the command didn't match any behavior
- print('Unknown command, type "help" for list of commands')
- def north(self):
- return {'north':self.game.moveNorth}
- def east(self):
- return {'east':self.game.moveEast}
- def west(self):
- return {'west':self.game.moveWest}
- def south(self):
- return {'south':self.game.moveSouth}
- def help(self):
- return {"help":self.game.help}
- def keyNotFound(self):
- return {"get key":self.game.keyNotFound}
- def keyFound(self):
- return {"get key":self.game.keyFound}
- def createStandardBehavior(self):
- # create a standard set of
- standardBehavior = {}
- standardBehavior.update(self.help())
- standardBehavior.update(self.keyNotFound())
- return standardBehavior
- def applyBehaviors(x,y,behaviorsToApply):
- for behavior in behaviorsToApply:
- self.behaviors[x][y].apply(behavior)
- def createBehaviors(self):
- # this applies full movement to the first 5 square of the top row
- applyBehaviors(0,0,[north,east,west,south])
- applyBehaviors(0,1,[north,east,west,south])
- applyBehaviors(0,2,[north,east,west,south])
- applyBehaviors(0,3,[north,east,west,south])
- applyBehaviors(0,4,[north,east,west,south])
- # this applies full movement to the first 5 square of the 15th row
- applyBehaviors(14,0,[north,east,west,south])
- applyBehaviors(14,1,[north,east,west,south])
- applyBehaviors(14,2,[north,east,west,south])
- applyBehaviors(14,3,[north,east,west,south])
- applyBehaviors(14,4,[north,east,west,south])
- def __init__(self,game):
- self.game = game
- self.createBehaviors()
- # create a dictionary of behaviors for each game square (16 by 16)
- gridSize = self.game.getGridSize()
- row = [self.createStandardBehavior() for i in range(gridSize['x'])]
- self.behaviors = [row for i in range(gridSize['y'])]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement