Vsixch / Adit

Buat Backup Coding
0 stars 0 forks source link

Daily Task : Simple Text Adventure Game #5

Open Vsixch opened 6 months ago

Vsixch commented 6 months ago

Buatlah permainan petualangan teks sederhana di mana pemain dapat memilih tindakan dari daftar pilihan yang diberikan dan melihat bagaimana pilihan mereka memengaruhi cerita.

Vsixch commented 6 months ago

'''Daily Task: Simple Text Adventure Game''' import random

'''Role Statistics''' role_user_list = ['> Mage', '> Assassin', '> Fighter', '> Archer (Only avaible)'] archer_statistics = ['This is your spesial ability for this role :', '1. +Long range attack -short attack damage', '2.Can camouflage with nature', '3.Damage always double if you hit it before']

'''Main menu for battle''' user_confirmation_battle = ['> Battle', '> Escape'] Battle_strategy = ['> Melee', '> Magic', '> Inventory', '> Surrender']

'''User Statistics''' level_statistics = {'HP': 30, 'MP': 15} item_backpack = {} weapon_statistics = [1, 2, 3, 4, 5]

'''Enemy Statistics''' enemy_user_list_first_map = ['slime', 'goblin'] enemy_dict_hp = {'slime': 20, 'goblin': 25} current_enemy = None

'''Item Weapon Recipe Craft''' wooden_sword_recipe = ['Wooden Sword', '2 Sticks', '3 Vines'] wooden_bow_recipe = ['Wooden Bow', '1 sticks', '4 Vines']

'''Item collect''' first_item_map = ['cherry', 'pebble', 'sticks', 'vine']

'''Main character statistics''' def char_statistics(): print('='45) for key, value in level_statistics.items(): if key in ['HP', 'MP']: print(f'{key}:{value}') print('='45)

'''Weapon Damage (hit)''' def weapon_stats(): return random.choice(weapon_statistics)

'''Enemy appear first map''' def first_enemy_stage(): return random.choice(enemy_user_list_first_map)

'''Item first map''' def first_item_in_first_map(): return random.choice(first_item_map)

'''User role pick''' def user_role_pick(): print('='45) for role in role_user_list: print(role) print('='45)

'''Role Archer''' def user_info_archer(): for archer in archer_statistics: print(archer) print('='*45)

'''Story Main''' def story_character(): story = (f'During the imperial period, there was a person named {username_input} who was escaping from being captured by the imperial soldiers. he was accused of killing the emperor. He was accused even though he had done nothing wrong and he didnt even know the emperors name, he was scapegoated by the nobles who wanted to take the throne of the emperor who was still alive at that time. he ran into the forest at that time he fell into a hole and suddenly he fainted and he was carried away by the river. When he wakes up he forgets his memories.') print(story)

'''confirmation user''' def confirmation_user(x): user_confirm = input(f'are you sure want to use {x}?\n--> ') if user_confirm == 'yes': return x

'''Battle Mechanism''' def battle_mechanism(): global current_enemy for confirm in user_confirmation_battle: print(confirm) confirmation_battle = input('--> ')

if confirmation_battle == 'battle':
    if current_enemy is None:
        current_enemy = first_enemy_stage()

    while True:
        for battle in Battle_strategy:
            print(battle)

        battle_input = input('--> ')
        if battle_input == 'melee':
            hit_point = weapon_stats()
            enemy = current_enemy
            enemy_dict_hp[enemy] -= hit_point
            print(f'You hit it {enemy} {hit_point} Damage, health remain {enemy_dict_hp[enemy]}')

        if enemy_dict_hp[enemy] <= 0:
            current_enemy = None
            print(f'you defeated the {enemy}')
            break

        enemy_damage = random.randint(0,3)
        level_statistics['HP'] -= enemy_damage
        print(f'The enemy hit you back, dealing damage {enemy_damage}, your health remaining {level_statistics["HP"]}')

        if level_statistics['HP'] <= 0:
            print('You were defeated...')
            break

def crafting_item(): while True: crafting_menu = ['> Weapon', '> Armor', '> Kit', '> Back'] for craft in crafting_menu: print(craft) input_crafting = input('--> ') if input_crafting == 'weapon': for sword in wooden_sword_recipe: print(sword) print('='*45)

        for bow in wooden_bow_recipe:
            print(bow)
        print('='*45)

    elif input_crafting == 'back':
        print('='*45)
        break

def character_option(): while True: option_user = ['1.walk','2.Loot','3.backpack','4.Crafting','9.Exit Game'] for option in option_user: print(option) user_choice = input('==> ')

    if user_choice == '1':
        print('U choose to walk...')

        if random.random() <= 0.45:
            enemy = first_enemy_stage()
            print(f'an enemy has appear : {enemy}\n{'='*45}')
            battle_mechanism()

        else:
            item = first_item_in_first_map ()
            if item in item_backpack:
                item_backpack[item] += 1
                print(f'You got another {item}, total: {item_backpack[item]}')

            else:
                item_backpack[item] = 1
                print(f'You got a new item: {item}')
                print('Item has been added to your backpack.\n')

    elif user_choice == '2':
        print('U loot an item surrounding you...')
        item = first_item_in_first_map()

        if item in item_backpack:
            item_backpack[item] += 1
            print(f'You got another {item}, total: {item_backpack[item]}')

        else:
            item_backpack[item] = 1
            print(f'You got a new item: {item}')

        print('Item has been added to your backpack.\n')

    elif user_choice == '3':
        print('='*45)
        print('This is your item in the backpack: ')
        for idx, (item, count) in enumerate(item_backpack.items(), 1):
            print(f'{idx}. {item}: {count}')
        print('='*45)

    elif user_choice == '4':
        print('Welcome to the workshop')
        crafting_item()

    elif user_choice == '9':
        print('See you next time :)')
        break

username_input = input('What is your charachter name: ') user_role_pick() pick_role = input('What role you gonna pick\n--> ')

confirmation_user(pick_role)

if pick_role == 'archer': print('='*45) user_info_archer()

while True: char_statistics() character_option() break