Esempio n. 1
0
 def create_labels(self):
     self.score_label = TextObject(c.score_offset, c.status_offset_y,
                                   lambda: f'SCORE: {self.score}',
                                   c.text_color, c.font_name, c.font_size)
     self.objects.append(self.score_label)
     self.lives_label = TextObject(c.lives_offset, c.status_offset_y,
                                   lambda: f'LIVES: {self.lives}',
                                   c.text_color, c.font_name, c.font_size)
     self.objects.append(self.lives_label)
Esempio n. 2
0
    def create_labels(self):
        self.score_label_left = TextObject(c.lives_left_offset_x,
                                           c.lives_left_offset_y,
                                           lambda: f'SCORE: {self.score_left}',
                                           c.text_color, c.font_name,
                                           c.font_size)
        self.objects.append(self.score_label_left)

        self.score_label_right = TextObject(
            c.lives_right_offset_x, c.lives_right_offset_y,
            lambda: f'SCORE: {self.score_right}', c.text_color, c.font_name,
            c.font_size)
        self.objects.append(self.score_label_right)
Esempio n. 3
0
 def create_labels(self):
     score_label = TextObject(c.offset_score, c.offset_status_y,
                              lambda: f'SCORE: {self.score}', c.text_color,
                              c.font_name, c.font_size)
     self.objects.append(score_label)
     level_label = TextObject(c.offset_level, c.offset_status_y,
                              lambda: f'LEVEL: {self.game_level}',
                              c.text_color, c.font_name, c.font_size)
     self.objects.append(level_label)
     lives_label = TextObject(c.offset_lives, c.offset_status_y,
                              lambda: f'LIVES: {self.lives}', c.text_color,
                              c.font_name, c.font_size)
     self.objects.append(lives_label)
Esempio n. 4
0
 def create_labels(self):
     self.score_label = TextObject(
         cfg.score_offset,
         cfg.score_offset_y,
         "",
         text_func=lambda: 'SCORE: {}'.format(self.score['score']))
     self.objects.append(self.score_label)
     self.pre_score_label = TextObject(
         cfg.score_offset,
         cfg.score_offset_y + 100,
         "",
         text_func=lambda: 'PLUS: {}'.format(self.pre_score['pre_score']))
     self.objects.append(self.pre_score_label)
Esempio n. 5
0
 def draw_menu(self):
     w, h = pygame.display.get_surface().get_size()
     exit_button = TextObject(610, 630, "Exit(Esc)", c.font_color,
                              c.font_name, c.font_size)
     help_button = TextObject(380, 630, "Help(H)", c.font_color,
                              c.font_name, c.font_size)
     reset_button = TextObject(510, 710, "New Game(N)", c.font_color,
                               c.font_name, c.font_size)
     exit_button.draw(self.surface)
     help_button.draw(self.surface)
     reset_button.draw(self.surface)
     if self.help_opened:
         self.draw_help()
     if self.game_over:
         self.draw_victory()
Esempio n. 6
0
    def create_orders(self):
        choose_text = TextObject(cfg.screen_width / 2 - 70, 30,
                                 'Select field sizes')

        def orders(button):
            cfg.map_width = int(button.text_easy[0:2])
            cfg.map_height = int(button.text_easy[3:])
            for b in self.order_buttons:
                self.objects.remove(b)
            self.objects.remove(choose_text)
            self.order_buttons = []
            self.mouse_handlers = []
            self.create_colors()

        self.objects.append(choose_text)
        for i, (text, handler) in enumerate(
            (('09x12', orders), ('12x15', orders), ('15x18', orders),
             ('18x21', orders))):
            width = cfg.screen_width / 4.5 + 2 * i * (cfg.menu_button_w + 3)
            b = Button(width,
                       cfg.screen_height / 3 + (cfg.menu_button_h + 3),
                       cfg.menu_button_w,
                       cfg.menu_button_h,
                       text,
                       handler,
                       padding=5)
            self.objects.append(b)
            self.order_buttons.append(b)
            self.mouse_handlers.append(b.handle_mouse_event)
Esempio n. 7
0
 def __init__(self, x, y, w, h, text, on_click=lambda x: None, padding=0):
     super().__init__(x, y, w, h)
     self.state = 'normal'
     self.on_click = on_click
     self.text = TextObject(x + padding, y + padding, lambda: text,
                            c.button_text_color, c.font_name,
                            c.menu_font_size)
