Ejemplo n.º 1
0
	def doAction(self,action,player,game):
		if self.check_help(action):
			return self.help(action,player,game)
		# won the game if the score is over 280
		if player.score > 280:
			self.won = True
		# update current level
		# if the current level isen't the last level, we parse the input
		# and try to get the value from the key(the input) in the level dictionary
		# If its not present in the dictionary, we still assign the parsed user input to the curAction,
		# So we can print it to the user
		if self.curlevel != self.totalLevels:
			if self.gameover:
				self.currentDeath = self.gameover[self.curlevel]
			process = parser.process_input(action,self.levels[self.curlevel],player.items + self.objects)
			self.curAction = self.levels[self.curlevel].get(process, process)
			if process in self.levels[self.curlevel]:
				self.lastAction = self.curAction
				self.curlevel += 1
			return self.curAction
		else:
			# Parse the input and pass the parsed input to the obstacles action function
			process = parser.process_input(action,self.obstacle.commands,player.items + self.objects)
			temp = self.curAction = self.obstacle.action(process,player)
			#The obstacle disappears/dies if the hp is 0
			if self.obstacle.hp < 1:
				self.obstacle = None
			return temp
Ejemplo n.º 2
0
 def doAction(self, action, player, game):
     if self.check_help(action):
         return self.help(action, player, game)
     # won the game if the score is over 280
     if player.score > 280:
         self.won = True
     # update current level
     # if the current level isen't the last level, we parse the input
     # and try to get the value from the key(the input) in the level dictionary
     # If its not present in the dictionary, we still assign the parsed user input to the curAction,
     # So we can print it to the user
     if self.curlevel != self.totalLevels:
         if self.gameover:
             self.currentDeath = self.gameover[self.curlevel]
         process = parser.process_input(action, self.levels[self.curlevel],
                                        player.items + self.objects)
         self.curAction = self.levels[self.curlevel].get(process, process)
         if process in self.levels[self.curlevel]:
             self.lastAction = self.curAction
             self.curlevel += 1
         return self.curAction
     else:
         # Parse the input and pass the parsed input to the obstacles action function
         process = parser.process_input(action, self.obstacle.commands,
                                        player.items + self.objects)
         temp = self.curAction = self.obstacle.action(process, player)
         #The obstacle disappears/dies if the hp is 0
         if self.obstacle.hp < 1:
             self.obstacle = None
         return temp
Ejemplo n.º 3
0
	def check_key(self, dir,player,game):
		process = parser.process_input(dir,self.paths,player.items + self.objects)
		# If the processed input is no key to a room, the pathExist is set to None
		pathExist = self.paths.get(process, None)
		if not pathExist:
			#CurAction is set to the output/response stored in process variable
			self.curAction = process
			if self.check_help(dir):
				self.help(dir,player,game)
		return pathExist
Ejemplo n.º 4
0
 def check_key(self, dir, player, game):
     process = parser.process_input(dir, self.paths,
                                    player.items + self.objects)
     # If the processed input is no key to a room, the pathExist is set to None
     pathExist = self.paths.get(process, None)
     if not pathExist:
         #CurAction is set to the output/response stored in process variable
         self.curAction = process
         if self.check_help(dir):
             self.help(dir, player, game)
     return pathExist
Ejemplo n.º 5
0
	def go(self, direction,player):
		# Processing the input with the process_input from the parser module. 
		# This function will return a valid room key (that we can use to find the room in the dictionary)
		process = parser.process_input(direction,self.paths,player.items + self.objects)
		#Checks if the user typed hidden, if the player score is under 200(score he needs to visit the room), None is returned
		if process == "hidden":
			if player.score < 200:
				#prevents the player from getting points for progressing to the same room
				player.score -= 10
				return self
		# pops the element, so the user never can go the same path several times
		next_room = self.paths.pop(process, None)
		if player.score > 280:
			next_room.won = True
			next_room.curAction = "You WON!!!"
		return next_room
Ejemplo n.º 6
0
 def go(self, direction, player):
     # Processing the input with the process_input from the parser module.
     # This function will return a valid room key (that we can use to find the room in the dictionary)
     process = parser.process_input(direction, self.paths,
                                    player.items + self.objects)
     #Checks if the user typed hidden, if the player score is under 200(score he needs to visit the room), None is returned
     if process == "hidden":
         if player.score < 200:
             #prevents the player from getting points for progressing to the same room
             player.score -= 10
             return self
     # pops the element, so the user never can go the same path several times
     next_room = self.paths.pop(process, None)
     if player.score > 280:
         next_room.won = True
         next_room.curAction = "You WON!!!"
     return next_room