Grid iron.
[naja.git] / naja / gamestate.py
1 """
2 The current game state.
3 """
4
5 from naja.gameboard import GameBoard
6 from naja.resources import resources, ResourceNotFound
7
8
9 def load_location_deck(name):
10     try:
11         return resources.get_yaml('location_decks', '%s.yaml' % name)
12     except ResourceNotFound:
13         return resources.get_json('location_decks', '%s.json' % name)
14
15
16 class GameState(object):
17     """
18     Naja game state.
19     """
20
21     def __init__(self, gameboard):
22         self.gameboard = gameboard
23
24     @classmethod
25     def new(cls, deck='standard', **kw):
26         deck = load_location_deck(deck)
27         return cls(GameBoard.new_game(deck, **kw))
28
29     @classmethod
30     def load(cls, data):
31         return cls(GameBoard.import_game(data))
32
33     @property
34     def player(self):
35         return self.gameboard.player
36
37     @property
38     def board_locations(self):
39         return self.gameboard.board_locations