コード例 #1
0
 def move(self, _num):
     if self.currentPosition + _num >= 0:
         if self.currentPosition + _num < len(self.positions):
             self.currentPosition += _num
             self.update_position(self.currentPosition)
             return self.currentPosition
         else:
             Utilities.show_error(
                 self.screen,
                 str(_num) +
                 " moves the cat off of the number line. Try Again!")
     else:
         Utilities.show_error(
             self.screen,
             str(_num) +
             " moves the cat off of the number line. Try Again!")
コード例 #2
0
    def __init__(self, screen, x, y):
        # make UI
        w, h = Utilities.get_width_height()

        self.ui_width = 370
        self.ui_height = 160

        spacing = (h - y - self.ui_height) / 2
        y = y + spacing
        self.y = y

        self.x = x
        x = x - self.ui_width / 2

        self.button_sub = Button(screen, (x, y), (80, (self.ui_height * 0.56)),
                                 "-", 80, 2)
        self.user_input = UserInput(screen, (x + 85, y), 200,
                                    self.ui_height * 0.56)
        self.button_add = Button(screen, (x + 290, y),
                                 (80, (self.ui_height * 0.56)), "+", 80, 1)
        self.button_go = Button(screen, (x, y + 95),
                                (self.ui_width, (self.ui_height * 0.44)), "Go",
                                60, 3)
        self.button_quit = Button(screen, (w - 110, 10), (100, 50), "Quit", 25,
                                  5)
        self.button_restart = Button(screen, (w - 220, 10), (100, 50),
                                     "Restart", 25, 4)

        self.screen = screen
コード例 #3
0
    def __init__(self, _screen):
        self.screen = _screen

        # setup variables
        self.w, self.h = Utilities.get_width_height(
        )  # width and height of the screen
        self.screen = _screen

        # make start screen
        self.start_screen = StartScreen(self.screen, self.w / 2, self.h / 2)

        # make end screen
        self.end_screen = EndScreen(self.screen, self.w / 2, self.h / 2)

        # make UI
        self.ui = UI(self.screen, self.w / 2, self.h / 2 + 50)

        # make Number Line
        self.number_line = NumberLine(self.screen, self.w, self.h)

        # make cat
        self.cat = Character(self.number_line.circle_pos, self.LEFT_CAT,
                             int(self.number_line.spacing * 1.3),
                             int(self.number_line.spacing * 1.3), self.screen)
        self.cat_position = -1

        # make mouse
        self.mouse = Character(self.number_line.circle_pos, self.MOUSE,
                               int((self.number_line.spacing / 2) * 1.3),
                               int((self.number_line.spacing / 2) * 1.3),
                               self.screen, self.cat.get_x_pos())
        self.mouse_position = -1

        self.end = False
コード例 #4
0
 def display_numbers(self):
     for num in range(0, len(self.circle_pos)):
         # draw number beneath circle
         x = self.circle_pos[num][0] - 5
         y = self.circle_pos[num][1] + 15
         text_surface = Utilities.make_text_surface(str(num * self.level), 20)
         text_size = text_surface.get_size()
         x = x - (text_size[0]/4)
         self.screen.blit(text_surface, (x, y))
コード例 #5
0
    def display_all_help_text(self):
        w, h = Utilities.get_width_height()
        help_text_width = ((w - self.ui_width) / 2)
        help_text_padding = help_text_width * 0.1
        help_text_width = help_text_width - (help_text_padding * 2)

        self.display_text("Try and catch the mouse!", w / 2, h / 4, 30)
        Utilities.draw_text(
            self.screen,
            "Type the number in the box or use the + and - buttons to change it.",
            (self.x + self.ui_width / 2 + help_text_width / 2 +
             help_text_padding, self.y, help_text_width, self.ui_height), 25)
        Utilities.draw_text(
            self.screen,
            "Move the cat by telling it how many numbers to jump. " +
            "Use negative numbers to move backwards.",
            (self.x - self.ui_width / 2 - help_text_width / 2 -
             help_text_padding, self.y, help_text_width, self.ui_height), 25)
コード例 #6
0
ファイル: StartScreen.py プロジェクト: jpazer/KittyCount
    def __init__(self, screen, x, y):
        # make UI
        self.x = x
        self.y = y
        self.w, self.h = Utilities.get_width_height()
        self.screen = screen

        self.button_start = Button(screen, (x - 150, y), (300, 100), "Start",
                                   60, 6)
        self.cat = pygame.image.load("../assets/cat1.png")
        self.mouse = pygame.image.load("../assets/mouse3.png")
