Esempio n. 1
0
    def __init__(self):
        pygame.init()

        self.fullscreen = GAME['fullscreen']
        self.set_resolution("mainmenu")

        pygame.display.set_caption(GAME['caption'])
        self.clock = pygame.time.Clock()
        self.timeinterval = GAME['fps-limit']

        self.mode = Mainmenu(self.screen.get_size())
Esempio n. 2
0
 def modeswitch(self, done):  # done is tuple with necessary information
     if done:
         self.blit()
         self.mode.update()
         self.blit()
         newmode = done[0]
         if newmode == "freemode":
             self.mode = Freemode(done[1], self.screen.get_size())
         elif newmode == "scoremode":
             self.mode = Scoremode(done[1], self.screen.get_size(), done[2])
         elif newmode == "timesavemode":
             self.mode = Timemode(done[1], self.screen.get_size(), done[2],
                                  done[3])
         elif newmode == "clicktocontinue":
             self.mode = ClickToContinue(done[1], self.screen.get_size(),
                                         done[2])
         elif newmode == "clicktocontinue_scoremode_loss":
             self.mode = ClickToContinue(done[1],
                                         self.screen.get_size(),
                                         done[2],
                                         wait=700)
         elif newmode == "selecthighscore":
             self.mode = SelectHighscore(self.screen.get_size())
         elif newmode == "mainmenu":
             self.mode = Mainmenu(self.screen.get_size())
Esempio n. 3
0
 def modeswitch(self,done): # done is tuple with necessary information
     if done:
         self.blit()
         self.mode.update()
         self.blit()
         newmode = done[0]
         if newmode == "freemode":
             self.mode = Freemode(done[1],self.screen.get_size())
         elif newmode == "scoremode":
             self.mode = Scoremode(done[1],self.screen.get_size(),done[2])
         elif newmode == "timesavemode":
             self.mode = Timemode(done[1],self.screen.get_size(),
                                  done[2],done[3])
         elif newmode == "clicktocontinue":
             self.mode = ClickToContinue(done[1],
                                         self.screen.get_size(),
                                         done[2])
         elif newmode == "clicktocontinue_scoremode_loss":
             self.mode = ClickToContinue(done[1],
                                         self.screen.get_size(),
                                         done[2],
                                         wait=700)
         elif newmode == "selecthighscore":
             self.mode = SelectHighscore(self.screen.get_size())
         elif newmode == "mainmenu":
             self.mode = Mainmenu(self.screen.get_size())
Esempio n. 4
0
    def __init__(self):
        pygame.init()

        self.fullscreen = GAME['fullscreen']
        self.set_resolution("mainmenu")

        pygame.display.set_caption(GAME['caption'])
        self.clock = pygame.time.Clock()
        self.timeinterval = GAME['fps-limit']

        self.mode = Mainmenu(self.screen.get_size())
Esempio n. 5
0
    def handle_button_clicks(self):
        if self.mode.name == "Scoremode":
            buttons = self.mode.button_clicked()
            for name in buttons:
                if name == "quit":
                    nice_print(["Game.handle_button_clicks:",
                                "'quit' clicked: exiting"])
                    exit()
                elif name == "restart":
                    self.mode = Scoremode(1,self.screen.get_size())

                elif name == "pause":
                    self.mode.set_pause()

                elif name == "main_menu":
                    self.set_resolution("mainmenu")
                    self.mode = Mainmenu(self.screen.get_size())

        if self.mode.name == "Timemode":
            buttons = self.mode.button_clicked()
            for name in buttons:
                if name == "quit":
                    nice_print(["Game.handle_button_clicks:",
                                "'quit' clicked: exiting"])
                    exit()
                elif name == "restart":
                    self.mode = Timemode(1,self.screen.get_size())

                elif name == "pause":
                    self.mode.set_pause()

                elif name == "main_menu":
                    self.set_resolution("mainmenu")
                    self.mode = Mainmenu(self.screen.get_size())

        elif self.mode.name == "Mainmenu":
            buttons = self.mode.button_clicked()
            for name in buttons:
                if name == "scoremode":
                    self.set_resolution("gametime")
                    self.mode = Scoremode(1,self.screen.get_size())
                elif name == "timesavemode":
                    self.set_resolution("gametime")
                    self.mode = Timemode(1,self.screen.get_size())
                elif name == "highscore":
                    self.mode = SelectHighscore(self.screen.get_size())
                elif name == "help":
                    open_help_in_browser()
                elif name == "exit":
                    nice_print(["Game.handle_button_clicks:",
                                "'quit' clicked: exiting"])
                    exit()
        elif self.mode.name == "SelectHighscore":
            buttons = self.mode.button_clicked()
            for name in buttons:
                if name == "back_highscore_button":
                    self.mode = Mainmenu(self.screen.get_size())
                elif name == "timesave_highscore_button":
                    self.mode = Highscore(self.screen.get_size(),
                                          gametype="timesave-game",
                                          title_prefix="Timesave ")
                elif name == "normalgame_highscore_button":
                    self.mode = Highscore(self.screen.get_size(),
                                          gametype="normal-game",
                                          title_prefix="Normal ")
