コード例 #1
0
def prompt(text="\n< Press Enter to continue. >",
           *keys,
           clear=True,
           message=True):
    """
    Asks user from prompt with text "text".
    Goes on if answer is present in "*keys". (use lower-cases here).
    Re-runs if a key not in "*keys" is pressed.

    Please use the format: prompt('< TEXT_HERE >', 'key1', 'key2', 'key3', clear=False/True, message=True/False)

    If clear is True then right after the user sends its input the screen will be cleared. It's True by default.

    'message' is the Error message when user gives an input other than the expected.
    If 'message' is False then error message will be ignored. It's True by default.

    :param text: str
    :param keys: tuple of strings
    :param clear: bool
    :param message: bool
    :return: str
    """
    answer = input(text)
    if clear is True:
        clear_screen()
    if not keys:
        return answer
    if answer in keys:
        return answer
    if message is True:
        print(f"- Error: Expected {keys} but got '{answer}' -")
    prompt()
コード例 #2
0
def cheat_hard():
    clear_screen()
    print("\t\nHARD CHEAT ENABLED.\t\nWaiting 180s. Maybe time for a coffee?")
    t = 180
    while t >= 1:
        time.sleep(1)
        t -= 1
    clear_screen()
コード例 #3
0
def cheat():
    clear_screen()
    print("\t\n90 seconds countdown...\n")
    t = 90
    while t >= 1:
        print(t, '\n')
        time.sleep(1)
        t -= 1
    clear_screen()
コード例 #4
0
def count_regressive():
    print('\t\n\nWRONG OPTION\n\n')
    print('\t\nChoose again... in 5 seconds...\n\n')
    t = 5
    while t >= 1:
        print(t, '\n')
        time.sleep(1)
        t -= 1
    clear_screen()
コード例 #5
0
def count_bye():
    print('\t\n\nGOODBYE\n\n')
    print('\t\nShutdown in 3 seconds...\n\n')
    t = 3
    while t >= 1:
        print(t, '\n')
        time.sleep(1)
        t -= 1
    clear_screen()
    sys.exit()
    sys.exit()
コード例 #6
0
ファイル: player.py プロジェクト: johnvictorfs/sacred-river-2
    def death(self):
        clear_screen()
        print(f"""
--- Oh dear, {self.name} Died! ---

Restart the game to keep playing.
Your stats will keep going from the last point you saved.

---""")
        prompt("< Press Enter to exit. >")
        exit(0)
コード例 #7
0
    def display(self):
        clear_screen()
        print(f"""
_________________________________________
||| Displaying NPC info of {self.name} |||
- Attack: {self.attack}
- Defence: {self.defence}
- Health: {self.health}/{self.max_health}
- Gold Drops: 0-{self.gold_drops}
- Extra Drop: {self.extra_drop} (Rate 1/{self.extra_drop_rate})
_________________________________________
        """)
コード例 #8
0
ファイル: player.py プロジェクト: johnvictorfs/sacred-river-2
    def display_stats(self):
        clear_screen()
        print(f"""
_________________________________________
||| Displaying stats of {self.name} |||
- Attack: {self.attack}
- Defence: {self.defence}
- Health: {self.health}/{self.max_health}
- Gold: {self.gold}
- Luck: {self.luck}

(Higher Luck = Increased chance of running
away from monsters and unique drops)
_________________________________________""")
        prompt()
コード例 #9
0
    def monster_turn(self):
        clear_screen()
        if self.monster.attack():
            print("{} is attacking!".format(self.monster))

            if input("Dodge? Y/N ").lower() == 'y':
                if self.player.dodge():
                    print("You dodged the attack!")
                else:
                    print("You got hit anyway!")
                    self.player.hit_points -= 1
            else:
                print("{} hit you for 1 point!".format(self.monster))
                self.player.hit_points -= 1
        else:
            print("{} isn't attacking this turn.".format(self.monster))
コード例 #10
0
def display():
    shop_list = {}
    clear_screen()
    print("||| Shop |||")
    index = 0
    for item in shop_entries:
        index += 1
        shop_list[index] = item
        print("________________________________")
        if item.item_type is 'Armour':
            print(f"[ {index} ] {item.name} (+{item.armour} Armour)")
        if item.item_type is 'Weapon':
            print(f"[ {index} ] {item.name} (+{item.attack} Attack)")
        if item.item_type is 'Health_Potion':
            print(f"[ {index} ] {item.name} (+{item.heal_value} Health)")
        print(f"Cost: {item.buy_value}")
    print(f"""
Your Gold: [ {player.gold} ]

[ 1-{index} ] Buy Item
[ S ] Sell items
[ Q ] Go Back""")
    options = ('q', 'Q', 's', 'S')
    for item in range(index + 1):
        options += (str(item), )
    answer = prompt("\n>> ", *options)
    if answer is 'q' or answer is 'Q':
        return
    elif answer is 's' or answer is 'S':
        sell_inventory_items()
        display()
    else:
        try:
            buy_item(shop_list[int(answer)])
            prompt()
            display()
        except (IndexError, TypeError, KeyError, ValueError):
            print("Item not found.")
            prompt()
            display()
            return
