annotate gamelib/mainmenu.py @ 70:442a1bf9b14e

fucking pep8
author Rizmari Versfeld <rizziepit@gmail.com>
date Tue, 08 May 2012 23:10:10 +0200
parents 364ff3479ef2
children 22b65c943712
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
53
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
2 # vim:fileencoding=utf-8 ai ts=4 sts=4 et sw=4
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
3
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
4 """The main menu"""
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
5
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
6 import pygame
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
7
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
8 from gamelib.gui_base import Window
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
9 from gamelib.gui import BigButton
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
10 from gamelib.engine import AddWindow
63
364ff3479ef2 Remove duplicate point tracking. Rename classes for future refactoring
Neil Muller <drnlmuller@gmail.com>
parents: 53
diff changeset
11 from gamelib.gamegui import LabWindow
53
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
12
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
13 from gamelib.constants import WIDTH, HEIGHT
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
14
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
15
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
16 class NewGameButton(BigButton):
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
17
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
18 def __init__(self, parent):
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
19 super(NewGameButton, self).__init__(((WIDTH - 128) / 2, HEIGHT / 2),
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
20 'Start New Game')
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
21 self.parent = parent
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
22
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
23 def on_click(self):
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
24 self.parent.start_new_game()
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
25
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
26
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
27 class ResumeGameButton(BigButton):
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
28
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
29 def __init__(self, parent):
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
30 super(ResumeGameButton, self).__init__(((WIDTH - 128) / 2,
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
31 HEIGHT / 2 + 50), 'Resume Game')
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
32 self.parent = parent
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
33
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
34 def on_click(self):
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
35 self.parent.resume_game()
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
36
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
37
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
38 class QuitButton(BigButton):
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
39
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
40 def __init__(self):
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
41 super(QuitButton, self).__init__(((WIDTH - 128) / 2,
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
42 HEIGHT / 2 + 100), 'Quit')
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
43
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
44 def on_click(self):
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
45 pygame.event.post(pygame.event.Event(pygame.QUIT))
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
46
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
47
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
48 class MainMenu(Window):
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
49
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
50 def __init__(self, screen):
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
51 super(MainMenu, self).__init__(screen)
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
52 self.game_window = None
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
53 self.resume = None
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
54 self.screen = screen
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
55 self.background_colour = (0, 0, 0)
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
56 button1 = NewGameButton(self)
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
57 self.add_child(button1)
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
58 button2 = QuitButton()
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
59 self.add_child(button2)
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
60
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
61 def start_new_game(self):
63
364ff3479ef2 Remove duplicate point tracking. Rename classes for future refactoring
Neil Muller <drnlmuller@gmail.com>
parents: 53
diff changeset
62 self.game_window = LabWindow(self.screen)
53
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
63 if not self.resume:
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
64 # Add the resume button
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
65 self.resume = ResumeGameButton(self)
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
66 self.add_child(self.resume)
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
67 AddWindow.post(self.game_window)
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
68
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
69 def resume_game(self):
655a6912e0ae Split gui stuff out of main.py
Neil Muller <drnlmuller@gmail.com>
parents:
diff changeset
70 AddWindow.post(self.game_window)