Beispiel #1
0
 def test_user_name_blank(self):
     user = User('user', Color.RED)
     settings_menu = SettingsMenu(10, 10, user, None)
     settings_menu.textBoxDict['Name'].text = ''
     settings_menu.validate()
     self.assertEqual(
         settings_menu.get_status_box('status').text,
         settings_menu.BLANK_ERROR_MSG)
Beispiel #2
0
 def test_user_name_forbidden_symbols_6(self):
     user = User('user', Color.RED)
     settings_menu = SettingsMenu(10, 10, user, None)
     settings_menu.textBoxDict['Name'].text = '*****@*****.**'
     settings_menu.validate()
     self.assertEqual(
         settings_menu.get_status_box('status').text,
         settings_menu.FORBIDDEN_SYMBOLS_ERROR_MSG)
Beispiel #3
0
 def test_user_name_starts_with_digits(self):
     user = User('user', Color.RED)
     settings_menu = SettingsMenu(10, 10, user, None)
     settings_menu.textBoxDict['Name'].text = '1qwertt'
     settings_menu.validate()
     self.assertEqual(
         settings_menu.get_status_box('status').text,
         settings_menu.START_WITH_DIGIT_ERROR_MSG)
Beispiel #4
0
 def test_user_name_maximum_length(self):
     user = User('user', Color.RED)
     settings_menu = SettingsMenu(10, 10, user, None)
     settings_menu.textBoxDict['Name'].text = 'qwertyuiopasdfghj'
     settings_menu.validate()
     self.assertEqual(
         settings_menu.get_status_box('status').text,
         settings_menu.MORE_THAN_MAX_CHAR_ERROR_MSG)
Beispiel #5
0
 def test_user_name_minimum_length(self):
     user = User('user', Color.RED)
     settings_menu = SettingsMenu(10, 10, user, None)
     settings_menu.textBoxDict['Name'].text = 'us'
     settings_menu.validate()
     self.assertEqual(
         settings_menu.get_status_box('status').text,
         settings_menu.LESS_THAN_MIN_CHAR_ERROR_MSG)
Beispiel #6
0
 def test_user_settings_save(self):
     user = User('user', Color.RED)
     settings_menu = SettingsMenu(10, 10, user, lambda: print(''))
     settings_menu.textBoxDict['Name'].text = 'GalconPlayer'
     settings_menu.get_color_button().color_p = Color.PURPLE
     settings_menu.validate()
     self.assertEqual(settings_menu.user.name,
                      settings_menu.get_text_box('Name'))
     self.assertEqual(settings_menu.user.color, Color.PURPLE)
Beispiel #7
0
 def set_settings_mode(self):
     self.mode = self.Mode.SETTINGS
     self.menu = SettingsMenu(main=self,
                              screen=self.display,
                              settings=self.settings)
Beispiel #8
0
 def set_menu_mode(self):
     self.mode = self.Mode.MENU
     self.menu = MainMenu(main=self,
                          screen=self.display,
                          settings=self.settings)
Beispiel #9
0
class Plumber:
    GAME_NAME = 'Plumber'
    FPS = 60

    class Mode(Enum):
        MENU = 0
        SETTINGS = 1
        GAME = 2
        QUITTING = 3

    def __init__(self):
        self.game = None
        self.menu = None
        self.mode = None
        self.settings = Settings()

        pygame.init()
        pygame.display.set_caption(self.GAME_NAME)
        self.display = pygame.display.set_mode(self.settings.screen_size())

    def set_menu_mode(self):
        self.mode = self.Mode.MENU
        self.menu = MainMenu(main=self,
                             screen=self.display,
                             settings=self.settings)

    def set_game_mode(self):
        self.mode = self.Mode.GAME
        self.game = Game(main=self,
                         screen=self.display,
                         settings=self.settings)

    def set_settings_mode(self):
        self.mode = self.Mode.SETTINGS
        self.menu = SettingsMenu(main=self,
                                 screen=self.display,
                                 settings=self.settings)

    def set_quitting_mode(self):
        self.mode = self.Mode.QUITTING

    def process_events(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.set_quitting_mode()
            if event.type == pygame.MOUSEBUTTONDOWN:
                pos = pygame.mouse.get_pos()
                if self.mode is self.Mode.GAME:
                    self.game.handle_click(pos)
            if event.type == pygame.KEYDOWN:
                if self.mode in {self.Mode.MENU, self.Mode.SETTINGS}:
                    self.menu.handle_key(event.key)
                elif self.mode is self.Mode.GAME:
                    self.game.handle_key(event.key)

    def run_loop(self):
        if self.mode is self.Mode.GAME:
            self.game.run_loop()

    def render_quitting(self):
        self.display.fill(WHITE)
        blit_text('Thanks for playing!', self.settings.screen_center(),
                  self.display, 60)

    def render(self):
        self.display = pygame.display.set_mode(self.settings.screen_size())

        if self.mode in {self.Mode.MENU, self.Mode.SETTINGS}:
            self.menu.blitme()
        elif self.mode == self.Mode.GAME:
            self.game.blitme()
        else:  # self.mode == self.Mode.QUITTING
            self.render_quitting()

        pygame.display.update()

    def run(self):
        self.set_menu_mode()

        while self.mode is not self.Mode.QUITTING:
            self.process_events()
            self.run_loop()
            self.render()
            sleep(1 / self.FPS)

        sleep(0.5)
        pygame.quit()
Beispiel #10
0
 def test_creation_settings_menu(self):
     user = User('user', Color.RED)
     settings_menu = SettingsMenu(10, 10, user, None)
     self.assertEqual(settings_menu.get_text_box('Name'), user.name)
     self.assertEqual(settings_menu.get_color_button().color_p, user.color)
Beispiel #11
0
 def show_settings(self):
     self.settingsMenu = SettingsMenu(self.w, self.h, self.user,
                                      self.show_main_menu)
     self.mode = self.settingsMenu
     self.screen.blit(self.mode.bg, (0, 0))
     disp.update()