from naja.scenes.howto import HowtoScene
from naja.scenes.load_save import LoadGameScene, SaveGameScene
from naja.scenes.new_game import NewGameScene
+from naja.scenes.puzzlelist import PuzzleListScene
from naja.widgets.selector import SelectorWidget
from naja.widgets.text import TextWidget
from naja.widgets.image_box import ImageBox
selector = SelectorWidget()
self.add(selector)
- y_offset, y_diff = 270, 40
+ y_offset, y_diff = 270, 36
x_offset = 400
y_offset += y_diff
y_offset += y_diff
new = TextWidget(
- (x_offset, y_offset), 'New Game', colour=PALETTE.WHITE,
+ (x_offset, y_offset), 'New Random Game', colour=PALETTE.WHITE,
centre=True)
new.add_callback('click', self.scene_callback(NewGameScene))
selector.add(new)
+ y_offset += y_diff
+ new = TextWidget(
+ (x_offset, y_offset), 'New Puzzle', colour=PALETTE.WHITE,
+ centre=True)
+ new.add_callback('click', self.scene_callback(PuzzleListScene))
+ selector.add(new)
+
y_offset += y_diff
load = TextWidget((x_offset, y_offset), 'Load', colour=PALETTE.WHITE,
centre=True)
hard.add_callback('click', self.hard_game)
selector.add(hard)
- y_offset += y_diff
- puzzle = TextWidget(
- (x_offset, y_offset), 'Puzzle', fontsize=32, colour='white',
- centre=True)
- puzzle.add_callback('click', self.puzzle_game)
- selector.add(puzzle)
-
def easy_game(self, event):
self.start_game(GameState.new(max_health=5, wins_required=3))
def hard_game(self, event):
self.start_game(GameState.new(max_health=3, wins_required=5))
- def puzzle_game(self, event):
- self.start_game(GameState.new(
- deck='puzzles/test', max_health=4, wins_required=4))
-
def start_game(self, state):
from naja.scenes.game import GameScene
LoadGameEvent.post(state=state)
--- /dev/null
+"""
+Load and save scenes.
+"""
+
+import functools
+import pygame.locals as pgl
+
+from naja.constants import KEYS, PUZZLES
+from naja.events import SceneChangeEvent, LoadGameEvent
+from naja.gamestate import GameState, load_location_deck
+from naja.scenes.scene import Scene
+from naja.widgets.image_box import ImageBox
+from naja.widgets.selector import SelectorWidget
+from naja.widgets.text import TextWidget
+
+
+class PuzzleListScene(Scene):
+ def __init__(self, state):
+ super(PuzzleListScene, self).__init__(state)
+
+ background = ImageBox(
+ (0, 0), "screens/splash.png")
+ self.add(background)
+
+ selector = SelectorWidget()
+ selector.position = 1
+ self.add(selector)
+
+ y_offset, y_diff = 270, 36
+ x_offset = 400
+
+ y_offset += y_diff
+ title = TextWidget(
+ (x_offset, y_offset), 'CHOOSE PUZZLE', colour='white',
+ centre=True)
+ self.add(title)
+
+ for puzzle in PUZZLES:
+ y_offset += y_diff
+ deck = load_location_deck('puzzles/%s' % puzzle)
+ puzzle_but = TextWidget(
+ (x_offset, y_offset), deck['description'], fontsize=32,
+ colour='white', centre=True)
+ callback = functools.partial(self.start_puzzle_game,
+ puzzle=puzzle, deck=deck)
+ puzzle_but.add_callback('click', callback)
+ selector.add(puzzle_but)
+
+ def start_puzzle_game(self, event, puzzle=None, deck=None):
+ from naja.scenes.game import GameScene
+ max_health = deck.get('max_health', 4)
+ wins_required = deck.get('wins_required', 4)
+ level = 'puzzles/%s' % puzzle
+ state = GameState.new(deck=level, max_health=max_health,
+ wins_required=wins_required)
+ 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