Untitled

 avatar
unknown
python
2 years ago
15 kB
1
Indexable
#Turbasert rpg

import random
import time

def main(): #main funksjon
    weapon = ()
    inventory = ()
    sword_stats = (random.randrange(18, 25))
    bow_stats = (random.randrange(10, 35))
    staff_stats = (random.randrange(15, 28))

    monster_list = ["Hydra (level 1)", "Tauren (level 1)", "Dragon (level 3)", "Chtulu (level 5)"]
    random_monster = random.choice(monster_list)
    
    battle_count = 0
    turn_count = 0


    xp = 0
    level = 1
    print ("""


        ____  ___  ______________    ______   ___    ____  _______   _____ 
       / __ )/   |/_  __/_  __/ /   / ____/  /   |  / __ \/ ____/ | / /   |
      / __  / /| | / /   / / / /   / __/    / /| | / /_/ / __/ /  |/ / /| |
     / /_/ / ___ |/ /   / / / /___/ /___   / ___ |/ _, _/ /___/ /|  / ___ |
    /_____/_/  |_/_/   /_/ /_____/_____/  /_/  |_/_/ |_/_____/_/ |_/_/  |_|

    """)

    print ("""                                                  
                                                    |>>>
                                                    |
                                                _  _|_  _
                                               |;|_|;|_|;|
                                               \\.    .  /
                                                \\:  .  /
                                                 ||:   |
                                                 ||:.  |
                                                 ||:  .|
                                                 ||:   |       \,/
                                                 ||: , |            /`\.
                                                 ||:   |
                                                 ||: . |
                  __                            _||_   |
         ____--`~    '--~~__            __ ----~    ~`---,              ___
    -~--~                   ~---__ ,--~'                  ~~----_____-~'   `~----~~
    \n""")

    
    intro = input("Welcome to BATTLE ARENA! Input START to proceed to character creation.")
    name = input("What is the name of your champion?")
    race = input("What are you? \n #Elf\n #Human\n #Orc\n")
    prof = input("What is your profession? \n#Warrior: \n#Archer \n#Wizard\n")
    
    #if race == 1:
    #    race = ("Elf")
    #elif race == 2:
    #    race = ("Human")
    #elif race == 3:
    #    race ("Orc")
    #else:
    #    print ("Wrong input: Try: '1', '2' or '3'")
    #    race = input (">")
    
    #if prof == 1:
    #    prof = ("Warrior")
    #elif prof == 2:
    #    prof = ("Archer")
    #elif prof == 3:
    #    prof ("Wizard")
    #else:
    #    print ("Wrong input: Try: '1', '2' or '3'")
    #    prof = input (">")

    print ("Generating character according to your specifications...")

    print ("Loading")
    time.sleep(1)
    print (".")
    time.sleep(1)
    print (".")
    time.sleep(1)
    print (".")
    time.sleep(1)
    print ("Complete!")
    time.sleep(1)
    print (""" 
          ***           
        *******          
       *********       
    /\* ### ### */\  
    |    @ / @    |    
    \/\    ^    /\/  
       \  ===  /      
        \_____/        
         _|_|_         
      *$$$$$$$$$*      
    """)
    time.sleep(1)
    print ("This is you.")
    time.sleep(1)
    accept = input("Are you happy with the looks of your charater? Say 'YES' ")

    print (f"\nYou are about to enter the arena {name}. Being a {race} {prof} might give you the edge you need in the battles to come\n")

    if prof == "warrior":
        weapon = "sword"

    elif prof == "archer":
        weapon = "bow"

    elif prof == "wizard":
        weapon = "staff"

    else:
        print ("Wrong input. Try again.")

    time.sleep(2)
    print (f"Congratulations - you have gained item: {weapon}\n") 
    
    
    
    

    play = True

    # Main loop
    while play:
        
        battle_count = battle_count + 1
        if xp > 150:
            level = level + 1
            print (f"""  
                (¯`·.¸¸.·´¯`·.¸¸.·´¯)
               ( \                 / )
              ( \ )You have reached( / )
             ( ) (                 ) ( )
              ( / )  Level {level}!   ( \ )
               ( /                 \ )
                (_.·´¯`·.¸¸.·´¯`·.¸_)
                
                """)
        time.sleep(0.5)
        print ("To watch item stats: type 'stats' \nTo watch your character progression: type 'xp' \nTo continue: type 'play'")
        input1 = input(">")

        while input1 == "stats": 
            if weapon == "sword":
                print ("\nSword: Damage: 2-5")
                input1 = input(">")
            elif weapon == "bow":
                print ("\nBow: Damage: 3-4")
                input1 = input(">")
            elif weapon == "staff":
                print ("\nStaff: Damage: 1-8")
                input1 = input(">")
        while input1 == "xp":
            print (f"\nCharacter stats:\n Level: {level} \n Experience: {xp} \n")
            input1 = input(">")
        
        
        winner = None
        player_health = 100
        computer_health = 100

        print (f"\n ### Battle {battle_count} ### \n")
        print (f" {name} (level {level}) VS {random_monster}\n")
        print("\nPlayer health: ", player_health, "\nComputer health: ", computer_health) 
        
        # Hvem skal begynne?
        turn = random.randint(1,2) # 50% sjanse til å begynne
        
        if turn == 1:
            player_turn = True
            computer_turn = False
            print(f"\n{name} will go first!")
        else:
            player_turn = False
            computer_turn = True
            print("\nMonster will go first.")

        print ("3")
        time.sleep(1)
        print ("2")
        time.sleep(1)
        print ("2")
        time.sleep(1)
        print ("1")
        time.sleep(1)
        print ("GO!")
        time.sleep(2)

        # set up the main game loop
        while (player_health != 0 or computer_health != 0):

            heal_up = False # determine if heal has been used by the player. Resets false each loop.
            miss = False # determine if the chosen move will miss.

            # create a dictionary of the possible moves and randomly select the damage it does when selected
            moves = {"Attack": random.randint(18, 25),
                     "Power Attack": random.randint(10, 35),
                     "Heal": random.randint(20, 25)}

            if player_turn:
                turn_count = turn_count + 1
                print (f"\n Turn {turn_count}. Your turn!\n")
                time.sleep(0.5)
                print("\nPlease select a move:\n1. Attack (Deal damage between 18-25)\n2. Power Attack (Deal damage between 10-35)\n3. Heal (Restore between 20-25 health)\n")

                player_move = input("> ").lower()
                move_miss = random.randint(1,5) # 20% of missing
                if move_miss == 1:
                    miss = True
                else:
                    miss = False

                if miss:
                    player_move = 0 # player misses and deals no damage
                    print("####################")
                    print("    You missed!")
                    print("####################")
                else:
                    if player_move in ("1", "attack"):
                        player_move = moves["Attack"]
                        print("\nYou used Attack. It dealt ", player_move, " damage.")
                    elif player_move in ("2", "power attack"):
                        player_move = moves["Power Attack"]
                        print("\nYou used Power Attack. It dealt ", player_move, " damage.")
                    elif player_move in ("3", "heal"):
                        heal_up = True # heal activated
                        player_move = moves["Heal"]
                        print("\nYou used Heal. It healed for ", player_move, " health.")
                    else:
                        print("\nThat is not a valid move. Please try again.")
                        continue

            else: # computer turn
                
                turn_count = turn_count + 1
                print (f"\n Turn {turn_count}. Computers turn!\n")
                time.sleep(1)
                print ("Computer is thinking...")
                time.sleep(0.3)
                print (".")
                time.sleep(0.3)
                print (".")
                time.sleep(0.3)
                print (".")
                time.sleep(0.3)
                move_miss = random.randint(1,5)
                if move_miss == 1:
                    miss = True
                else:
                    miss = False

                if miss:
                    computer_move = 0 # #miss, ingen dmg, 
                    print("####################")
                    print("The computer missed!")
                    print("####################")
                else:
                    print("\n####################\n")
                    if computer_health > 30: 
                        if player_health > 75:
                            computer_move = moves["Attack"]
                            print("\nThe computer used Attack. It dealt ", computer_move, " damage.")
                        elif player_health > 35 and player_health <= 75: # go big or play safe?
                            imoves = ["Attack", "Power Attack"]
                            imoves = random.choice(imoves)
                            computer_move = moves[imoves]
                            print("\nThe computer used ", imoves, ". It dealt ", computer_move, " damage.")
                        elif player_health <= 35:
                            computer_move = moves["Power Attack"] # FINISH HIM!
                            print("\nThe computer used Power Attack. It dealt ", computer_move, " damage.")                       
                    else: # 50% sjanse for å heale når under 30 hp. 
                        heal_or_fight = random.randint(1,2) 
                        if heal_or_fight == 1:
                            heal_up = True
                            computer_move = moves["Heal"]
                            print("\nThe computer used Heal. It healed for ", computer_move, " health.")
                        else:
                            if player_health > 75:
                                computer_move = moves["Attack"]
                                print("\nThe computer used Attack. It dealt ", computer_move, " damage.")
                            elif player_health > 35 and player_health <= 75:
                                imoves = ["Attack", "Power Attack"]
                                imoves = random.choice(imoves)
                                computer_move = moves[imoves]
                                print("\nThe computer used ", imoves, ". It dealt ", computer_move, " damage.")
                            elif player_health <= 35:
                                computer_move = moves["Power Attack"] # FINISH HIM!
                                print("\nThe computer used Power Attack. It dealt ", computer_move, " damage.")

            if heal_up:
                if player_turn:
                    player_health += player_move
                    if player_health > 100:
                        player_health = 100 # max health = 100
                else:
                    computer_health += computer_move
                    if computer_health > 100:
                        computer_health = 100
            else:
                if player_turn:
                    computer_health -= player_move
                    if computer_health < 0:
                        computer_health = 0 # min health = 0
                        winner = "Player"
                        break
                else:
                    player_health -= computer_move
                    if player_health < 0:
                        player_health = 0
                        winner = "Computer"
                        break

            print("\nPlayer health: ", player_health, "Computer health: ", computer_health)

            #bytte tur
            player_turn = not player_turn
            computer_turn = not computer_turn

        # Når main loop brekker, finn ut hvem som er vinneren. 

        if winner == "Player":
            print("\nPlayer health: ", player_health, "Computer health: ", computer_health)
            print("""
             ____   ____  _____   ______  _________     ___   _______   ____  ____  
            |_  _| |_  _||_   _|.' ___  ||  _   _  | .'   `.|_   __ \ |_  _||_  _| 
              \ \   / /    | | / .'   \_||_/ | | \_|/  .-.  \ | |__) |  \ \  / /   
               \ \ / /     | | | |           | |    | |   | | |  __ /    \ \/ /    
                \ ' /     _| |_\ `.___.'\   _| |_   \  `-'  /_| |  \ \_  _|  |_    
                 \_/     |_____|`.____ .'  |_____|   `.___.'|____| |___||______|   """)
            
            time.sleep(2)
            print("\nCongratulations! You have won!")
            
            xp = xp + 200
            time.sleep(2)
            print ("You have gained 200 xp! ")
           
        
        else:
            print("\nPlayer health: ", player_health, "Computer health: ", computer_health)
            print("""
                            YOU LOST! 
                            
                            , ,, ,                              
               | || |    ,/  _____  \.             
               \_||_/    ||_/     \_||             
                 ||       \_| . . |_/              
                 ||         |  L  |                
                ,||         |`==='|                
                |>|      ___`>  -<'___             
                |>|\    /             \            
                \>| \  /  ,    .    .  |           
                 ||  \/  /| .  |  . |  |           
                 ||\  ` / | ___|___ |  |     (     
              (( || `--'  | _______ |  |     ))  ( 
            (  )\|| (  )\ | - --- - | -| (  ( \  ))
            (\/  || ))/ ( | -- - -- |  | )) )  \(( 
             ( ()||((( ())|         |  |( (( () ) """)
            
            

        battle_count + 1
        time.sleep(2)
        print("\nWould you like to play again?")

        answer = input("> ").lower()
        if answer not in ("yes", "y"):
            play = False

main()

#TO DO: 
#- Reset turn_count for hver gang
#- Fikse weapons i starten 
Editor is loading...