예제 #1
0
def draw_stat(lst, lst1):  # вывод стат
    dop_func.print_text(screen,
                        lst[0],
                        lst1[1][0] + WIDTH // 20,
                        lst1[1][1] + HEIGHT // 6,
                        font_size=25,
                        color='black',
                        font_type='stat.ttf')
    dop_func.print_text(screen,
                        f'Hit Point {lst[1]}',
                        lst1[1][0] + WIDTH // 20,
                        lst1[1][1] + HEIGHT // 6 + 35,
                        font_size=25,
                        color='black',
                        font_type='stat.ttf')
    dop_func.print_text(screen,
                        f'Damage {lst[2]}',
                        lst1[1][0] + WIDTH // 20,
                        lst1[1][1] + HEIGHT // 6 + 70,
                        font_size=25,
                        color='black',
                        font_type='stat.ttf')
    dop_func.print_text(screen,
                        f'Armour {lst[3]}',
                        lst1[1][0] + WIDTH // 20,
                        lst1[1][1] + HEIGHT // 6 + 105,
                        font_size=25,
                        color='black',
                        font_type='stat.ttf')
    dop_func.print_text(screen,
                        f'{lst[4]}',
                        lst1[1][0] + WIDTH // 20,
                        lst1[1][1] + HEIGHT // 6 + 140,
                        font_size=25,
                        color='black',
                        font_type='stat.ttf')
