예제 #1
0
def device_choice_screen(_mouse_x, _mouse_y, _ard_conn):
    """Obsługa ekranu z pytaniem czy gra się z urządzeniem do rozdawania kart"""
    deal_with_device = None
    use_device = None
    if _ard_conn is not None:
        use_device = True
    button_yes = Button((0, 255, 255), 375, 300, 100, 60, 'Tak')
    button_no = Button((255, 0, 0), 575, 300, 100, 60, 'Nie')
    button_yes_deal = Button((0, 255, 255), 375, 500, 100, 60, 'Tak')
    button_no_deal = Button((255, 0, 0), 575, 500, 100, 60, 'Nie')
    if button_yes_deal.is_over(_mouse_x, _mouse_y):
        deal_with_device = True
    if button_no_deal.is_over(_mouse_x, _mouse_y):
        deal_with_device = False
    if button_yes.is_over(_mouse_x, _mouse_y):
        screen.fill(bg_green)
        add_text(text_deal_choice, 200, 450)
        button_yes_deal.draw(screen)
        button_no_deal.draw(screen)
        try:
            _ard_conn = ArduinoConnection()
            models = tensorflow_load_models()
            return True, _ard_conn, models, deal_with_device
        except SerialException:
            add_text(text_no_device, 300, 500)
    if button_no.is_over(_mouse_x, _mouse_y):
        screen.fill(bg_green)
        return False, _ard_conn, None, False
    add_text(text_device_choice, 300, 150)
    button_yes.draw(screen)
    button_no.draw(screen)
    return use_device, _ard_conn, None, deal_with_device
예제 #2
0
def draw_auction(_mouse_x, _mouse_y, player_me, my_curr_bid):
    """Obsługa ekranu licytacji"""
    curr_bid = max(game.return_value_of_auction()[0])
    max_bid = max(int(game.count_points(game.get_ownership()) / 10) * 10, 100)
    screen.fill((0, 122, 30))
    add_text('LICYTACJA', 450, 125)
    add_text(f'Obecnie wylicytowano: {curr_bid}', 100, 300)
    button_add = Button((127, 127, 127), 300, 350, 60, 60, '+')
    button_subs = Button((127, 127, 127), 100, 350, 60, 60, '-')

    if button_add.is_over(_mouse_x, _mouse_y):
        my_curr_bid += 10
    if button_subs.is_over(_mouse_x, _mouse_y):
        my_curr_bid -= 10

    my_curr_bid = min(max(100, curr_bid, my_curr_bid), max_bid)

    udpate_my_bid(my_curr_bid)
    button_add.draw(screen)
    button_subs.draw(screen)

    _taken_action = 'wait'
    if max_bid > curr_bid:
        button_bid = Button((127, 127, 127), 500, 350, 120, 60, 'Zalicytuj')
        if button_bid.is_over(_mouse_x, _mouse_y):
            _taken_action = 'bid'
        button_bid.draw(screen)
    button_pass = Button((127, 127, 127), 500, 450, 120, 60, 'Pass')
    if button_pass.is_over(_mouse_x, _mouse_y):
        _taken_action = 'pass'
    button_pass.draw(screen)

    player_me.player_cards(screen, False)

    return _taken_action, my_curr_bid
예제 #3
0
    def __init__(self, score_val, player_name):
        os.environ['SDL_VIDEO_CENTERED'] = '1'
        pygame.init()
        pygame.mouse.set_visible(True)
        self.running = True
        self.screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
        self.gameover_buttons = []
        self.gameover_buttons.append(
            Button('Assets/UI/restart.png', 'Assets/UI/restart_1.png', 206,
                   425, 6))
        self.gameover_buttons.append(
            Button('Assets/UI/home.png', 'Assets/UI/home_1.png', 296, 425, 7))
        self.game_over_font = pygame.font.Font('SigmarOne.ttf', 55)
        self.game_over_tag = self.game_over_font.render(
            "GAME OVER", True, (255, 255, 255))
        self.player_name = player_name

        self.obtained_score_font = pygame.font.Font('SigmarOne.ttf', 30)
        self.obtained_score_tag = self.obtained_score_font.render(
            "SCORE: " + str(score_val), True, (255, 255, 255))
        self.score_tag_rect = self.obtained_score_tag.get_rect()
        self.score_tag_rect.center = (275, 310)
        self.score_tag_rect.y = 320

        # sound effects: MOVE IT TO UTIL FILE LATER
        self.click_sound = pygame.mixer.Sound('Assets/music/clicked.wav')
        self.hover_sound = pygame.mixer.Sound('Assets/music/hover.wav')
        mixer.music.load('Assets/music/game_over_music.wav')
        mixer.music.play()

        # save high score to file and then sort the file
        self.save_score(player_name, score_val)
        sort_file()

        self.game_loop()