コード例 #7
0
    def __init__(self, screen, position, size, text, text_size, event_num):
        self.screen = screen
        self.position = position  # x, y of button and text
        self.size = size  # w, h of button
        self.text = text  # string
        self.text_size = text_size  # pt size of text

        # make the text surface
        self.text_surface = Utilities.make_text_surface(
            self.text, self.text_size)

        # calculate the padding needed to center the text
        text_w, text_h = self.text_surface.get_size()
        button_w, button_h = self.size
        self.padding_x = (button_w - text_w) / 2
        self.padding_y = (button_h - text_h) / 2

        self.event = pygame.event.Event(pygame.USEREVENT + event_num)
コード例 #8
0
 def display_text(self, text, x, y, size):
     text_surface = Utilities.make_text_surface(text, size)
     text_w, text_h = text_surface.get_size()
     self.screen.blit(text_surface, (x - text_w/2, y))
コード例 #9
0
 def clear_numbers(self):
     # cover over numbers
     pygame.draw.rect(self.screen, (255, 255, 255), (0, self.number_line_y + 10,
                                                     Utilities.get_width_height()[0], 30), 0)
コード例 #10
0
 def update_level(self, level):
     # display level
     pygame.draw.rect(self.screen, (255, 255, 255), (10, 10, 200, 50), 0)
     self.screen.blit(
         Utilities.make_text_surface("Level: " + str(level), 30), (20, 20))
コード例 #11
0
    def loop(self, events):
        # draw UI
        if self.game_state == "start":
            self.start_screen.display(events)
        if self.game_state == "play":
            self.ui.display(events)
        if self.game_state == "end":
            self.end_screen.display(events)

        for event in events:

            if event.type == self.GO or (event.type == pygame.KEYDOWN
                                         and event.key == pygame.K_RETURN):
                Utilities.show_error(self.screen, "")  # clear previous error
                input_num = self.ui.user_input.get_input()

                if input_num is not None:

                    if input_num % self.level == 0:
                        new_position = int(input_num / self.level)

                        if self.cat_position + new_position >= 0:

                            if self.cat_position + new_position < self.number_line.num_of_points:
                                self.cat_position = self.cat.move(new_position)
                                self.mouse.display()
                                self.ui.user_input.clear()

                                if self.cat_position == self.mouse_position:
                                    self.mouse_position = self.mouse.set_random_position(
                                        self.cat_position)
                                    self.cat.display()
                                    self.level += 1

                                    if self.level > self.MAX_LEVEL:
                                        self.game_state = "end"
                                    else:
                                        self.ui.update_level(self.level)
                                        self.number_line.change_level(
                                            self.level)
                            else:
                                Utilities.show_error(
                                    self.screen,
                                    str(input_num) + self.CAT_TOO_FAR_MESSAGE)
                        else:
                            Utilities.show_error(
                                self.screen,
                                str(input_num) + self.CAT_TOO_FAR_MESSAGE)
                    else:
                        equation = ""
                        if self.ui.user_input.get_input() > 0:
                            equation = str(
                                self.cat_position * self.level) + " + " + str(
                                    self.ui.user_input.get_input())
                        else:
                            equation = str(
                                self.cat_position * self.level) + " - " + str(
                                    self.ui.user_input.get_input())[1:]
                        Utilities.show_error(
                            self.screen,
                            equation + self.NOT_ON_THE_NUMBER_LINE_MESSAGE)
                else:
                    Utilities.show_error(self.screen, self.EMPTY_BOX_MESSAGE)

            if event.type == self.ADD:
                self.ui.user_input.add(1)
            if event.type == self.SUB:
                self.ui.user_input.add(-1)

            if event.type == self.START:
                self.game_state = "play"
                self.game_display()

            if event.type == self.RESTART:
                self.level = 1
                self.game_state = "play"
                self.game_display()

            if event.type == self.QUIT:
                pygame.event.post(pygame.event.Event(pygame.QUIT))

            if self.ui.user_input.get_input(
            ) is not None and self.ui.user_input.get_input() < 0:
                self.cat.set_display_image(self.LEFT_CAT)
                self.cat.erase()
                self.cat.display()
                self.mouse.erase()
                self.mouse.display()
            if self.ui.user_input.get_input(
            ) is not None and self.ui.user_input.get_input() > 0:
                self.cat.set_display_image(self.RIGHT_CAT)
                self.cat.erase()
                self.cat.display()
                self.mouse.erase()
                self.mouse.display()