def congratulations(flag):  # выводит результат битвы
    fon = pygame.transform.scale(dop_func.load_image('battle_fon.jpg'),
                                 (WIDTH, HEIGHT))
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                dop_func.terminate()
            if event.type == pygame.MOUSEBUTTONDOWN:
                return
        screen.blit(fon, (0, 0))
        if flag is None:
            dop_func.print_text(screen, "Игра завершена",
                                WIDTH // 2 - WIDTH // 13,
                                HEIGHT // 2 - HEIGHT // 15)
        elif flag:
            dop_func.print_text(screen, "Вы победили",
                                WIDTH // 2 - WIDTH // 13,
                                HEIGHT // 2 - HEIGHT // 15)
        else:
            dop_func.print_text(screen, "Вы проиграли",
                                WIDTH // 2 - WIDTH // 13,
                                HEIGHT // 2 - HEIGHT // 15)
        pygame.display.flip()
예제 #3
0
 def draw(self,
          x,
          y,
          text,
          action=None,
          param_action=None,
          color='white'):  # рисует кнопку
     mouse = pygame.mouse.get_pos()
     click = pygame.mouse.get_pressed()
     naved = pygame.mixer.Sound('data/naved.wav')
     if x < mouse[0] < x + self.width and y < mouse[1] < y + self.height:
         pygame.draw.rect(screen, self.active_color,
                          (x, y, self.width, self.height))
         global flag_click
         if click[0] == 1:
             pygame.mixer.Sound.play(naved)
             pygame.time.delay(300)
             if action is not None:
                 if action == quit:
                     pygame.quit()
                     quit()
                 elif action == 'battle':
                     param_action.next()
                 elif action == 'set_captain':
                     set_captain(param_action[0], param_action[1])
                 elif action == 'return':
                     self.action = True
                     mainField.pause(True)
                 elif action == dop_func.save_game:
                     dop_func.save_game(param_action)
                     self.action = True
                     mainField.pause(True)
                 elif action == 'change_hero':
                     flag_click[0] = True
                     if flag_click[0] and flag_click[1]:
                         mainField.change_hero(param_action, flag_click[2])
                         flag_click = [False, False, None]
                     else:
                         flag_click = [True, False, param_action]
                 elif action == 'change':
                     flag_click[1] = True
                     if flag_click[0] and flag_click[1]:
                         mainField.change_hero(flag_click[2], param_action)
                         flag_click = [False, False, None]
                     else:
                         flag_click = [False, True, param_action]
                 elif action == 'quit':
                     self.action = True
                 else:
                     if param_action:
                         action(param_action)
                         return
                     action()
                     return
     else:
         pygame.draw.rect(screen, self.inactive_color,
                          (x, y, self.width, self.height))
     dop_func.print_text(screen,
                         text,
                         x + 10,
                         y + 15,
                         font_size=self.text_size,
                         font_type=self.font_type,
                         color=color)
예제 #4
0
def choose_captain(
        LEVEL=1
):  # выбор капитана, очень много костылей, лучше не смотреть код
    background = pygame.transform.scale(dop_func.load_image(f'board.jpg'),
                                        (WIDTH, HEIGHT))
    heroes = set()
    while len(heroes) != 5:
        hero = database.take_hero()
        if hero[0] in database.TAKED_HERO or hero[0] in list(
                map(lambda x: x.name, defaultUnit.groupMain.get_lst())):
            continue
        heroes.add(hero)
    heroes = list(heroes)
    image0 = pygame.transform.scale(
        dop_func.load_image("heroes/" + heroes[0][-1]),
        (5 * WIDTH // 26, HEIGHT // 2))
    image1 = pygame.transform.scale(
        dop_func.load_image("heroes/" + heroes[1][-1]),
        (5 * WIDTH // 26, HEIGHT // 2))
    image2 = pygame.transform.scale(
        dop_func.load_image("heroes/" + heroes[2][-1]),
        (5 * WIDTH // 26, HEIGHT // 2))
    image3 = pygame.transform.scale(
        dop_func.load_image("heroes/" + heroes[3][-1]),
        (5 * WIDTH // 26, HEIGHT // 2))
    image4 = pygame.transform.scale(
        dop_func.load_image("heroes/" + heroes[4][-1]),
        (5 * WIDTH // 26, HEIGHT // 2))
    dct_names = {
        0: [heroes[0][0]],
        1: [heroes[1][0]],
        2: [heroes[2][0]],
        3: [heroes[3][0]],
        4: [heroes[4][0]]
    }
    choose = Button(185, 65, text_size=30)
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                dop_func.terminate()
        screen.fill((255, 255, 255))
        dop_func.print_text(screen,
                            'Выберите героя', (2 * WIDTH) // 6,
                            HEIGHT // 8,
                            color='black')
        for i in range(0, 5):
            choose.draw(3 * WIDTH // 30 + i * WIDTH // 6, 3 * HEIGHT // 4,
                        "Выбрать", "set_captain", (dct_names[i][0], LEVEL))
            if len(dct_names[i]) == 1:
                dct_names[i] = [
                    dct_names[i][0],
                    (3 * WIDTH // 50 + 8 * i * image0.get_width() // 9,
                     HEIGHT // 5),
                    (3 * WIDTH // 50 + 8 * i * image0.get_width() // 9 +
                     image0.get_width(), HEIGHT // 5 + HEIGHT // 2), False
                ]
            if dct_names[i][-1] is False:
                dct_names[i] = [
                    dct_names[i][0],
                    (3 * WIDTH // 50 + 8 * i * image0.get_width() // 9,
                     HEIGHT // 5),
                    (3 * WIDTH // 50 + 8 * i * image0.get_width() // 9 +
                     image0.get_width(), HEIGHT // 5 + HEIGHT // 2), False
                ]
                screen.blit(locals()['image%s' % i],
                            (3 * WIDTH // 50 + 8 * i * image0.get_width() // 9,
                             HEIGHT // 5))
            else:
                dct_names[i] = [
                    dct_names[i][0],
                    (3 * WIDTH // 50 + 8 * i * image0.get_width() // 9,
                     HEIGHT // 5),
                    (3 * WIDTH // 50 + 8 * i * image0.get_width() // 9 +
                     image0.get_width(), HEIGHT // 5 + HEIGHT // 2), True
                ]
                draw_stat(heroes[i], dct_names[i])
            if dct_names[i][1][0] <= pygame.mouse.get_pos()[0] <= dct_names[i][2][0] and\
                    dct_names[i][1][1] <= pygame.mouse.get_pos()[1] <= dct_names[i][2][1] and pygame.mouse.get_pressed()[0]:
                dct_names[i][-1] = not dct_names[i][-1]
        pygame.display.flip()
        clock.tick(FPS)
def run_cycle(captain_name, LEVEL=1, planets=None):  # основной цикл
    if len(groupMain.lst) != LEVEL and LEVEL < 6:
        groupMain.lst.clear()
    if groupMain.lst == list():
        name, hp, damage, armour, bonus_hp, bonus_damage, bonus_armour, photo = list(
            database.full_hero(captain_name))
        hero = defaultUnit.HeroUnit(name, hp, damage, armour, groupMain,
                                    bonus_hp, bonus_damage, bonus_armour,
                                    photo)
        groupMain.append_hero(hero)

    board = Board(16, 8)
    global lst_planet, lvl
    if planets:
        lst_planet = planets
    else:
        lst_planet = [
            Planet(i[0], i[1], i[2], LEVEL)
            for i in database.take_planet(LEVEL)
        ]
    lvl = LEVEL
    cell_s = WIDTH // 16 - 1
    board.set_view((WIDTH - cell_s * 16) // 2, (HEIGHT - cell_s * 8) // 2,
                   WIDTH // 16 - 1)
    fon = pygame.transform.scale(dop_func.load_image('Space.jpg'),
                                 (WIDTH, HEIGHT))
    flag = True
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                dop_func.terminate()
            if event.type == pygame.MOUSEBUTTONDOWN:
                cell = board.get_cell(event.pos)
                if cell is None:
                    break
                x, y = cell

                if x == 15 and y == 7:
                    if LEVEL < 8:
                        stat = True
                        for i in lst_planet:
                            if not i.get_status():
                                stat = False
                        if stat:
                            return mainMenu.choose_captain(LEVEL + 1)
                    else:
                        congratulations(None)
                    break
                flag = True
                for i in range(len(lst_planet)):
                    if lst_planet[i].x == x and lst_planet[i].y == y:
                        if lst_planet[i].get_status() is False:
                            board.get_click(event.pos)
                            if battleUI(lst_planet[i]):
                                lst_planet[i].set_status(True)
                                congratulations(True)
                            else:
                                congratulations(False)
                        else:
                            flag = False
                            break
                if flag:
                    board.get_click(event.pos)
            if event.type == pygame.KEYDOWN and event.key == 27:
                pause()
        screen.blit(fon, (0, 0))
        draw_level(LEVEL, board)
        board.render()
        if flag is False:
            dop_func.print_text(screen, 'Планета уже захвачена',
                                WIDTH // 2 - WIDTH // 5,
                                HEIGHT // 2 - HEIGHT // 20)
        pygame.display.flip()
def change():  # вывод окна команды
    pers = mainMenu.Button(250,
                           75,
                           text_size=30,
                           inactive_color=(255, 255, 255),
                           active_color=(255, 255, 255),
                           font_type='stat.ttf')
    stock = mainMenu.Button(250,
                            75,
                            text_size=30,
                            inactive_color=(255, 255, 255),
                            active_color=(255, 255, 255),
                            font_type='stat.ttf')
    quit = mainMenu.Button(225, 75)
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                dop_func.terminate()
            if event.type == pygame.MOUSEBUTTONDOWN:
                x, y = event.pos
                if x in range(int(WIDTH // 2 - quit.width // 2),
                              int(WIDTH // 2 + quit.width // 2)):
                    if y in range(int(HEIGHT // 2 + HEIGHT // 3),
                                  (HEIGHT // 2 + HEIGHT // 3 + quit.height)):
                        quit.draw(WIDTH // 2 - quit.width // 2,
                                  HEIGHT // 2 + HEIGHT // 3, 'Выйти', 'quit')
                        return quit.ret()
        screen.fill((255, 255, 255))
        dop_func.print_text(screen,
                            'Команда',
                            WIDTH // 15,
                            HEIGHT // 20,
                            font_type='stat.ttf',
                            font_size=60,
                            color='black')
        dop_func.print_text(screen,
                            'Все герои',
                            WIDTH // 2,
                            HEIGHT // 20,
                            font_type='stat.ttf',
                            font_size=60,
                            color='black')
        taked = groupMain.lst
        lineup = database.TAKED_HERO
        hp = 0
        damage = 0
        armour = 0
        for i in range(len(taked)):
            pers.draw(WIDTH // 15,
                      i * HEIGHT // 13 + HEIGHT // 5,
                      f'{taked[i].name}',
                      color='black',
                      action='change',
                      param_action=taked[i].name)
            hp += int(taked[i].hp)
            damage += int(taked[i].dmg)
            armour += int(taked[i].armour)
        for i in range(len(lineup)):
            stock.draw(WIDTH // 2,
                       i * HEIGHT // 15 + HEIGHT // 5,
                       f'{lineup[i]}',
                       color='black',
                       action='change_hero',
                       param_action=lineup[i])
        dop_func.print_text(screen,
                            'Общие статы',
                            WIDTH // 15,
                            HEIGHT // 2 + HEIGHT // 8,
                            font_type='stat.ttf',
                            font_size=40,
                            color='black')
        dop_func.print_text(screen,
                            f'HP {hp} DMG {damage} ARM {armour}',
                            WIDTH // 15,
                            HEIGHT // 2 + HEIGHT // 6,
                            font_type='stat.ttf',
                            font_size=30,
                            color='black')
        quit.draw(WIDTH // 2 - quit.width // 2, HEIGHT // 2 + HEIGHT // 3,
                  'Выйти', 'quit')
        pygame.display.flip()
def battleUI(planet=None, flag=False, res=None):
    global screen
    if flag:
        return res
    battle = Battle((groupMain, planet.get_group()))
    fon = pygame.transform.scale(dop_func.load_image('fone.jpg'),
                                 (WIDTH, HEIGHT))
    start_but = mainMenu.Button(105, 75, font_type='stat.ttf')
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                dop_func.terminate()
        screen.blit(fon, (0, 0))
        not_ours_lst = battle.lst2
        our_lst = battle.lst1
        hp, damage, armour = 0, 0, 0
        for i in range(len(our_lst)):
            hpp, dmgg, armrr = our_lst[i][0], our_lst[i][1], our_lst[i][2]
            if hpp < 0:
                hpp = 0
            dop_func.print_text(screen,
                                'Ваши герои',
                                WIDTH // 15,
                                HEIGHT // 20,
                                font_type='stat.ttf',
                                font_size=60)
            dop_func.print_text(
                screen,
                f'{battle.gr1.get_lst()[i].name} HP {hpp} DMG {dmgg} ARM '
                f'{armrr}',
                WIDTH // 15,
                i * HEIGHT // 10 + HEIGHT // 5,
                font_type='stat.ttf',
                font_size=35)
            dop_func.print_text(screen,
                                'Общие статы',
                                WIDTH // 15,
                                HEIGHT // 2 + HEIGHT // 5,
                                font_type='stat.ttf',
                                font_size=45)
            hp += int(hpp)
            damage += int(dmgg)
            armour += int(armrr)
        dop_func.print_text(screen,
                            f'HP {hp} DMG {damage} ARM {armour}',
                            WIDTH // 15,
                            HEIGHT // 2 + HEIGHT // 4,
                            font_type='stat.ttf',
                            font_size=35)
        hp, damage, armour = 0, 0, 0
        for i in range(len(not_ours_lst)):
            hpp, dmgg, armrr = not_ours_lst[i][0], not_ours_lst[i][
                1], not_ours_lst[i][2]
            if hpp < 0:
                hpp = 0
            dop_func.print_text(screen,
                                'Герои противника',
                                WIDTH // 2,
                                HEIGHT // 20,
                                font_type='stat.ttf',
                                font_size=60)
            dop_func.print_text(
                screen,
                f'{battle.gr2.get_lst()[i].name} HP {hpp} DMG {dmgg} ARM '
                f'{armrr}',
                WIDTH // 2,
                i * HEIGHT // 10 + HEIGHT // 5,
                font_type='stat.ttf',
                font_size=35)
            dop_func.print_text(screen,
                                'Общие статы',
                                WIDTH // 2,
                                HEIGHT // 2 + HEIGHT // 5,
                                font_type='stat.ttf',
                                font_size=45)
            hp += int(hpp)
            damage += int(dmgg)
            armour += int(armrr)
        dop_func.print_text(screen,
                            f'HP {hp} DMG {damage} ARM {armour}',
                            WIDTH // 2,
                            HEIGHT // 2 + HEIGHT // 4,
                            font_type='stat.ttf',
                            font_size=35)
        start_but.draw(WIDTH // 2 - start_but.width // 2,
                       HEIGHT // 2 + HEIGHT // 3, "Ход", 'battle', battle)
        pygame.display.flip()
        if battle.get_result() is not None:
            return battle.get_result()