예제 #4
0
 def create_buttons(self):
     self.start_button = Button(rect=(STARTBTN_X, BTN_Y2, 100, 50),
                                color=STARTBTNCOL1,
                                hover_color=STARTBTNCOL2,
                                text='Start',
                                function=self.start_button_function)
     self.pause_button = Button(rect=(PAUSEBTN_X, BTN_Y2, 100, 50),
                                color=PAUSEBTNCOL1,
                                hover_color=PAUSEBTNCOL2,
                                text='Pause',
                                function=self.pause_button_function)
     self.next_button = Button(rect=(NEXTBTN_X, BTN_Y2, 100, 50),
                               color=PAUSEBTNCOL1,
                               hover_color=PAUSEBTNCOL2,
                               text='>',
                               function=self.next_button_function)
     self.reset_button = Button(rect=(NEXTBTN_X + 125, BTN_Y2, 100, 50),
                                color=PAUSEBTNCOL1,
                                hover_color=PAUSEBTNCOL2,
                                text='Reset',
                                function=self.reset_button_function)
     self.new_array_button = Button(rect=(NEXTBTN_X + 250, BTN_Y2, 100, 50),
                                    color=PAUSEBTNCOL1,
                                    hover_color=PAUSEBTNCOL2,
                                    text='New Array',
                                    function=self.new_array_function)
예제 #5
0
def load_buttons():
    dummy_file_path = os.path.join(os.getcwd(), "audio", "dummy.wav")
    for idx in range(64):
        file_path = os.path.join(os.getcwd(), "audio", samples_list[idx])
        try:
            buttons[idx] = Button(idx, file_path, False)
        except FileNotFoundError:
            buttons[idx] = Button(idx, dummy_file_path, False)
예제 #6
0
def game_menu(Food_Sound):
    """The Start menu

    Returns:

            bool: True if hit Play button
    """
    start = Button(x=300,
                   y=150,
                   width=200,
                   height=70,
                   real_color=(220, 220, 220),
                   color=(220, 220, 220),
                   hover_color=(0, 255, 255),
                   press_color=(0, 128, 255),
                   text="START")
    end = Button(x=300,
                 y=350,
                 width=200,
                 height=70,
                 real_color=(220, 220, 220),
                 color=(220, 220, 220),
                 hover_color=(0, 255, 255),
                 press_color=(0, 128, 255),
                 text="END")
    sound = Button(x=720, y=520, width=64, height=64)
    sound_state = "play"
    while True:
        WINDOW.blit(BACKGROUND, (0, 0))
        start.draw(WINDOW, (0, 0, 0))
        end.draw(WINDOW, (0, 0, 0))
        if sound_state == "play":
            WINDOW.blit(PLAY_BUTTON, (720, 520))
        elif sound_state == "pause":
            WINDOW.blit(PAUSE_BUTTON, (720, 520))
        for event in pygame.event.get():
            # WINDOW.blit(BACKGROUND, (0,0))
            pos = pygame.mouse.get_pos()
            if event.type == pygame.QUIT:
                pygame.quit()
                exit()
            if start.main_loop(event, pos):
                return True
            elif end.main_loop(event, pos):
                pygame.quit()
                exit()
            elif sound.clicked(event, pos):
                if sound_state == "play":
                    sound_state = "pause"
                    pygame.mixer.music.pause()
                    EXPLOSION_SOUND.set_volume(0)
                    FOOD_SOUND.set_volume(0)
                elif sound_state == "pause":
                    sound_state = "play"
                    pygame.mixer.music.unpause()
                    EXPLOSION_SOUND.set_volume(1)
                    FOOD_SOUND.set_volume(1)
        pygame.display.update()
