Пример #1
0
def start_menu(race):
    is_running = True

    FIRST_ELEMENT = 0
    SECOND_ELEMENT = 1
    num_of_option = 0

    while is_running:
        helpers.clear_screen()
        # print menu structure //ui.print_menu?
        # wait for user input
        print_menu(start_menu_structure(), num_of_option)
        key = helpers.key_pressed()
        # call menu handler with user input
        menu_handler_options = start_menu_handler(key, num_of_option)
        is_running = menu_handler_options[FIRST_ELEMENT]
        num_of_option = menu_handler_options[SECOND_ELEMENT]
        user_name = menu_handler_options[2]
        if len(user_name) > 1:
            if num_of_option == 0:
                hero_class = 'Wizzard'
            if num_of_option == 1:
                hero_class = 'Knight'
            if num_of_option == 2:
                hero_class = 'Rouge'
            main.main(user_name, race, hero_class)
            is_running = False
Пример #2
0
def handle_user_input(client):
    key = key_pressed()
    client.send(key.encode('utf-8'))
    if key == 'p':
        return True
    else: 
        return False
Пример #3
0
def change_body_part(player, new_body_part_type, id=0):

    clear_screen()
    print()

    if new_body_part_type == "head":
        part_type = BODY_PARTS["heads"]
        print(f"\t{new_body_part_type.upper()}: ◄ {part_type[id]} ►")
        print(f"\tBODY:   {PLAYER_ICON['body']}  ")
        print(f"\tLEGS:   {PLAYER_ICON['legs']}  ")
    elif new_body_part_type == "body":
        part_type = BODY_PARTS["bodies"]
        print(f"\tHEAD:   {PLAYER_ICON['head']}  ")
        print(f"\t{new_body_part_type.upper()}: ◄ {part_type[id]} ►")
        print(f"\tLEGS:   {PLAYER_ICON['legs']}  ")
    elif new_body_part_type == "legs":
        part_type = BODY_PARTS["legs"]
        print(f"\tHEAD:   {PLAYER_ICON['head']}  ")
        print(f"\tBODY:   {PLAYER_ICON['body']}  ")
        print(f"\t{new_body_part_type.upper()}: ◄ {part_type[id]} ►")

    key = key_pressed()
    if key in KEY_BINDINGS_MOVE["left"] and id > 0:
        change_body_part(player, new_body_part_type, id - 1)
    elif key in KEY_BINDINGS_MOVE["right"] and id < len(part_type) - 1:
        change_body_part(player, new_body_part_type, id + 1)
    elif key == 10:  # test ENTERa
        input()
        pass
    elif key in KEY_BINDINGS["exit"]:
        PLAYER_ICON[new_body_part_type] = part_type[id]
        return player
    else:
        change_body_part(player, new_body_part_type, id)
Пример #4
0
def main():
    file_name = 'Messages/start_screen.txt'
    START_INDEX = 8
    INSTRUCTION_INDEX = 10
    AUTHORS_INDEX = 12
    EXIT_INDEX = 14
    screen = make_start_board(START_INDEX, file_name)
    while True:
        helpers.clear_screen()
        print_screen(screen)
        key = helpers.key_pressed()
        if key == 'n':
            change_option_to_next(screen, file_name)
            helpers.clear_screen()
            print_screen(screen)
        if key == 'p':
            change_option_to_previous(screen, file_name)
            helpers.clear_screen()
            print_screen(screen)
        if key == 'e':
            chosen_option_index = check_option_true(screen, file_name)
            if chosen_option_index == START_INDEX:
                return
            else:
                make_chosen_option(chosen_option_index, INSTRUCTION_INDEX,
                                   AUTHORS_INDEX, EXIT_INDEX)
Пример #5
0
def print_menu():

    helpers.clear_screen()
    empty_space = 7 * "\n"
    print(empty_space)
    #print(colored(const.LOGO[1], 'yellow', attrs=[]))
    ui.show_logo_animation(asciiart.LOGO, True)
    print(empty_space)

    print(
        colored("PRESS ANY KEY TO START", "white",
                attrs=['bold',
                       'blink']).center(shutil.get_terminal_size().columns))

    helpers.key_pressed()
    ui.show_logo_animation(asciiart.LOGO, False)
    show_animation(asciiart.swing, asciiart.orphan)
Пример #6
0
def instruction():
    with open('instruction.txt', 'r') as instruction:
        instruction = instruction.readlines()
    helpers.clear_screen()
    print_screen(instruction)
    while True:
        key = helpers.key_pressed()
        if key == 'q':
            break
