コード例 #1
0
 def move_down(self, labyrinth: Labyrinth):
     """Make the player move odwn if there are no wall or monolith. If the player has the treasure and moves out
             it triggers the win action"""
     underneath__cell = labyrinth.get_labyrinth()[(self.__pos_y * 2 + 1) +
                                                  1][self.__pos_x * 2 +
                                                     1].get_cell_type()
     if underneath__cell == CellType.WALL or underneath__cell == CellType.MONOLITH:
         return "step impossible", underneath__cell.value, False
     elif underneath__cell == CellType.NO_WALL and self.__pos_y == labyrinth.get_size(
     ) - 1 and self.player_has_treasure():
         return "step executed", "out of labyrinth", True
     elif underneath__cell == CellType.NO_WALL and self.__pos_y == labyrinth.get_size(
     ) - 1 and not self.player_has_treasure():
         return "step impossible", "no treasure in inventory", False
     else:
         self.__pos_y += 1
         return "step executed", self.get_current_cell(
             labyrinth).get_cell_type().value, False
コード例 #2
0
 def move_left(self, labyrinth: Labyrinth):
     """Make the player move left if there are no wall or monolith. If the player has the treasure and moves out
             it triggers the win action"""
     left_cell = labyrinth.get_labyrinth()[(self.__pos_y * 2 +
                                            1)][(self.__pos_x * 2 + 1) -
                                                1].get_cell_type()
     if left_cell == CellType.WALL or left_cell == CellType.MONOLITH:
         return "step impossible", left_cell.value, False
     elif left_cell == CellType.NO_WALL and self.__pos_x == 0 and self.player_has_treasure(
     ):
         return "step executed", "out of labyrinth", True
     elif left_cell == CellType.NO_WALL and self.__pos_x == 0 and not self.player_has_treasure(
     ):
         return "step impossible", "no treasure in inventory", False
     else:
         self.__pos_x -= 1
         return "step executed", self.get_current_cell(
             labyrinth).get_cell_type().value, False
コード例 #3
0
 def get_current_cell(self, labyrinth: Labyrinth):
     """Return the cell on which the player is"""
     return labyrinth.get_labyrinth()[(self.__pos_y * 2 +
                                       1)][self.__pos_x * 2 + 1]