예제 #7
0
    def main_menu(self):
        # Create text
        self.intro_text = self.font.render("Snake", True, BLACK)
        self.intro_text_pos = self.intro_text.get_rect()
        self.intro_text_pos.center = ((self.screen_width / 2),
                                      (self.screen_height / 4))

        # Create buttons
        start_button = Button(self.screen, self.font, "Start Game", BLACK,
                              DARK_GREEN, self.intro_text_pos.centerx,
                              self.intro_text_pos.centery + 200)
        start_button.add_paddings(BUTTON_PADX, BUTTON_PADY)

        quit_button = Button(self.screen, self.font, "Quit", BLACK, DARK_RED,
                             self.intro_text_pos.centerx,
                             self.intro_text_pos.centery + 350)
        quit_button.add_paddings(BUTTON_PADX, BUTTON_PADY)

        walls_toggle_button = ToggleButton(self.walls_toggle, self.screen,
                                           self.toggle_font, "Walls: On",
                                           BLACK, DARK_GREEN,
                                           self.intro_text_pos.centerx,
                                           self.intro_text_pos.centery + 100)
        walls_toggle_button.add_paddings(BUTTON_PADX, BUTTON_PADY)
        walls_toggle_button.set_toggle("Walls: On", GREEN, "Walls: Off", RED)

        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.quit()

            self.screen.fill(WHITE)

            # Get mouse action
            mouse_pos = pygame.mouse.get_pos()
            mouse_click = pygame.mouse.get_pressed()

            start_button.mouse_handler(mouse_pos, [mouse_click[0]], True,
                                       GREEN, self.run)
            quit_button.mouse_handler(mouse_pos, [mouse_click[0]], True, RED,
                                      self.quit)

            def walls_switch():
                self.walls_toggle = not self.walls_toggle

            walls_toggle_button.mouse_handler(mouse_pos, [mouse_click[0]],
                                              True, GREEN, walls_switch)

            # Draw text
            self.screen.blit(self.intro_text, self.intro_text_pos)

            # Draw buttons
            start_button.draw()
            quit_button.draw()
            walls_toggle_button.draw()

            pygame.display.update()
            self.clock.tick(FRAMERATE)
예제 #8
0
 def __init__(self):
     pyxel.init(180, 120, caption="Keymusic Py", scale=4)
     self.keys = [
         Button([11, 3], [20, 100], 4, [0, 1, "A2"], pyxel.KEY_A),
         Button([10, 9], [40, 100], 4, [1, 2, "B2"], pyxel.KEY_S),
         Button([12, 5], [60, 100], 4, [2, 3, "C2"], pyxel.KEY_F),
         Button([15, 14], [80, 100], 4, [3, 4, "D2"], pyxel.KEY_G),
     ]
     pyxel.run(self.update, self.draw)
예제 #9
0
    def init_ui(self):
        """Create local components"""
        self.glayout = QGridLayout()  # main Grid Layout
        self.vlayout = QVBoxLayout()  # WebView Layout
        self.hlayout = QHBoxLayout()  # additional buttons
        self.webview = QWebEngineView()  # WebView object
        self.webview.load(
            QUrl("http://www.youtube.com/embed/hI9GyhX7yHM?rel"
                 "=0&modestbranding=0&autohide=1&mute=0&showinfo"
                 "=0&controls=1&autoplay=1"))  # default url
        # refresh button
        self.btn_size = QSize(16, 16)
        refresh = Button()
        refresh.setEnabled(False)
        refresh.setFixedWidth(24)
        refresh.setToolTip('Refresh')
        refresh.setStatusTip('Refresh')
        icon = QIcon()
        path = os.path.join(os.path.dirname(__file__), "Icons")
        icon.addPixmap(QPixmap(os.path.join(path, "refresh-24.png")))
        icon.addPixmap(QPixmap(os.path.join(path, "cancel-24.png")),
                       QIcon.Disabled)
        refresh.setIcon(icon)
        refresh.clicked.connect(self.refresh)
        refresh.setCursor(QCursor(Qt.PointingHandCursor))
        self.rfresh = refresh

        # Stream button
        stream = Button()
        stream.setFixedWidth(24)
        stream.setToolTip("Stream video")
        stream.setStatusTip("Stream video")
        stream.setIconSize(self.btn_size)
        stream.setIcon(QIcon(os.path.join(path, 'streaming-media-30.png')))
        stream.clicked.connect(self.search)
        stream.setCursor(QCursor(Qt.PointingHandCursor))

        btns_widget = QWidget()
        self.hlayout.addWidget(self.rfresh, 0)
        self.hlayout.addWidget(stream, 1)
        btns_widget.setLayout(self.hlayout)
        btns_widget.setFixedWidth(330)

        self.vlayout.addWidget(self.webview)
        self.vlayout.setAlignment(Qt.AlignTop)
        self.setLayout(self.glayout)
        self.glayout.addLayout(self.vlayout, 0, 0)
        self.add_scroll_box()
        self.glayout.addWidget(btns_widget, 1, 1)
        QShortcut(
            QKeySequence(Qt.Key_Space),  # Space key responds to None
            self,
            lambda: None,
            context=Qt.ApplicationShortcut)