コード例 #11
0
    def display_inventory(self, player):
        print(f"||| Inventory of {player.name} |||")
        if not self.items:
            print(f"\nInventory of {player.name} is empty!")
            prompt()
            return
        for item in self.items.values():
            print("________________________________")

            if item.item_type is 'Weapon':
                print(
                    f"[ x{item.quantity} {item.name} ] (+{item.attack} Attack)"
                )
            if item.item_type is 'Armour':
                print(
                    f"[ x{item.quantity} {item.name} ] (+{item.armour} Armour)"
                )
            if item.item_type is 'Health_Potion':
                print(
                    f"[ x{item.quantity} {item.name} ] (+{item.heal_value} Health)"
                )
            print(f"Sell value: {item.sell_value} Gold")
        print("""
 _____________________
| [ 1 ] Equip Weapon  |
| [ 2 ] Equip Armour  |
| [ 3 ] Drink Potion  |
|                     |
| [ Q ] Go back       |
|_____________________|""")
        answer = prompt(">> ", 'q', 'Q', '1', '2', '3')
        if answer is 'q':
            return

        if answer is '1':
            clear_screen()
            weapons = []
            index = 1
            for item in self.items.values():
                if item.item_type is 'Weapon':
                    weapons.append(item)
            print("||| Weapons in Inventory |||")
            for item in weapons:
                print("________________________________")
                print(f"[ {index} ] {item.name} (+{item.attack} Attack)")
                index += 1
            equip_options = ('q', 'Q')
            for item_option in range(index):
                equip_options += (str(item_option), )
            print(f"\n[ 1-{index-1} ] Equip Weapon")
            print("[ Q ] Go back")
            answer = prompt("\n>> ", *equip_options)
            if answer is 'q' or answer is 'Q':
                return
            else:
                try:
                    pos = int(answer) - 1
                    self.equip_item(weapons[pos])
                except (IndexError, TypeError):
                    print("Item not found.")
                prompt()
                return

        if answer is '2':
            clear_screen()
            armours = []
            index = 1
            for item in self.items.values():
                if item.item_type is 'Armour':
                    armours.append(item)
            print("||| Armours in Inventory |||")
            for item in armours:
                print("________________________________")
                print(f"[ {index} ] {item.name} (+{item.armour} Armour)")
                index += 1
            equip_options = ('q', 'Q')
            for item_option in range(index):
                equip_options += (str(item_option), )
            print(f"\n[ 1-{index-1} ] Equip Armour")
            print("[ Q ] Go back")
            answer = prompt("\n>> ", *equip_options)
            if answer is 'q' or answer is 'Q':
                return
            else:
                try:
                    pos = int(answer) - 1
                    self.equip_item(armours[pos])
                except (IndexError, TypeError):
                    print("Item not found.")
                prompt()
                return
        if answer is '3':
            clear_screen()
            index = 1
            item_options = []
            print(
                f"||| Current Health: {player.health}/{player.max_health} |||\n"
            )
            for item in self.items.values():
                if item.item_type is 'Health_Potion':
                    item_options.append(item)
                    print("________________________________")
                    print(
                        f"[ {index} ] {item.name} (+{item.heal_value} Health)")
                    index += 1
            drink_options = ('q', 'Q')
            for item_option in range(index):
                drink_options += (str(item_option), )
            print(f"\n[ 1-{index-1} ] Drink Potion")
            print("[ Q ] Go back")
            answer = prompt("\n>> ", *drink_options)
            if answer is 'q' or answer is 'Q':
                return
            try:
                pos = int(answer) - 1
                self.drink_potion(item_options[pos], player)
            except (IndexError, TypeError):
                print("Item not found.")
                prompt()
                return