Esempio n. 6
0
class Game(object):
    def __init__(self):
        pygame.init()

        self.fullscreen = GAME['fullscreen']
        self.set_resolution("mainmenu")

        pygame.display.set_caption(GAME['caption'])
        self.clock = pygame.time.Clock()
        self.timeinterval = GAME['fps-limit']

        self.mode = Mainmenu(self.screen.get_size())

    def set_resolution(self,display_name):
        if display_name == "mainmenu":
            self.screen = pygame.display.set_mode(MENU['resolution'])        
        elif display_name == "gametime":
            if self.fullscreen:
                self.screen = pygame.display.set_mode(GAME['resolution'],pygame.FULLSCREEN)
            else:
                self.screen = pygame.display.set_mode(GAME['resolution'])

    def loop(self):
        while 1:
            self.handle_button_clicks()

            self.modeswitch(self.mode.done())
            self.events()

            self.blit()
            self.mode.update()

            pygame.display.flip()
            self.clock.tick(self.timeinterval)

    def handle_button_clicks(self):
        if self.mode.name == "Scoremode":
            buttons = self.mode.button_clicked()
            for name in buttons:
                if name == "quit":
                    nice_print(["Game.handle_button_clicks:",
                                "'quit' clicked: exiting"])
                    exit()
                elif name == "restart":
                    self.mode = Scoremode(1,self.screen.get_size())

                elif name == "pause":
                    self.mode.set_pause()

                elif name == "main_menu":
                    self.set_resolution("mainmenu")
                    self.mode = Mainmenu(self.screen.get_size())

        if self.mode.name == "Timemode":
            buttons = self.mode.button_clicked()
            for name in buttons:
                if name == "quit":
                    nice_print(["Game.handle_button_clicks:",
                                "'quit' clicked: exiting"])
                    exit()
                elif name == "restart":
                    self.mode = Timemode(1,self.screen.get_size())

                elif name == "pause":
                    self.mode.set_pause()

                elif name == "main_menu":
                    self.set_resolution("mainmenu")
                    self.mode = Mainmenu(self.screen.get_size())

        elif self.mode.name == "Mainmenu":
            buttons = self.mode.button_clicked()
            for name in buttons:
                if name == "scoremode":
                    self.set_resolution("gametime")
                    self.mode = Scoremode(1,self.screen.get_size())
                elif name == "timesavemode":
                    self.set_resolution("gametime")
                    self.mode = Timemode(1,self.screen.get_size())
                elif name == "highscore":
                    self.mode = SelectHighscore(self.screen.get_size())
                elif name == "help":
                    open_help_in_browser()
                elif name == "exit":
                    nice_print(["Game.handle_button_clicks:",
                                "'quit' clicked: exiting"])
                    exit()
        elif self.mode.name == "SelectHighscore":
            buttons = self.mode.button_clicked()
            for name in buttons:
                if name == "back_highscore_button":
                    self.mode = Mainmenu(self.screen.get_size())
                elif name == "timesave_highscore_button":
                    self.mode = Highscore(self.screen.get_size(),
                                          gametype="timesave-game",
                                          title_prefix="Timesave ")
                elif name == "normalgame_highscore_button":
                    self.mode = Highscore(self.screen.get_size(),
                                          gametype="normal-game",
                                          title_prefix="Normal ")

    def blit(self):
        if self.mode.changed:
            nice_print(["Mode {0!r} changed:".format(self.mode.name),
                        "Blitting on screen\n"])
            self.screen.blit(self.mode.background,(0,0))


    def events(self):
        for i in pygame.event.get():
            if i.type==pygame.QUIT or (i.type==pygame.KEYDOWN and i.key==pygame.K_ESCAPE or
                                       i.type==pygame.KEYDOWN and i.key==pygame.K_q):
                exit()
            if i.type==pygame.MOUSEBUTTONDOWN:
                self.mode.mousedown(i.pos)
            if i.type==pygame.MOUSEBUTTONUP:
                self.mode.mouseup(i.pos)

    def modeswitch(self,done): # done is tuple with necessary information
        if done:
            self.blit()
            self.mode.update()
            self.blit()
            newmode = done[0]
            if newmode == "freemode":
                self.mode = Freemode(done[1],self.screen.get_size())
            elif newmode == "scoremode":
                self.mode = Scoremode(done[1],self.screen.get_size(),done[2])
            elif newmode == "timesavemode":
                self.mode = Timemode(done[1],self.screen.get_size(),
                                     done[2],done[3])
            elif newmode == "clicktocontinue":
                self.mode = ClickToContinue(done[1],
                                            self.screen.get_size(),
                                            done[2])
            elif newmode == "clicktocontinue_scoremode_loss":
                self.mode = ClickToContinue(done[1],
                                            self.screen.get_size(),
                                            done[2],
                                            wait=700)
            elif newmode == "selecthighscore":
                self.mode = SelectHighscore(self.screen.get_size())
            elif newmode == "mainmenu":
                self.mode = Mainmenu(self.screen.get_size())