예제 #10
0
파일: main.py 프로젝트: uhalid/Path-Finding
    def draw_ui(self):
        self.buttons = []
        astar_button = Button(0, 3, 40, 100, DISPLAY, WHITE,
                      (150, 150, 150), "RUN A*", self.handle_astar, 25)
        dijkstra_button = Button(WIDTH-153, 3, 40, 150, DISPLAY, WHITE,
                      (150, 150, 150), "RUN DIJKSTRA", self.handle_dijkstra, 25)

        # self.buttons.append(astar_button, dijkstra_button)
        self.buttons.extend((astar_button, dijkstra_button))
        for button in self.buttons:
            button.create()
예제 #11
0
 def init_buttons(self):
     self.all_buttons.append(
         Button('Assets/UI/play.png', 'Assets/UI/play_1.png', 175, 250, 1))
     self.all_buttons.append(
         Button('Assets/UI/options.png', 'Assets/UI/options_1.png', 150,
                500, 2))
     self.all_buttons.append(
         Button('Assets/UI/highscore.png', 'Assets/UI/highscore_1.png', 150,
                600, 3))
     self.all_buttons.append(
         Button('Assets/UI/exit.png', 'Assets/UI/exit_1.png', 150, 700, 4))
예제 #12
0
    def game_end(self):
        # Create text
        self.endgame_text = self.font.render(
            "Game Over! Score is {}".format(self.score), True, BLACK)
        self.endgame_text_pos = self.endgame_text.get_rect()
        self.endgame_text_pos.center = ((self.screen_width / 2),
                                        (self.screen_height / 4))

        # Create buttons
        try_again_button = Button(self.screen, self.font, "Try Again", BLACK,
                                  DARK_GREEN, self.endgame_text_pos.centerx,
                                  self.endgame_text_pos.centery + 150)
        try_again_button.add_paddings(BUTTON_PADX, BUTTON_PADY)

        quit_button = Button(self.screen, self.font, "Quit", BLACK, DARK_RED,
                             self.endgame_text_pos.centerx,
                             self.endgame_text_pos.centery + 350)
        quit_button.add_paddings(BUTTON_PADX, BUTTON_PADY)

        back_menu_button = Button(self.screen, self.font, "Back to Main Menu",
                                  BLACK, DARK_BLUE,
                                  self.endgame_text_pos.centerx,
                                  self.endgame_text_pos.centery + 250)
        back_menu_button.add_paddings(BUTTON_PADX, BUTTON_PADY)

        end = True
        while end:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.quit()

            self.screen.fill(WHITE)

            mouse_pos = pygame.mouse.get_pos()
            mouse_click = pygame.mouse.get_pressed()

            try_again_button.mouse_handler(mouse_pos, [mouse_click[0]], True,
                                           GREEN, self.run)
            back_menu_button.mouse_handler(mouse_pos, [mouse_click[0]], True,
                                           BLUE, self.main_menu)
            quit_button.mouse_handler(mouse_pos, [mouse_click[0]], True, RED,
                                      self.quit)

            # Draw text
            self.screen.blit(self.endgame_text, self.endgame_text_pos)

            # Draw buttons
            try_again_button.draw()
            back_menu_button.draw()
            quit_button.draw()

            pygame.display.update()
            self.clock.tick(FRAMERATE)
