59efdb917c37b63a19db3f205279e274c52eac0f
[naja.git] / naja / scenes / win.py
1 """
2 Win scene.
3 """
4
5 import pygame.locals as pgl
6
7 from naja.constants import KEYS, PALETTE
8 from naja.events import SceneChangeEvent, LoadGameEvent
9 from naja.sound import sound
10 from naja.scenes.scene import Scene
11 from naja.widgets.image_box import ImageBox
12 from naja.widgets.text import TextWidget, TextBoxWidget
13
14
15 class WinScene(Scene):
16     """
17     Congratulations.
18     """
19
20     def __init__(self, state):
21         super(WinScene, self).__init__(state)
22
23         background = ImageBox(
24             (0, 0), "screens/you_won.png")
25         self.add(background)
26
27         if self.state.gameboard.has_cheated:
28             self.add(TextWidget(
29                 (50, 250), 'But you\'re a CHEATER!', colour=PALETTE.ORANGE))
30         self.add(TextBoxWidget(
31             (50, 300), '\n\n'.join([
32                 "You're great.",
33                 "You did well.",
34                 "You should be proud of yourself.",
35                 "",
36                 "Press ESC to return to the menu",
37             ]),
38             colour=PALETTE.WHITE, padding=1, border=1,
39             bg_colour=PALETTE.BLACK, border_colour=PALETTE.BLACK,
40             box_width=300))
41         sound.play_music('A_ninja.ogg')
42
43     def handle_scene_event(self, ev):
44         from naja.scenes.menu import MenuScene
45         if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT:
46             sound.stop()
47             # drop current state
48             LoadGameEvent.post(None)
49             SceneChangeEvent.post(MenuScene)
50             return