Esempio n. 7
0
    def handle_button_clicks(self):
        if self.mode.name == "Scoremode":
            buttons = self.mode.button_clicked()
            for name in buttons:
                if name == "quit":
                    nice_print([
                        "Game.handle_button_clicks:", "'quit' clicked: exiting"
                    ])
                    exit()
                elif name == "restart":
                    self.mode = Scoremode(1, self.screen.get_size())

                elif name == "pause":
                    self.mode.set_pause()

                elif name == "main_menu":
                    self.set_resolution("mainmenu")
                    self.mode = Mainmenu(self.screen.get_size())

        if self.mode.name == "Timemode":
            buttons = self.mode.button_clicked()
            for name in buttons:
                if name == "quit":
                    nice_print([
                        "Game.handle_button_clicks:", "'quit' clicked: exiting"
                    ])
                    exit()
                elif name == "restart":
                    self.mode = Timemode(1, self.screen.get_size())

                elif name == "pause":
                    self.mode.set_pause()

                elif name == "main_menu":
                    self.set_resolution("mainmenu")
                    self.mode = Mainmenu(self.screen.get_size())

        elif self.mode.name == "Mainmenu":
            buttons = self.mode.button_clicked()
            for name in buttons:
                if name == "scoremode":
                    self.set_resolution("gametime")
                    self.mode = Scoremode(1, self.screen.get_size())
                elif name == "timesavemode":
                    self.set_resolution("gametime")
                    self.mode = Timemode(1, self.screen.get_size())
                elif name == "highscore":
                    self.mode = SelectHighscore(self.screen.get_size())
                elif name == "help":
                    open_help_in_browser()
                elif name == "exit":
                    nice_print([
                        "Game.handle_button_clicks:", "'quit' clicked: exiting"
                    ])
                    exit()
        elif self.mode.name == "SelectHighscore":
            buttons = self.mode.button_clicked()
            for name in buttons:
                if name == "back_highscore_button":
                    self.mode = Mainmenu(self.screen.get_size())
                elif name == "timesave_highscore_button":
                    self.mode = Highscore(self.screen.get_size(),
                                          gametype="timesave-game",
                                          title_prefix="Timesave ")
                elif name == "normalgame_highscore_button":
                    self.mode = Highscore(self.screen.get_size(),
                                          gametype="normal-game",
                                          title_prefix="Normal ")