예제 #13
0
def lose():
    global lang, die
    running = True
    die = True
    fon = pygame.transform.scale(load_image('game_over.png'), (width, height))
    button_group_lose = pygame.sprite.Group()
    screen.blit(fon, (0, 0))
    w = 150
    h = 50
    if lang == 'ru':
        cancel = Button(button_group_lose, (0, 0, w, h), screen, 'МЕНЮ', menu)
        results = Button(button_group_lose, (width - w, 0, w, h), screen, 'ЛИДЕРЫ', finish)
    elif lang == 'eng':
        cancel = Button(button_group_lose, (0, 0, w, h), screen, 'MENU', menu)
        results = Button(button_group_lose, (width - w, 0, w, h), screen, 'RECORDS', finish)
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                terminate()
            if event.type == pygame.MOUSEMOTION:
                pos = event.pos
                if cancel.coords[0] <= pos[0] <= cancel.coords[0] + w and cancel.coords[1] <= pos[
                    1] <= \
                        cancel.coords[1] + h:
                    cancel.mouse_down = True
                else:
                    cancel.mouse_down = False
                if results.coords[0] <= pos[0] <= results.coords[0] + w and results.coords[1] <= pos[
                    1] <= \
                        results.coords[1] + h:
                    results.mouse_down = True
                else:
                    results.mouse_down = False
            if event.type == pygame.MOUSEBUTTONDOWN:
                pos = event.pos
                if cancel.coords[0] <= pos[0] <= cancel.coords[0] + w and cancel.coords[1] <= pos[
                    1] <= \
                        cancel.coords[1] + h:
                    return MENU
                if results.coords[0] <= pos[0] <= results.coords[0] + w and results.coords[1] <= pos[
                    1] <= \
                        results.coords[1] + h:
                    return RESULTS
        keys = pygame.key.get_pressed()
        if keys[pygame.K_ESCAPE]:
            return EXIT
        clock.tick(FPS)
        button_group_lose.update()
        pygame.display.flip()
    pygame.quit()
예제 #14
0
    def __init__(self, x, y, identity):
        self.pieces = 0
        self.color = ""
        self.identity = identity
        self.x = x
        self.y = y

        if 24 > identity > 11:
            self.button = Button(x, 500, 56, 383)
        else:
            if identity == 24 or identity == 25:
                self.button = Button(x, y, 56, 383)
            else:
                self.button = Button(x, y, 900 - x, 900 - y)
예제 #15
0
    def __init__(self):
        self.screen = pygame.display.set_mode((WIDTH, HEIGHT))
        self.clock = pygame.time.Clock()
        self.running = True
        self.state = 'main menu'
        self.algorithm_state = ''
        self.grid_square_length = 24
        # self.load()
        self.start_end_checker = 0
        self.mouse_drag = 0

        # start and end nodes coordinates
        self.start_node_x = None
        self.start_node_y = None
        self.end_node_x = None
        self.end_node_y = None

        # wall nodes list
        self.wall_pos = wall_nodes_coords_list.copy()

        # main menu buttons
        self.bfs_button = Button(self, WHITE, 338, MAIN_BUTTON_Y_POS,
                                 MAIN_BUTTON_LENGTH, MAIN_BUTTON_HEIGHT, 'BFS')
        self.dfs_button = Button(self, WHITE, 558, MAIN_BUTTON_Y_POS,
                                 MAIN_BUTTON_LENGTH, MAIN_BUTTON_HEIGHT, 'DFS')
        self.astar_button = Button(self, WHITE, 778, MAIN_BUTTON_Y_POS,
                                   MAIN_BUTTON_LENGTH, MAIN_BUTTON_HEIGHT,
                                   'Astar')
        self.dijkstra_button = Button(self, WHITE, 998, MAIN_BUTTON_Y_POS,
                                      MAIN_BUTTON_LENGTH, MAIN_BUTTON_HEIGHT,
                                      'Dijkstra')

        # grid menu options
        self.start_end_node_button = Button(self, AQUAMARINE, 20,
                                            START_END_BUTTON_HEIGHT,
                                            GRID_BUTTON_LENGTH,
                                            GRID_BUTTON_HEIGHT,
                                            'Start/End Node')
        self.wall_node_button = Button(
            self, AQUAMARINE, 20,
            START_END_BUTTON_HEIGHT + GRID_BUTTON_HEIGHT + BUTTON_SPACER,
            GRID_BUTTON_LENGTH, GRID_BUTTON_HEIGHT, 'Wall Node')
        self.reset_button = Button(
            self, AQUAMARINE, 20, START_END_BUTTON_HEIGHT +
            GRID_BUTTON_HEIGHT * 2 + BUTTON_SPACER * 2, GRID_BUTTON_LENGTH,
            GRID_BUTTON_HEIGHT, 'RESET')
        self.start_button = Button(
            self, AQUAMARINE, 20, START_END_BUTTON_HEIGHT +
            GRID_BUTTON_HEIGHT * 3 + BUTTON_SPACER * 3, GRID_BUTTON_LENGTH,
            GRID_BUTTON_HEIGHT, 'Visualize')
        self.main_menu_button = Button(
            self, AQUAMARINE, 20, START_END_BUTTON_HEIGHT +
            GRID_BUTTON_HEIGHT * 4 + BUTTON_SPACER * 4, GRID_BUTTON_LENGTH,
            GRID_BUTTON_HEIGHT, 'Main Menu')
