コード例 #1
0
ファイル: test_menu.py プロジェクト: MichalBroucek/galaxyrun
 def test_game_over_menu_buttons(self):
     """
     Test Game over menu items
     """
     main_menu = menu.Menu()
     game_over_l, play_again_b, main_menu_b = main_menu.get_game_over_menu_items(
     )
     self.assertTrue(
         isinstance(game_over_l, Label),
         msg='\'Game Over Label\' doesn\'t exist in Game over window !')
     self.assertTrue(
         isinstance(play_again_b, Button),
         msg='\'Play Again Button\' doesn\'t exist in Game over window !')
     self.assertTrue(
         isinstance(main_menu_b, Button),
         msg='\'Main menu Button\' doesn\'t exist in Game over window !')
コード例 #2
0
ファイル: test_menu.py プロジェクト: MichalBroucek/galaxyrun
 def test_run_game_menu_buttons(self):
     """
     Test Run Game menu items
     """
     main_menu = menu.Menu()
     game_background, my_rocket, my_slider, my_meteorites = main_menu.get_level_1_run_items(
         100, 30)
     self.assertTrue(
         isinstance(game_background, Background),
         msg='\'Game Background\' isn\'t instance of Background !')
     self.assertTrue(
         isinstance(my_rocket, rocket.Rocket),
         msg='\'Game Rocket\' doesn\'t exist in game run window !')
     self.assertTrue(isinstance(my_slider, Sprite),
                     msg='\'Slider\' doesn\'t exist in game run window !')
     self.assertTrue(isinstance(my_meteorites, meteorites.Meteorites),
                     msg='\'Meteorites\' don\'t exist in game run window !')
コード例 #3
0
ファイル: test_menu.py プロジェクト: MichalBroucek/galaxyrun
 def test_main_menu_new_game_buttons(self):
     """
     Test Main menu - New Game Button
     """
     main_menu = menu.Menu()
     menu_background, galaxy_run_l, play_b, levels_b, exit_b = main_menu.get_main_menu_items(
     )
     self.assertTrue(isinstance(menu_background, Background),
                     msg='\'Background\' isn\'t instance of Background !')
     self.assertTrue(isinstance(galaxy_run_l, Label),
                     msg='\'Game Label\' isn\'t instance of Label !')
     self.assertTrue(isinstance(play_b, Button),
                     msg='\'New Game Button\' isn\'t instance of Button !')
     self.assertTrue(isinstance(levels_b, Button),
                     msg='\'Levels Button\' isn\'t instance of Button !')
     self.assertTrue(isinstance(exit_b, Button),
                     msg='\'Exit Button\' isn\'t instance of Button !')
コード例 #4
0
    def __init__(self, game_name="Star's Labyrinth", width=1280, height=720):

        pygame.init()
        pygame.font.init()
        pygame.mixer.init()
        pygame.mixer.music.load("assets/song.mp3")

        self.w = width
        self.h = height
        self.clock = pygame.time.Clock()
        self.screen = pygame.display.set_mode((self.w, self.h))
        self.screenName = pygame.display.set_caption(game_name)
        self.gameExit = False
        self.menu = menu.Menu()
        self.in_menu = True
        self.in_instructions = False
        self.pause = False
        self.image = "assets/background.png"
        self.background = pygame.image.load(self.image)
        self.player_hit_sound = pygame.mixer.Sound("assets/playerhit.wav")
        self.player_hitting = pygame.mixer.Sound("assets/whip.wav")
        self.in_highscore = False
        self.myfont = pygame.font.SysFont(pygame.font.get_default_font(), 32)
コード例 #5
0
ファイル: test_menu.py プロジェクト: MichalBroucek/galaxyrun
 def test_levels_menu_buttons(self):
     """
     Test levels menu items
     :return:
     """
     main_menu = menu.Menu()
     levels_background, levels_label, main_menu_b, levels_buttons = main_menu.get_levels_items(
         1)
     self.assertTrue(isinstance(levels_background, Background),
                     msg='\'Background\' doesn\'t exist in Levels window !')
     self.assertTrue(isinstance(levels_label, Label),
                     msg='\'Label\' doesn\'t exist in Levels window !')
     self.assertTrue(
         isinstance(main_menu_b, Button),
         msg='\'Main menu Button\' doesn\'t exist Levels window !')
     self.assertTrue(
         isinstance(levels_buttons[0], Button),
         msg='\'1st Level Button\' doesn\'t exist in Levels window !')
     self.assertTrue(
         isinstance(levels_buttons[1], Button),
         msg='\'2nd Level Button\' doesn\'t exist in Levels window !')
     self.assertTrue(
         isinstance(levels_buttons[2], Button),
         msg='\'3rd Level Button\' doesn\'t exist in Levels window !')