Пример #7
0
def make_chosen_option(chosen_option_index, INSTRUCTION_INDEX, AUTHORS_INDEX,
                       EXIT_INDEX):
    if chosen_option_index == INSTRUCTION_INDEX:
        file_to_print = 'messages/instruction.txt'
        screen = make_board(file_to_print)
        helpers.clear_screen()
        print_screen(screen)
        while True:
            key = helpers.key_pressed()
            if key == 'q':
                break
    elif chosen_option_index == AUTHORS_INDEX:
        file_to_print = 'messages/authors.txt'
        screen = make_board(file_to_print)
        helpers.clear_screen()
        print_screen(screen)
        while True:
            key = helpers.key_pressed()
            if key == 'q':
                break
    elif chosen_option_index == EXIT_INDEX:
        sys.exit()
Пример #8
0
def show_story():

    time.sleep(1)

    text_movement_delay = 3
    animation_delay = 0.3

    story = []
    story.append(
        "The night was cold, I wrapped myself in thick blanket and tried to sleep. "
    )
    story.append("Then I heard a thunder. The Baba Yaga has came. ")
    story.append("She took my lynx, she killed my parents. ")
    story.append("I hid under bed and saw as she rode away on my lynx.")
    story.append("I will get you back Rysio. I will get revenge.")
    text = []

    for i in range(len(story)):
        clear_screen()
        empty_space = (20 - i) * "\n"
        text.append(story[i])
        print(empty_space)
        for e in range(len(text)):
            print(text[e].center(shutil.get_terminal_size().columns))

        time.sleep(text_movement_delay)

    for i in range(1, 15):
        print(empty_space)
        for e in range(len(text)):
            print(text[e].center(shutil.get_terminal_size().columns))
        print(asciiart.FACE2[i % 2])
        time.sleep(animation_delay)

    print("Press any key".center(shutil.get_terminal_size().columns))
    key_pressed()
def race_start_menu():
    is_running = True

    FIRST_ELEMENT = 0
    SECOND_ELEMENT = 1
    num_of_option = 0

    while is_running:
        helpers.clear_screen()
        # print menu structure //ui.print_menu?
        # wait for user input
        print_menu(start_menu_structure(), num_of_option)
        key = helpers.key_pressed()
        # call menu handler with user input
        menu_handler_options = start_menu_handler(key, num_of_option)
        is_running = menu_handler_options[FIRST_ELEMENT]
        num_of_option = menu_handler_options[SECOND_ELEMENT]
Пример #10
0
def boss(player):
    while True:
        ui.display_board(create_board("messages/message_boss.txt"))
        time.sleep(3)
        key = helpers.key_pressed()
        if key == "s":
            amount_of_numbers = 4
            message = ['', 'HEY', '', 'I\'M GOING TO KILL YOU', '',
                       'YOU HAVE TO GUESS ALL {} NUMBERS'.format(amount_of_numbers), '', '']
            ui.print_boss(message)
            band_of_numbers = 64 // amount_of_numbers
            lives = int(player['HP']/10)
            guessed_numbers = []
            numbers_list = [random.randint(1, band_of_numbers) for number in range(amount_of_numbers)]
            guessed_numbers = main_game(numbers_list, band_of_numbers, lives, guessed_numbers)
            if numbers_list == guessed_numbers:
                player['level'] = 5
            if numbers_list != guessed_numbers:
                player['HP'] = 0
            return player
Пример #11
0
 def start_game(self):
     player_reach_exit = False
     #start_counting = False
     while not player_reach_exit:
         clear_screen()
         if self.player.position == self.maze.start_position:
             self.displayer.prepare_map_string(Point(0, 0))
             self.displayer.display_string()
         elif self.player.position == self.maze.exit_positon:
             break
         else:
             self.displayer.prepare_player_vision(
                 self.player.position, self.player.player_vision_length)
             self.displayer.display_player()
         key = key_pressed()
         if key == '0':
             # should be changed
             player_reach_exit = True
         elif key in 'wdsa':
             p1.change_position(key)
     self.finish_game()
