self.health = state['health']
self.wins = state['wins']
self.locations = [item.copy() for item in state['locations']]
+ self.puzzle = state['puzzle']
self.player = player
self.board_locations = board_locations
self.player_mode = EXAMINE
@classmethod
- def new_game(cls, locations_definition,
+ def new_game(cls, deck,
initial_bits=PLAYER_DEFAULTS.INITIAL_BITS,
initial_pos=PLAYER_DEFAULTS.INITIAL_POS,
max_health=PLAYER_DEFAULTS.MAX_HEALTH,
'health': max_health,
'wins_required': wins_required,
'wins': 0,
- 'locations': locations_definition,
+ 'locations': deck['cards'],
+ 'puzzle': deck.get('puzzle', False),
}
player = Player(initial_bits, initial_pos)
board_locations = cls.import_board_locations(
- cls.generate_board(locations_definition))
+ cls.generate_board(deck))
return cls(state, player, board_locations)
@classmethod
'wins_required': self.wins_required,
'wins': self.wins,
'locations': [item.copy() for item in self.locations],
+ 'puzzle': self.puzzle,
'player': self.player.export(),
'board_locations': self.export_board_locations(),
}
for position, definition in board_locations_definition)
@classmethod
- def generate_board(cls, locations_definition):
+ def generate_board(cls, deck):
+ if deck.get('puzzle', False):
+ return cls.generate_puzzle_board(deck)
+ else:
+ return cls.generate_random_board(deck)
+
+ @classmethod
+ def generate_puzzle_board(cls, deck):
+ assert len(deck['cards']) == 5 * 5
+ board_locations = [
+ [(i % 5, i // 5),
+ LocationCard.new_location(card.copy()).export()]
+ for i, card in enumerate(deck['cards'])
+ ]
+ return board_locations
+
+ @classmethod
+ def generate_random_board(cls, deck):
board_locations = []
for x in range(5):
for y in range(5):
board_location = LocationCard.new_location(
- choice(locations_definition).copy())
+ choice(deck['cards']).copy())
board_locations.append([(x, y), board_location.export()])
return board_locations