Naja game state.
"""
- def __init__(self, data=None):
+ def __init__(self, gameboard):
+ self.gameboard = gameboard
+
+ @classmethod
+ def new(cls, **kw):
locations_deck = load_location_deck('standard')
- if data is None:
- self.gameboard = GameBoard.new_game(locations_deck['cards'])
- else:
- self.gameboard = GameBoard.import_game(data)
+ return cls(GameBoard.new_game(locations_deck['cards'], **kw))
+
+ @classmethod
+ def load(cls, data):
+ return cls(GameBoard.import_game(data))
@property
def player(self):
from naja.scenes.credits import CreditsScene
from naja.scenes.game import GameScene
from naja.scenes.load_save import LoadGameScene, SaveGameScene
+from naja.scenes.new_game import NewGameScene
from naja.widgets.selector import SelectorWidget
from naja.widgets.text import TextWidget
selector = SelectorWidget()
self.add(selector)
- run_game = TextWidget((100, 100), 'Game', fontsize=32, colour='white')
+ run_game = TextWidget((100, 50), 'Game', fontsize=32, colour='white')
run_game.add_callback(
'click', lambda event: SceneChangeEvent.post(GameScene))
selector.add(run_game)
+ new_game = TextWidget((100, 100), 'New', fontsize=32, colour='white')
+ new_game.add_callback(
+ 'click', lambda event: SceneChangeEvent.post(NewGameScene))
+ selector.add(new_game)
+
credits = TextWidget(
(100, 150), 'Credits', fontsize=32, colour='white')
credits.add_callback(
--- /dev/null
+"""
+Load and save scenes.
+"""
+
+import pygame.locals as pgl
+
+from naja.constants import KEYS
+from naja.events import SceneChangeEvent, LoadGameEvent
+from naja.gamestate import GameState
+from naja.scenes.scene import Scene
+from naja.widgets.selector import SelectorWidget
+from naja.widgets.text import TextWidget
+
+
+class NewGameScene(Scene):
+ def __init__(self, state):
+ super(NewGameScene, self).__init__(state)
+ selector = SelectorWidget()
+ self.add(selector)
+
+ easy = TextWidget((100, 100), 'Easy', fontsize=32, colour='white')
+ easy.add_callback('click', self.easy_game)
+ selector.add(easy)
+
+ standard = TextWidget(
+ (100, 150), 'Standard', fontsize=32, colour='white')
+ standard.add_callback('click', self.standard_game)
+ selector.add(standard)
+
+ hard = TextWidget((100, 200), 'Hard', fontsize=32, colour='white')
+ hard.add_callback('click', self.hard_game)
+ selector.add(hard)
+
+ def easy_game(self, event):
+ self.start_game(GameState.new(max_health=5, wins_required=3))
+
+ def standard_game(self, event):
+ self.start_game(GameState.new(max_health=4, wins_required=4))
+
+ def hard_game(self, event):
+ self.start_game(GameState.new(max_health=3, wins_required=5))
+
+ def start_game(self, state):
+ from naja.scenes.game import GameScene
+ LoadGameEvent.post(state=state)
+ SceneChangeEvent.post(GameScene)
+
+ def handle_scene_event(self, ev):
+ if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT:
+ from naja.scenes.menu import MenuScene
+ SceneChangeEvent.post(MenuScene)
+ return