예제 #16
0
 def mainmenu(self):
     screen = pygame.display.set_mode(self.size)
     but_in_menu = []
     continue_but = Button('Продолжить', self.offset, self.titlspace)
     but_in_menu.append(continue_but)
     new_g_but = Button('Новая игра', self.offset,
                        self.titlspace + self.space)
     but_in_menu.append(new_g_but)
     ach_but = Button('Достижения', self.offset,
                      self.titlspace + self.space * 2)
     but_in_menu.append(ach_but)
     pre_but = Button('Предыстория', self.offset,
                      self.titlspace + self.space * 3)
     but_in_menu.append(pre_but)
     exit_but = Button('Выход', self.offset,
                       self.titlspace + self.space * 4)
     but_in_menu.append(exit_but)
     header = load_image('bigpic', 'title.png')
     while self.run:
         screen.fill(self.clr)
         screen.blit(header, (self.offset - 20, 11))
         for event in pygame.event.get():
             if event.type == pygame.QUIT:
                 self.run = False
                 terminate()
             if event.type == pygame.MOUSEMOTION:
                 for i in but_in_menu:
                     pos = pygame.mouse.get_pos()
                     i.set_hov(i.onclick(pos))
             elif event.type == pygame.MOUSEBUTTONDOWN:
                 pos = pygame.mouse.get_pos()
                 if continue_but.onclick(pos):  # Проверка нажатия
                     self.run = False
                     return 'continue'
                 if new_g_but.onclick(pos):
                     self.run = False
                     return 'new game'
                 if ach_but.onclick(pos):
                     self.run = False
                     return 'achievements'
                 if pre_but.onclick(pos):
                     Prologue().tellstory()
                 if exit_but.onclick(pos):
                     self.run = False
                     return 'termination'
         for i in but_in_menu:
             i.draw(screen)
         pygame.display.flip()
예제 #17
0
 def get_search_actions(self, resource, context):
     search_button = Button(access=True,
                            resource=resource,
                            context=context,
                            css='button-search',
                            title=MSG(u'Search'))
     return [search_button]
예제 #18
0
 def add_buttons(cls, *button_ids):
     for button in button_ids:
         cls.buttons[button] = Button(button,
                                       cls.button_blank,
                                       (0, 0),
                                       button)
         print(cls.buttons)
예제 #19
0
 def __init__(self):
     self.size = self.width, self.height = 640, 640
     self.fill_clr = pygame.Color(0, 97, 100)
     self.txt_clr = pygame.Color(255, 255, 255)
     self.watch = True
     self.b_w, self.b_h = 128, 50
     self.back_button = Button('Назад', 24, 24, self.b_w, self.b_h)
     self.offset, self.ac_hei, self.leng = 60, 80, 500
     self.aff_one = 100
     ach_cod = []
     self.score = 0
     self.real_got = []
     with open("dostig.txt", encoding="utf-8") as ac:
         ach_cod = str(ac.read())  # чтение из файла сохранения
         ach_cod = ach_cod.split(',')
     for i in range(1, len(ach_cod)):  # Вывод достижений
         if ach_cod[i] == 'T':
             if i == 1:
                 self.real_got.append('Начало положено. '
                                      '(Запустить игру, +10)')
                 self.score += 10
             if i == 2:
                 self.real_got.append('Путь к развитию. '
                                      '(Получена неплохая концовка, +150)')
                 self.score += 150
             if i == 3:
                 self.real_got.append('Восход. '
                                      '(Получена лучшая концовка, +300)')
                 self.score += 300
             if i == 4:
                 self.real_got.append('Пучина греха. '
                                      '(Получена худшая концовка, +100)')
                 self.score += 100
예제 #20
0
 def __init__(self):
     pygame.init()
     self.player = Player(settings.screen, self)
     self.ball = Ball(settings.screen, self.player)
     self.go_button = Button(settings.screen)
     self.go = False
     self.level = settings.get_level()[0]
