+ @classmethod
+ def import_locations(cls, locations_definition):
+ return [
+ LocationCard.import_location(definition)
+ for definition in locations_definition]
+
+ def export_board_locations(self):
+ return dict(
+ (position, location.export())
+ for position, location in self.board_locations.iteritems())
+
+ @classmethod
+ def import_board_locations(cls, board_locations_definition):
+ return dict(
+ (position, LocationCard.import_location(definition))
+ for position, definition in board_locations_definition.iteritems())
+
+ @classmethod
+ def generate_board(cls, locations_definition):
+ board_locations = {}
+ for x in range(5):
+ for y in range(5):
+ board_location = LocationCard.new_location(
+ choice(locations_definition).copy())
+ board_locations[(x, y)] = board_location.export()
+ return board_locations
+
+ def lose_health(self):
+ self.health -= 1
+ if self.health <= 0:
+ self.end_game(win=False)
+
+ def gain_health(self):
+ if self.health < self.max_health:
+ self.health += 1
+
+ def acquire_win_token(self):
+ self.wins += 1
+ if self.wins >= self.wins_required:
+ self.end_game(win=True)
+
+ def replace_card(self, position):
+ location = LocationCard.new_location(choice(self.locations).copy())
+ self.board_locations[position] = location
+
+ def change_mode(self, new_mode):
+ """Advance to the next mode"""
+ if new_mode == self.player_mode:
+ raise RuntimeError("Inconsistent state. Setting mode %s to itself"
+ % self.player_mode)
+ elif new_mode in (MOVE, ACT, EXAMINE):
+ self.player_mode = new_mode
+ else:
+ raise RuntimeError("Illegal player mode %s" % self.player_mode)
+
+ def end_game(self, win):
+ # TODO: Find a way to not have UI stuff in game logic stuff.
+ from naja.events import SceneChangeEvent
+ from naja.scenes.lose import LoseScene
+ from naja.scenes.win import WinScene
+ if win:
+ SceneChangeEvent.post(WinScene)
+ else:
+ SceneChangeEvent.post(LoseScene)
+