Esempio n. 8
0
    def create_colors(self):
        choose_text = TextObject(cfg.screen_width / 2 - 100, 30,
                                 'Choose count of colors')

        def colors(button):
            cfg.count_colors = int(button.text_easy)
            for b in self.color_buttons:
                self.objects.remove(b)
            self.objects.remove(choose_text)
            self.color_buttons = []
            self.mouse_handlers = []
            self.create_game()

        self.objects.append(choose_text)
        for i, (text, handler) in enumerate(
            (('3', colors), ('4', colors), ('5', colors))):
            width = cfg.screen_width / 3.5 + 2 * i * (cfg.menu_button_w + 3)
            b = Button(width,
                       cfg.screen_height / 3 + (cfg.menu_button_h + 3),
                       cfg.menu_button_w,
                       cfg.menu_button_h,
                       text,
                       handler,
                       padding=5)
            self.objects.append(b)
            self.color_buttons.append(b)
            self.mouse_handlers.append(b.handle_mouse_event)
Esempio n. 9
0
 def __init__(self, x, y, contents, font_name, font_size):
     self.text = contents['text'].item()
     self.label = contents['label'].item()
     self.color = literal_eval(contents['color'].item())
     self.stimulus = TextObject(
     x, y, lambda: self.text,
     self.color, font_name, font_size
     )
Esempio n. 10
0
 def create_remain_repeate_display(self):
     rr_display = ClockDisplay(c.rr_x, c.rr_y, c.rr_x_size, c.rr_y_size,
                               c.rr_color[self.style_mode])
     rr_text = TextObject(rr_display.centerx, rr_display.centery,
                          self.text_for_rr,
                          c.rr_text_color[self.style_mode], c.rr_font_name,
                          c.rr_font_size, True)
     self.objects.append(rr_display)
     self.objects.append(rr_text)
Esempio n. 11
0
 def create_mode_display(self):
     mode_display = ClockDisplay(c.mode_x, c.mode_y, c.mode_x_size,
                                 c.mode_y_size,
                                 c.mode_color[self.style_mode])
     mode_text = TextObject(mode_display.centerx, mode_display.centery,
                            self.text_for_mode,
                            c.mode_text_color[self.style_mode],
                            c.mode_font_name, c.mode_font_size, True)
     self.objects.append(mode_display)
     self.objects.append(mode_text)
Esempio n. 12
0
 def create_clock_display(self):
     clock_display = ClockDisplay(c.clock_x, c.clock_y, c.clock_x_size,
                                  c.clock_y_size,
                                  c.clock_color[self.style_mode])
     #text =  time.strftime("%H : %M",
     clock_text = TextObject(clock_display.centerx, clock_display.centery,
                             self.text_for_time,
                             c.clock_text_color[self.style_mode],
                             c.clock_font_name, c.clock_font_size, True)
     self.objects.append(clock_display)
     self.objects.append(clock_text)
Esempio n. 13
0
 def __init__(self, x, y, w, h, text, on_click=lambda x: None, padding=0):
     self.bounds = pygame.Rect(x, y, w, h)  # прямоугольный объект
     self.x = x
     self.y = y
     self.w = w
     self.h = h
     self.padding = padding
     self.state = 'normal'
     self.on_click = on_click
     self.text = TextObject(x + padding, y + padding, lambda: text,
                            c.button_text_color, c.font_name, c.font_size)
Esempio n. 14
0
 def show_message(self,
                  text,
                  color=colors.GRAY24,
                  font_name='Century',
                  font_size=20,
                  centralized=False):
     message = TextObject(c.w_x_size // 2, c.w_y_size // 2, lambda: text,
                          color, font_name, font_size, True)
     self.draw()
     message.draw(self.surface)
     pygame.display.update()
     time.sleep(c.message_duration)
 def show_message(self,
                  text,
                  color=colors.WHITE,
                  font_name='Arial',
                  font_size=20,
                  centralized=False):
     message = TextObject(c.screen_width // 2, c.screen_height // 2,
                          lambda: text, color, font_name, font_size)
     self.draw()
     message.draw(self.surface, centralized)
     pygame.display.update()
     time.sleep(c.message_duration)