コード例 #6
0
def main():
    pygame.init()

    fps_clock = pygame.time.Clock()
    fps = 23.8
    window = pygame.display.set_mode((640, 480), pygame.DOUBLEBUF)

    mode = "menu"
    menu = m.Menu('config/menu.conf', 'config/user.conf',
                  'config/default.conf', MIXER)

    while (mode):

        while (mode == "menu"):

            if menu.resolution != window.get_size():

                window = pygame.display.set_mode(menu.resolution,
                                                 pygame.DOUBLEBUF)

            m.draw_menu(menu, window)
            pygame.display.flip()
            fps_clock.tick(fps)

            mode = menu.menu_navigation()

        if mode == "game":
            try:
                print "loading map: {0}".format(menu.config["map"])
                game = g.Game(menu.config,
                              'assets/maps/{0}.npy'.format(menu.config["map"]),
                              menu.setup["font"], menu.setup["fontsize"], fps)
                pygame.event.set_grab(True)
                pygame.mouse.set_visible(False)
                pygame.mouse.get_rel()
            except IOError:
                print "no such map: {0}; using Legacy".format(
                    menu.config["map"])
                game = g.Game(menu.config, 'assets/maps/legacy.npy',
                              menu.setup["font"], menu.setup["fontsize"], fps)
                pygame.event.set_grab(True)
                pygame.mouse.set_visible(False)
                pygame.mouse.get_rel()

        while (mode == "game"):
            mode = game.do_step(window)
            pygame.display.flip()
            fps_clock.tick(fps)

        while (mode == "hiscore"):
            print "high-score list is not implemented. returning to menu ..."
            mode = "menu"

        while (mode == "gallery"):
            print "gallery is not implemented. returning to menu ..."
            mode = "menu"

        while (mode == "credits"):
            print "credits is not implemented. returning to menu ..."
            mode = "menu"

        while (mode == "quit"):
            print "quitting game ..."
            pygame.quit()
            mode = False
コード例 #7
0
    def play(self):
        """ the meat of the program """
        #Menus
        main_menu_funcs = {
            'Start': self.set_view,
            'High Scores': self.set_view,
            'Options': self.set_view,
            'Quit': self.quit_game
        }
        main_menu = Menu.Menu(self.screen, list(main_menu_funcs.keys()),
                              main_menu_funcs)

        options_menu_funcs = {'Controls': self.set_view, 'Back': self.set_view}
        options_menu = Menu.Menu(self.screen, list(options_menu_funcs.keys()),
                                 options_menu_funcs)

        controls_menu_funcs = {
            'Up: Up Arrow': self.placeholder,
            'Shoot: Space Bar': self.placeholder,
            'Back': self.set_view
        }
        controls_menu = Menu.Menu(self.screen,
                                  list(controls_menu_funcs.keys()),
                                  controls_menu_funcs)

        highscore_menu_funcs = {'Name': self.set_view, 'Back': self.set_view}
        highscore_menu = Menu.Menu(self.screen,
                                   list(highscore_menu_funcs.keys()),
                                   highscore_menu_funcs)

        #Inputbox for High Scores menu, called when 'Name' is clicked
        name_input_box = Inputbox.Inputbox(self.screen, self.add_menuitem,
                                           "High Scores", "Name")

        the_game = Gamemanager.GameManager(self.screen)

        #Workload
        # Note 1: I don't like hardcoding "Main Menu" as the default curr_view,
        #  but the first menu should be the main menu so it doesn't matter.
        #  Just make sure there is a "Main Menu" in self.views
        #
        # Note 2: These are the views that can be selected by the set_view()
        #  function these are not all the buttons available
        self.views = {
            'Main Menu': main_menu,
            'Options': options_menu,
            'High Scores': highscore_menu,
            'Name': name_input_box,
            'Start': the_game,
            'Controls': controls_menu
        }

        mainloop = True
        self.curr_view = "Main Menu"
        #This is the one loop to rule them all.
        # This should pretty much be the last line,
        # any setup for the game should be above this.
        while mainloop:
            self.clock.tick(60)
            self.views[self.curr_view].display()
            mainloop = self.views["Main Menu"].mainloop