Esempio n. 8
0
class Game(object):
    def __init__(self):
        pygame.init()

        self.fullscreen = GAME['fullscreen']
        self.set_resolution("mainmenu")

        pygame.display.set_caption(GAME['caption'])
        self.clock = pygame.time.Clock()
        self.timeinterval = GAME['fps-limit']

        self.mode = Mainmenu(self.screen.get_size())

    def set_resolution(self, display_name):
        if display_name == "mainmenu":
            self.screen = pygame.display.set_mode(MENU['resolution'])
        elif display_name == "gametime":
            if self.fullscreen:
                self.screen = pygame.display.set_mode(GAME['resolution'],
                                                      pygame.FULLSCREEN)
            else:
                self.screen = pygame.display.set_mode(GAME['resolution'])

    def loop(self):
        while 1:
            self.handle_button_clicks()

            self.modeswitch(self.mode.done())
            self.events()

            self.blit()
            self.mode.update()

            pygame.display.flip()
            self.clock.tick(self.timeinterval)

    def handle_button_clicks(self):
        if self.mode.name == "Scoremode":
            buttons = self.mode.button_clicked()
            for name in buttons:
                if name == "quit":
                    nice_print([
                        "Game.handle_button_clicks:", "'quit' clicked: exiting"
                    ])
                    exit()
                elif name == "restart":
                    self.mode = Scoremode(1, self.screen.get_size())

                elif name == "pause":
                    self.mode.set_pause()

                elif name == "main_menu":
                    self.set_resolution("mainmenu")
                    self.mode = Mainmenu(self.screen.get_size())

        if self.mode.name == "Timemode":
            buttons = self.mode.button_clicked()
            for name in buttons:
                if name == "quit":
                    nice_print([
                        "Game.handle_button_clicks:", "'quit' clicked: exiting"
                    ])
                    exit()
                elif name == "restart":
                    self.mode = Timemode(1, self.screen.get_size())

                elif name == "pause":
                    self.mode.set_pause()

                elif name == "main_menu":
                    self.set_resolution("mainmenu")
                    self.mode = Mainmenu(self.screen.get_size())

        elif self.mode.name == "Mainmenu":
            buttons = self.mode.button_clicked()
            for name in buttons:
                if name == "scoremode":
                    self.set_resolution("gametime")
                    self.mode = Scoremode(1, self.screen.get_size())
                elif name == "timesavemode":
                    self.set_resolution("gametime")
                    self.mode = Timemode(1, self.screen.get_size())
                elif name == "highscore":
                    self.mode = SelectHighscore(self.screen.get_size())
                elif name == "help":
                    open_help_in_browser()
                elif name == "exit":
                    nice_print([
                        "Game.handle_button_clicks:", "'quit' clicked: exiting"
                    ])
                    exit()
        elif self.mode.name == "SelectHighscore":
            buttons = self.mode.button_clicked()
            for name in buttons:
                if name == "back_highscore_button":
                    self.mode = Mainmenu(self.screen.get_size())
                elif name == "timesave_highscore_button":
                    self.mode = Highscore(self.screen.get_size(),
                                          gametype="timesave-game",
                                          title_prefix="Timesave ")
                elif name == "normalgame_highscore_button":
                    self.mode = Highscore(self.screen.get_size(),
                                          gametype="normal-game",
                                          title_prefix="Normal ")

    def blit(self):
        if self.mode.changed:
            nice_print([
                "Mode {0!r} changed:".format(self.mode.name),
                "Blitting on screen\n"
            ])
            self.screen.blit(self.mode.background, (0, 0))

    def events(self):
        for i in pygame.event.get():
            if i.type == pygame.QUIT or (
                    i.type == pygame.KEYDOWN and i.key == pygame.K_ESCAPE
                    or i.type == pygame.KEYDOWN and i.key == pygame.K_q):
                exit()
            if i.type == pygame.MOUSEBUTTONDOWN:
                self.mode.mousedown(i.pos)
            if i.type == pygame.MOUSEBUTTONUP:
                self.mode.mouseup(i.pos)

    def modeswitch(self, done):  # done is tuple with necessary information
        if done:
            self.blit()
            self.mode.update()
            self.blit()
            newmode = done[0]
            if newmode == "freemode":
                self.mode = Freemode(done[1], self.screen.get_size())
            elif newmode == "scoremode":
                self.mode = Scoremode(done[1], self.screen.get_size(), done[2])
            elif newmode == "timesavemode":
                self.mode = Timemode(done[1], self.screen.get_size(), done[2],
                                     done[3])
            elif newmode == "clicktocontinue":
                self.mode = ClickToContinue(done[1], self.screen.get_size(),
                                            done[2])
            elif newmode == "clicktocontinue_scoremode_loss":
                self.mode = ClickToContinue(done[1],
                                            self.screen.get_size(),
                                            done[2],
                                            wait=700)
            elif newmode == "selecthighscore":
                self.mode = SelectHighscore(self.screen.get_size())
            elif newmode == "mainmenu":
                self.mode = Mainmenu(self.screen.get_size())