Esempio n. 16
0
 def show_message(self,
                  text,
                  color=cfg.text_color,
                  font_name=cfg.font_name,
                  font_size=cfg.font_size):
     message = TextObject(cfg.screen_width // 2 - 40,
                          (cfg.screen_height // 2) - 40, text, font_size,
                          color, font_name)
     self.draw()
     message.draw(self.surface)
     pygame.display.update()
     time.sleep(3)
Esempio n. 17
0
 def __init__(self):
     Game.__init__(self, 'Stimulus control competition task', c.background_image, c.frame_rate)
     # Loads experimental setup
     self.df = pandas.read_csv(c._thisDir + os.sep + 'stimuli' + os.sep + c.setup,
                               encoding="utf-8"
                               )
     # Creates iterator to loop over phases
     self.phases = itertools.cycle(self.df['phase'].unique())
     self.phase = self.phases.next()
     # Constructs counters
     self.score = 0
     self.counters = []
     self.counters.append(TextObject(
                              0.06*w, 0.06*h,
                              lambda: u'Счет: %i' %self.score,
                              colors.WHITE, c.font_name, int(c.font_size*h)
                             )
                          )
     # Constructs stimuli
     self.stimuli = []
     self.stimuli.append(TextStimulus(
                             0.35*w, 0.45*h,
                             self.df.loc[self.df['phase'] == self.phase].sample(1),
                             c.font_name, int(c.font_size*h)
                             )
                         )
     self.stimuli.append(TextStimulus(
                             0.65*w, 0.45*h,
                             self.df.loc[self.df['phase'] == self.phase].sample(1),
                             c.font_name, int(c.font_size*h)
                             )
                         )
     # Initializes event to change stimuli every n seconds
     self.rate = 1
     self.CHANGE_STIMULI = pygame.USEREVENT + 1
     # Constructs necessary buttons
     self.buttons = []
     self.buttons.append(Button(
                         0.5*w - 0.15*w // 2,
                         0.85*h - 0.15*h // 2, 0.15*w, 0.15*h,
                         on_click=lambda x: self.handle_reinforcement(are_stimuli_equal(iter(self.stimuli),
                                                                                        attr='label'),
                                                                      reinforcement=1)
                                )
                         )
     pygame.time.set_timer(self.CHANGE_STIMULI, int(1000 / self.rate))
     # Finishes initialization
     self.screen.fill(self.bg)
     self.clock = pygame.time.Clock()
     print 'Session started!'
Esempio n. 18
0
 def __init__(self,
              x,
              y,
              w,
              h,
              text,
              on_click=lambda x: None,
              padding=0,
              size=cfg.font_size):
     super().__init__(x, y, w, h)
     self.state = 'normal'
     self.on_click = on_click
     self.text = TextObject(x + padding,
                            y + padding,
                            text,
                            color=cfg.button_text_color,
                            font_size=size)
     self.text_easy = text
Esempio n. 19
0
 def __init__(self,
              x,
              y,
              w,
              h,
              button_color_dict,
              text,
              text_color,
              on_click=lambda x: None,
              key=None):
     GeneralObject.__init__(self, x, y, w, h)
     self.state = 'normal'
     self.button_color_dict = button_color_dict
     self.on_click = on_click
     self.text_color = text_color
     self.key = key
     self.text = TextObject(self.centerx, self.centery, lambda: text,
                            self.text_color, c.button_font_name,
                            c.button_font_size, True)
Esempio n. 20
0
 def __init__(self,
              start_pos_x: int,
              start_pos_y: int,
              char_count: int,
              font_name: str,
              font_size: int,
              bold=False,
              like_column=False):
     velocity_y = 0.5 + random() * 2
     self.charset = [
         TextObject(
             pos_x=start_pos_x,
             pos_y=start_pos_y - (i * font_size),
             text_func=get_random_char,
             color=(224 if i == 1 else 10, 255 + randint(-100, 0), 20),
             font_name=font_name,
             font_size=font_size,
             velocity_y=velocity_y if like_column else random() * 2,
             bold=bold,
         ) for i in range(1, char_count)
     ]
Esempio n. 21
0
 def update(self):
     if not self.game_running:
         return
     if self.finded['finded'] is False:
         if (self.check_saves()):
             if (not self.flag_for_textbox):
                 self.show_message('NEW RECORD!')
                 for y in range(cfg.map_height):
                     for x in range(cfg.map_width):
                         self.objects.remove(self.cubes[y][x])
                 label = TextObject(30, 10, 'INPUT YOUR NICKNAME:')
                 self.objects.append(label)
                 self.make_input()
                 self.flag_for_textbox = True
             if (self.textbox.final == True):
                 nickname = self.textbox.text
                 records = self.remake_saves(nickname)
                 self.rewrite_saves(records)
                 self.game_running = False
                 self.restart()
         else:
             self.show_message('GAME OVER')
             self.restart()
         return
Esempio n. 22
0
 def __init__(self, x, y, w, h, text, button_type):
     super().__init__(x, y, w, h)
     self.type = button_type
     self.text = TextObject(x + 1, y + 10, lambda: text,
                            config.BUTTON_TEXT_COLOR, config.BUTTON_FONT,
                            config.BUTTON_SIZE)
Esempio n. 23
0
 def create_score_label(self):
     self.score_label = TextObject(c.score_offset, c.status_offset_y,
                                   lambda: f'СЧЕТ: {self.score}',
                                   c.text_color, c.font_name, c.font_size)
     self.objects.append(self.score_label)
Esempio n. 24
0
 def draw_victory(self):
     victory_content = TextObject(500, 30, "YOU WON! CONGRATULATIONS!",
                                  c.font_color, c.font_name, c.font_size)
     victory_content.draw(self.surface)