Пример #12
0
def main(player, board):
    global word_used
    
    board_with_player = engine.put_player_on_board(board, player)

    clear_screen(40)
    ui.display_board(board_with_player, player)
    print(f"\n\tPLAYER X:{player['x']} Y:{player['y']}")
    
    key = key_pressed()
    around_player = 2
    
    # collisions check
    no_obstacle_on_up = board[player["y"]-around_player][player["x"]] in PASSABLE and board[player["y"]-around_player][player["x"]+1] in PASSABLE
    no_obstacle_on_down = board[player["y"] + around_player][player["x"]] in PASSABLE and board[player["y"] + around_player][player["x"]+1] in PASSABLE
    no_obstacle_on_left = board[player["y"]][player["x"]-around_player] in PASSABLE and board[player["y"]+1][player["x"]-around_player] in PASSABLE
    no_obstacle_on_right = board[player["y"]][player["x"]+around_player] in PASSABLE and board[player["y"]+1][player["x"]+around_player] in PASSABLE
    no_obstacle_on_leftUP = board[player["y"]-around_player][player["x"]-around_player] in PASSABLE
    no_obstacle_on_rightUP = board[player["y"]-around_player][player["x"]+around_player] in PASSABLE
    no_obstacle_on_leftDOWN = board[player["y"] + around_player][player["x"]-around_player] in PASSABLE
    no_obstacle_on_rightDOWN = board[player["y"] + around_player][player["x"]+around_player] in PASSABLE
    # move keys pressed
    move_keys = sum(KEY_BINDINGS_MOVE.values(),[])

    if key in move_keys:
        # vertical movement
        if key in KEY_BINDINGS_MOVE["up"] and no_obstacle_on_up:
            player["y"] -= 1
        elif key in KEY_BINDINGS_MOVE["down"] and no_obstacle_on_down:
            player["y"] += 1
        # horiontal movement
        elif key in KEY_BINDINGS_MOVE["left"] and no_obstacle_on_left:
            player["x"] -= 1
        elif key in KEY_BINDINGS_MOVE["right"] and no_obstacle_on_right:
            player["x"] += 1
        # diagonal movement
        elif key in KEY_BINDINGS_MOVE["leftUP"] and no_obstacle_on_leftUP:
            player["x"] -= 1
            player["y"] -= 1
        elif key in KEY_BINDINGS_MOVE["rightUP"] and no_obstacle_on_rightUP:
            player["x"] += 1
            player["y"] -= 1
        elif key in KEY_BINDINGS_MOVE["leftDOWN"] and no_obstacle_on_leftDOWN:
            player["x"] -= 1
            player["y"] += 1
        elif key in KEY_BINDINGS_MOVE["rightDOWN"] and no_obstacle_on_rightDOWN:
            player["x"] += 1
            player["y"] += 1
        
        # item collisions
        if board[player["y"]][player["x"]] in PICKUPS or board[player["y"]][player["x"]+1] in PICKUPS:
            board[player["y"]][player["x"]-1] = " "
            board[player["y"]][player["x"]] = " "
            board[player["y"]][player["x"]+1] = " "

        fight_result = False
        # enemy collision
        if board[player["y"]][player["x"]] in ENEMIES["small"]["icon"] or board[player["y"]][player["x"]+1] in ENEMIES["small"]["icon"]:
            fight_result = enemies.fight_with_monsters_small(player)
        if board[player["y"]][player["x"]] in ENEMIES["big"]["icon"] or board[player["y"]][player["x"]+1] in ENEMIES["big"]["icon"]:
            fight_result = enemies.fight_with_monsters_large(player)

        if fight_result:
            board[player["y"]][player["x"]-1] = " "
            board[player["y"]][player["x"]] = "†"
            board[player["y"]][player["x"]+1] = " "
            ui.player_say(board_with_player, player, "Another one bites the dust!")
            key_pressed()

    # key binded options
    elif key in KEY_BINDINGS["overlay"]: # OVERLAY TEST
        ui.show_overlay(board_with_player)
        clear_screen()
        ui.display_board(board_with_player, player)
        input()
    
    elif key in KEY_BINDINGS["customize"]:
        engine.customize_character(player)
    elif key in KEY_BINDINGS["logo"]:
        ui.show_logo_animation(LOGO)
    elif key in KEY_BINDINGS["story"]:
        ui.show_story()
    elif key in KEY_BINDINGS["verbal_attack"]:
        word_used, board = ui.verbal_attack(board_with_player, board, player, word_used)
        key_pressed()
    elif key in KEY_BINDINGS["generator"]:
        engine.generate_new_map(board, player)
    
    elif key in KEY_BINDINGS["clear"]:    
        clear_screen(0)
        
    elif key in KEY_BINDINGS["inventory"]:
        ui.display_inv()
        print("1.Heal", "2.Regen", "~~~Enter to Exit")
        option = input()
        if option == "1":
            if "HP Potion" in ui.inv:
                player["HP"] += 4 + player["intelligence"]
                # If current HP >= maxHP currentHP=MaxHP
                if player["HP"] >= player["max_hp"]:
                    player["HP"] = player["max_hp"]
                ui.inv.remove("HP Potion")
            else:
                print("No potions")
                pass
        if option == "2":
            if "Mana Potion" in ui.inv:
                player["MP"] += 10 + player["intelligence"]
                ui.inv.remove("Mana Potion")
        else:
            print("No potions")
        if option == "3":
            #pass
            player["experience"] += 100   # Cheat
            player["HP"] = 10
            stats.level_up(player)
    elif key in KEY_BINDINGS["stats"]:
        stats.display_advenced_stats(player)  # Display stats like attack dmg
        enemies.fight_with_monsters_small(player)
        pass
    elif key in KEY_BINDINGS["exit"]:
        return

    stats.small_monster_hp = 10
    stats.large_monster_hp = 20
    main(player, board)