예제 #21
0
    def __init__(self, player_name):
        #  declare variables for UI navigation
        # load UI images and background images

        os.environ['SDL_VIDEO_CENTERED'] = '1'
        pygame.init()
        self.screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
        self.player_name = player_name
        self.running = True
        self.start_img = load_image('Assets/background/start.png')
        self.instructions_img = load_image(
            'Assets/background/instructions.png')
        self.instruction_window = False
        self.all_buttons = []
        self.next_button = []
        self.next_button.append(
            Button('Assets/UI/next.png', 'Assets/UI/next_1.png', 476, 775, 5))
        self.init_buttons()

        # sound effects
        self.click_sound = pygame.mixer.Sound('Assets/music/clicked.wav')
        self.hover_sound = pygame.mixer.Sound('Assets/music/hover.wav')

        # fonts to display player name
        font = pygame.font.Font('SigmarOne.ttf', 20)
        self.player_name_tag = font.render(self.player_name, True,
                                           (255, 255, 255))

        self.game_loop()
예제 #22
0
    def __init__(self):
        """Initialize the game, and create game ressources."""
        pygame.init()
        self.settings = Settings()
        self.clock = pygame.time.Clock()

        # # Switch the comments on these blocks for fullscreen or window screen
        # self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        # self.settings.screen_width = self.screen.get_rect().width
        # self.settings.screen_height = self.screen.get_rect().height

        self.screen = pygame.display.set_mode(
            (self.settings.screen_width, self.settings.screen_height))
        pygame.display.set_caption('COVID Invasion')

        # Create an instance to store game statistics
        #   and create a scoreboard
        self.stats = GameStats(self)
        self.scoreboard = Scoreboard(self)

        self.ship = Ship(self)
        self.bullets = pygame.sprite.Group()
        self.aliens = pygame.sprite.Group()

        self._create_fleet()

        self.play_button = Button(self, 'Play')
예제 #23
0
    def __init__(self):
        """Initialise the game, and create game resources"""
        pygame.init(
        )  #This initialises background settings that Pygame needs to work properly
        self.settings = Settings()

        #self.screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN) These settings are for fullscreen mode
        #self.settings.screen_width = self.screen.get_rect().width        but have been commented out as i prefer
        #self.settings.screen_height = self.screen.get_rect().height       windowed mode

        self.screen = pygame.display.set_mode(
            (self.settings.screen_width, self.settings.screen_height
             ))  #This creates a display window for the game
        pygame.display.set_caption("Alien Invasion")

        #Create an instance to store game statistics
        #  and create a scoreboard
        self.stats = GameStats(self)
        self.sb = Scoreboard(self)

        self.ship = Ship(self)  #Make an instance of ship
        self.bullets = pygame.sprite.Group()
        self.aliens = pygame.sprite.Group()

        self._create_fleet()  #This is a group for the fleet of aliens

        #Make play button
        self.play_button = Button(self, "Play")

        #Set the background colour
        self.bg_colour = (
            230, 230, 230
        )  #Colours defined by a mix of RGB this mixes equal of all
예제 #24
0
class AcceptInvitation(ConfirmSubscription):

    title = MSG(u"Invitation")
    description = MSG(
        u'By accepting the invitation you will receive an email every time'
        u' this resource is modified.')
    actions = [Button(access=True, title=MSG(u'Accept invitation'))]
예제 #25
0
def run_game():
    # Initialize pygame, settings, and screen object.
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("almykivasion!!!")

    play_button = Button(ai_settings, screen, "Play")

    # Create an instance to store game statistics and create a scoreboard.
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)

    # Make a ship, a group of bullets, and a group of aliens.
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    gf = GameFunctions(ai_settings, screen, stats, sb, ship, aliens, bullets,
                       play_button)

    # Create the fleet of aliens.
    gf.create_fleet()

    # Start the main loop for the game.
    while True:
        gf.check_events()

        if stats.game_active:
            ship.update()
            gf.update_bullets()
            gf.update_aliens()

        gf.update_screen()
예제 #26
0
 def __init__(self, button_pin, event_start, event_stop,
              white_lamp_controller, semaphore_mode):
     Thread.__init__(self)
     self.button = Button(button_pin)
     self.event_start = event_start
     self.event_stop = event_stop
     self.white_lamp_controller = white_lamp_controller
     self.semaphore_mode = semaphore_mode