コード例 #12
0
def battle(player, npc):
    """
    :param player: Monster
    :param npc: Player
    :return: None
    """
    for item in inventory.inv.equipment.values():
        if item.item_type == 'Weapon':
            weapon_attack = item.attack
            break
    else:
        weapon_attack = 0
    for item in inventory.inv.equipment.values():
        if item.item_type == 'Armour':
            armour_defence = item.armour
            break
    else:
        armour_defence = 0
    effective_player_defence = player.defence + armour_defence
    effective_player_attack = player.attack + weapon_attack
    npc.health = npc.max_health
    print(f"""
______ {player.name} Vs {npc.name} ______

- {player.name} HP: {player.health}/{player.max_health}
- {player.name} Attack: {player.attack} + {weapon_attack} from Weapon ({effective_player_attack})
- {player.name} Defence: {player.defence} + {armour_defence} from Armour ({effective_player_defence})
-----------------------------------------
- {npc.name} HP: {npc.health}/{npc.max_health}
- {npc.name} Attack: {npc.attack}
- {npc.name} Defence: {npc.defence}
__________________________________________
    """)
    prompt()

    while True:
        player_hit = random.randint(
            0, effective_player_attack) - random.randint(0, npc.defence)
        npc_hit = random.randint(0, npc.attack) - random.randint(
            0, effective_player_defence)
        if player_hit < 0:
            player_hit = 0
        if npc_hit < 0:
            npc_hit = 0
        player.health -= npc_hit
        npc.health -= player_hit

        print(f"""
______ {player.name} Vs {npc.name} ______
{player.name} hit {player_hit}.
{npc.name} hit {npc_hit}.
-----------------------------------------
- {player.name} HP: {player.health}/{player.max_health}
- {npc.name} HP: {npc.health}/{npc.max_health}
__________________________________________""")
        if player.health <= 0:
            player.death()
        if npc.health <= 0:
            break
        print(f"""
[ Enter ] Attack
[   1   ] Attack
[   2   ] Drink HP Potion
[   Q   ] Run Away!

Current Run chance: {player.luck} roll(s) at 1/5 Chance.""")
        answer = prompt("\n>> ", '', '1', '2', 'q', 'Q')
        if answer is '1':
            pass
        elif answer is '2':
            for item in inventory.inv.items.values():
                if item.item_type is 'Health_Potion':
                    inventory.inv.drink_potion(item, player)
            else:
                print("You don't have any Health Potions.")
                prompt()
        if answer is 'q' or answer is 'Q':
            for number in range(player.luck):
                if random.randint(0, 5) is 5:
                    clear_screen()
                    print("You ran away successfully. What a coward!")
                    prompt()
                    return
            clear_screen()
            print("You couldn't get away! Tough luck.")
            prompt()

    gold_reward = random.randint(0, npc.gold_drops)
    print(f"""
[ {player.name} beat {npc.name} successfully. ]

[ HP: {player.health}/{player.max_health} ]
________________________________________________
[      REWARDS      ]

[ Gold: {gold_reward} ]
    """)
    for number in range(player.luck):
        if random.randint(0, npc.extra_drop_rate) == npc.extra_drop_rate:
            try:
                print(f"[ Other: {npc.extra_drop.name} ]")
                inventory.inv.add_item(npc.extra_drop)
                break
            except AttributeError:
                pass
    else:
        print("[ Other: None ]")
    player.level_up(skill='attack', chance=7, increase=5)
    player.level_up(skill='defence', chance=25, increase=3)
    player.level_up(skill='health', chance=15, increase=5)
    player.level_up(skill='luck', chance=5, increase=2)

    player.gold += gold_reward
    prompt()
コード例 #13
0
    h = HurricaneAdvisory()

    print(curr_weather.get_current_conditions())
    print(sun_phase.get_sun_phase())

    print("\nWhat else would you like to know about {}?".format(
        curr_weather.city_full_name))

    while True:
        user_input = input(
            "\n1) 10 day forcast\n2) Weather Alerts\n3) Hurricane Advisory\n4) Quit\n"
        )
        if user_input == '1':

            ten_day.get_ten_day_forcast()

        elif user_input == '2':

            weather_alerts.get_alerts()

        elif user_input == '3':

            h.get_hurricanes()
        elif user_input == '4':
            exit()


if __name__ == "__main__":
    clear_screen()
    main()
コード例 #14
0
def indicator():
    print('\t\n *** THIS PROGRAM IS A CONSTRUCTOR OF PARTNERS DATA ***\n')
    print('\t\n === USE THIS FOR POPULATE THE dbfornecedores on site ===\n')
    option = input('\t\n Choose your OS below:\t\n - Type:\t\n\n'+
                   '"1" for *NIX\t\n"2" for WIN\t\n"0" for EXIT\t\n\n\n->')
    if option == '1':
        clear_screen()
        path = input('\t\nInsert the path...\t\nEx:\n'+
                        '/home/<user>/Documents/<spreadsheat.*>"\t\n\n'+
                        '->')
        path_indicator(path)
        #clear_screen()
    elif option == '2':
        clear_screen()
        path = input('\t\nInsert the path...\t\nEx:\n'+
                        'C:\\Users\\<user>\\Documents\\<spreadsheat.*>"\t\n\n'+
                        '->')
        path_indicator(path)
        clear_screen()
    elif option == '0':
        clear_screen()
        count_bye()
    else:
        clear_screen()
        count_regressive()
        clear_screen()
        indicator()
        option = ''