Exemple #1
0
class MainMenu(Scene):
    def __init__(self):
        """
        @summary: Initializes a main menu
        """
        Scene.__init__(self)
        self.helpMenu = HelpMenu(self)

        self.menu = Menu()
        self.menu.addWidget(Button("Start", self.runGame))
        self.menu.addWidget(Button("Settings", self.runSettingsMenu))
        self.menu.addWidget(Button("Help", self.runHelpMenu))
        self.menu.addWidget(Button("Quit", self.quitGame))

    def draw(self, surface):
        """
        @param surface: The surface which the main menu should be drawed on
        @summary: draws the main menu on a specified surface
        """
        self.menu.draw(surface)

    def update(self, input):
        """
        @param input: The user input
        @summary: updates the status of the main menu based on the user input
        """
        self.menu.update(input)

    def runGame(self):
        """
        @summary: runs a new game
        """
        game = Game()
        game.mainmenu = self
        SceneManager().setScene(game)

    def runSettingsMenu(self):
        """
        @summary: shows the settings menu
        """
        SceneManager().setScene(SettingsMenu(self))

    def runHelpMenu(self):
        """
        @summary: shows the help screen
        """
        SceneManager().setScene(self.helpMenu)

    def quitGame(self):
        """
        @summary: quits the game
        """
        SceneManager().setScene(None) #No scene, means quit game!
Exemple #2
0
 def update(self, input):
     """
     @param input: The user input
     @summary: updates the inventory status based on the user input
     """
     Menu.update(self, input)
     if(not None == self.selectedItemIndex):
         self.visible = False
         returnWeapon = self.weapons[self.selectedItemIndex]
         self.selectedItemIndex = None
         return returnWeapon
     else:
         return None
class SettingsMenu(Scene):
    def __init__(self, parentScene):
        """
        Initialize the Settingsmenu
        @param parentScene: The scene he should go back to when the settings are adjusted
        """
    
        Scene.__init__(self)
        self.parentScene = parentScene
        self.frame = Menu()
        self.sliderPlayers = Slider(2, 4, Settings.GAME_PLAYERS, "Players: ")
        self.sliderSnails = Slider(2, 10, Settings.GAME_SNAILS, "Snails: ")
        self.sliderSnailsHp = Slider(1, 150, Settings.GAME_SNAILS_HP, "Hitpoints: ", 10)
        self.sliderStartTime = Slider(10, 90, Settings.TIMER_STARTTIME, "Turntime: ", 10)
        self.sliderBreakTime = Slider(1,10, Settings.TIMER_BREAKTIME, "Breaktime: ")

        self.frame.addWidget(self.sliderPlayers)
        self.frame.addWidget(self.sliderSnails)
        self.frame.addWidget(self.sliderSnailsHp)
        self.frame.addWidget(self.sliderStartTime)
        self.frame.addWidget(self.sliderBreakTime)
        self.frame.addWidget(Button("Ok",self.applySettings))

    def update(self, input):
        """
        Update the settingsmenu
        @param input: The input class
        """
        self.frame.update(input)

    def draw(self, surface):
        """
        Draw the settingsmenu on a surface
        @param surface: The surface the settingsmenu should be drawed on
        """
        self.frame.draw(surface)

    def applySettings(self):
        """
        Adjust the game settings
        """
        Settings.GAME_PLAYERS = self.sliderPlayers.value
        Settings.GAME_SNAILS = self.sliderSnails.value
        Settings.GAME_SNAILS_HP = self.sliderSnailsHp.value
        Settings.TIMER_STARTTIME = self.sliderStartTime.value
        Settings.TIMER_BREAKTIME = self.sliderBreakTime.value
        SceneManager().setScene(self.parentScene)