예제 #27
0
def main():
    pg.font.init()
    pg.display.set_caption("Sudoku by Hategan Florin")

    game = Game(my_board, 3, pg.Color('black'), 55)
    disp = Display(game, 550, 750, 10, pg.Color('white'))

    running = True

    buttons = []

    start_button = Button(pg.Color('green'), pg.Color('white'), 100, 600, 70,
                          30, 'Start')

    quit_button = Button(pg.Color('blue'), pg.Color('white'), 300, 600, 70, 30,
                         'Quit')

    buttons.append(start_button)
    buttons.append(quit_button)

    while running:
        for event in pg.event.get():
            pos = pg.mouse.get_pos()

            if event.type == pg.QUIT:
                running = False

            if event.type == pg.KEYDOWN:
                if event.key == pg.K_SPACE:
                    disp.game.resolve_sudoku(disp.screen, disp.draw_screen)

            if event.type == pg.MOUSEBUTTONDOWN:
                if quit_button.isOver(pos):
                    running = False
                if start_button.isOver(pos):
                    running = False

            if event.type == pg.MOUSEMOTION:
                for button in buttons:
                    button.isOver(pos)

        disp.draw_screen()
        for button in buttons:
            button.draw(disp.screen, pg.Color('black'))
        pg.display.update()
예제 #28
0
class StartScreen(GameState):
    """State to handle update and and render logic when the
        start screen is active
    """

    bgr = pygame.image.load(os.path.join(constants.ASSETS, 'start_screen_bgr.png'))
    buttons = {}
    buttons['play'] = Button('play_button', 
                             pygame.image.load(os.path.join(constants.ASSETS, 'play_button.png')))
    visibles = []
    switch_to_states = []


    @classmethod
    def __init__(cls):
        cls.buttons['play'].pos = [((constants.screen_width / 2) 
                                     - (cls.buttons['play'].sprite.get_width() / 2)),
                                    (constants.screen_height / 2)]
        cls.buttons['play'].rect = pygame.Rect(cls.buttons['play'].pos,
                                               (cls.buttons['play'].rect.width,
                                                cls.buttons['play'].rect.height))
        asdf = [cls.buttons['play'].sprite, cls.buttons['play'].pos]
        cls.visibles.append(asdf)

    @classmethod
    def update(cls):
        cls.switch_to_states = []

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False
                pygame.display.quit()
                raise SystemExit

            # Check if a button has been clicked            
            if event.type == pygame.MOUSEBUTTONDOWN:
                pos = pygame.mouse.get_pos()
                for button in cls.buttons.values():
                    if button.rect.collidepoint(pos):
                        print(button.id)
                        if button.id == 'play_button':
                            #cls.switch_to_states.append('roster_edit')
                            return 'roster_edit'
                    else:
                        print("not clicked")            

    @classmethod
    def draw(cls, game_win):
        game_win.blit(cls.bgr, (0, 0))

        for i in cls.visibles:
            game_win.blit(i[0], i[1])

    @classmethod
    def on_enter(cls):
        pass        
예제 #29
0
def draw_room_buttons(list_of_empty_buttons, list_of_hosted_buttons):
    screen.fill(bg_green)
    _list_of_empty_rooms = game.select_empty_rooms()
    _list_of_hosted_rooms = game.select_started_rooms()
    y = -90
    for room in _list_of_empty_rooms:
        room_text = f'Pokój nr {str(room[0])}'
        y += 100
        button = Button((255, 0, 0), 300, y, 100, 60, room_text)
        button.draw(screen)
        list_of_empty_buttons.append(button)
    y = -90
    for room in _list_of_hosted_rooms:
        room_text = f'Pokój nr {str(room[0])}'
        y += 100
        button = Button((255, 255, 0), 500, y, 100, 60, room_text)
        button.draw(screen)
        list_of_hosted_buttons.append(button)
    return list_of_empty_buttons, list_of_hosted_buttons
예제 #30
0
 def set_roster_buttons(cls):
     """Creates buttons for each creature in the player's roster
     """
     i = 0
     for name in player.player1.roster_ids:
         cls.roster_buttons.append(Button(name,
                                          player.player1.get_roster_thumbs(name),
                                          pos=cls.thumb_positions[i],
                                          text=name))
         i += 1