6 import pygame.locals as pgl
8 from naja.constants import KEYS, PUZZLES
9 from naja.events import SceneChangeEvent, LoadGameEvent
10 from naja.gamestate import GameState, load_location_deck
11 from naja.scenes.scene import Scene
12 from naja.widgets.image_box import ImageBox
13 from naja.widgets.selector import SelectorWidget
14 from naja.widgets.text import TextWidget
17 class PuzzleListScene(Scene):
18 def __init__(self, state):
19 super(PuzzleListScene, self).__init__(state)
21 background = ImageBox(
22 (0, 0), "screens/splash.png")
25 selector = SelectorWidget()
29 y_offset, y_diff = 270, 36
34 (x_offset, y_offset), 'CHOOSE PUZZLE', colour='white',
38 for puzzle in PUZZLES:
40 deck = load_location_deck('puzzles/%s' % puzzle)
41 puzzle_but = TextWidget(
42 (x_offset, y_offset), deck['description'], fontsize=32,
43 colour='white', centre=True)
44 callback = functools.partial(self.start_puzzle_game,
45 puzzle=puzzle, deck=deck)
46 puzzle_but.add_callback('click', callback)
47 selector.add(puzzle_but)
49 def start_puzzle_game(self, event, puzzle=None, deck=None):
50 from naja.scenes.game import GameScene
51 max_health = deck.get('max_health', 4)
52 wins_required = deck.get('wins_required', 4)
53 level = 'puzzles/%s' % puzzle
54 state = GameState.new(deck=level, max_health=max_health,
55 wins_required=wins_required)
56 LoadGameEvent.post(state=state)
57 SceneChangeEvent.post(GameScene)
59 def handle_scene_event(self, ev):
60 if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT:
61 from naja.scenes.menu import MenuScene
62 SceneChangeEvent.post(MenuScene)