Пример #13
0
def fight_with_monsters_small(player):
    while stats.small_monster_hp > 0:
        print("Monster HP: " + str(stats.small_monster_hp))
        print("Player Hp :  " + str(player["HP"]) + "/" +
              str(player["max_hp"]) + "  Player MP : " + str(player["MP"]))
        print("Choose option: "
              "\n"
              "1.Attack"
              "\n"
              "2. Inventory"
              "\n"
              "3.Try to escape")
        key = key_pressed()
        clear_screen()
        if key in KEY_BINDINGS_FIGHT["Fight"]:
            print("1. Attack with weapon =", player["attack"], "dmg", "\n"
                  "2. Cast Fire ball =", 1 + player["intelligence"],
                  "dmg Cost : 5 MP"
                  "\n"
                  "3. Back")
            key = key_pressed()
            clear_screen()
            if key == "1":
                chance_to_hit = ["hit", "hit", "hit", "miss"]
                if random.choice(chance_to_hit) == "hit":
                    print("Succeeded!")
                    # Add monster hp
                    stats.small_monster_hp -= player["attack"]
                    if stats.small_monster_hp <= 0:
                        print("You killed monster")
                        small_monster_kill(player)
                        return True
                    else:
                        stats.small_taking_dmg(player)
                        fight_with_monsters_small(player)
                    print("Press enter")
                    key_pressed()
                    clear_screen()
                    return True
                else:
                    print("Missed")
                    stats.small_taking_dmg(player)
                    print("Press enter")
                    key_pressed()
            elif key == "2":
                if player["MP"] >= 5:
                    player["MP"] -= 5
                    chance_to_hit = ["hit", "hit", "hit", "miss"]
                    if random.choice(chance_to_hit) == "hit":
                        print("Succeeded!")
                        stats.small_monster_hp -= 1 + player["intelligence"]
                        if stats.small_monster_hp <= 0:
                            print("You killed monster")
                            small_monster_kill(player)
                            return True
                        else:
                            stats.small_taking_dmg(player)
                            fight_with_monsters_small(player)
                        print("Press enter")
                        key_pressed()
                    else:
                        print("Missed")
                        stats.small_taking_dmg(player)
                        print("Press enter")
                        key_pressed()
                else:
                    print("Not enough mana")
                    fight_with_monsters_small(player)
            elif key == "3":
                fight_with_monsters_small(player)
        elif key in KEY_BINDINGS_FIGHT["Use inventory"]:
            ui.display_inv()
            print("1.Heal", "2.Regen", "3.Back")
            key = key_pressed()
            if key == "1":
                if "HP Potion" in ui.inv:
                    player["HP"] += 4 + player["intelligence"]
                    # If current HP >= maxHP currentHP=MaxHP
                    if player["HP"] >= player["max_hp"]:
                        player["HP"] = player["max_hp"]
                    ui.inv.remove("HP Potion")
                else:
                    print("No potions")
                    return True  # Sprawdź
            if key == "2":
                if "Mana Potion" in ui.inv:
                    player["MP"] += 10 + player["intelligence"]
                    ui.inv.remove("Mana Potion")
                else:
                    print("No potions")
            fight_with_monsters_small(player)
            if key == "3":
                fight_with_monsters_small(player)
        elif key in KEY_BINDINGS_FIGHT["Try to escape"]:
            chance_to_escape = [
                "fail", "fail", "fail", "fail", "fail", "fail", "successed"
            ]
            if random.choice(chance_to_escape) == "successed":
                print("You escaped")
                stats.small_monster_hp = 0
                print("Press enter")
                key_pressed()
                return False
            elif random.choice(chance_to_escape) == "fail":
                print("Failed")
                stats.small_taking_dmg(player)
                fight_with_monsters_small(player)
        if key not in KEY_BINDINGS_FIGHT:
            fight_with_monsters_small(player)
    return True