running = True i = 0 print(bcolors.FAIL + bcolors.BOLD + "AN ENEMY ATTACKS" + bcolors.ENDC) while running: print("=========================") player.choose_action() choice = input("Choose action: ") index = int(choice) - 1 if index == 0: dmg = player.generate_damage() enemy.take_damage(dmg) print("You Attacked for ", dmg, "points of damage.", enemy.get_hp()) elif index == 1: player.choose_magic() magic_choice = int(input("Choose magic: ")) - 1 if magic_choice == -1: continue spell = player.magic[magic_choice] magic_dmg = spell.generate_damage() current_mp = player.get_mp() if spell.cost > current_mp: print(bcolors.FAIL + "\n Not enough MP" + bcolors.ENDC) continue
player.choose_item() item_choice = int(input("choose item:")) - 1 if item_choice == -1: continue item = player.items[item_choice] if item.type == "potion": player.heal(item.prop) print( Bcolors.OKGREEN + "\n" + item.name + "you have been healed for:", str(item.prop), "hp" + Bcolors.ENDC) enemy_choice = 1 enemy_dmg = enemy.generate_damage() player.take_damage(enemy_dmg) print("enemy attacks for", enemy_dmg) print("-----------------") print( "enemy hp:", Bcolors.FAIL + str(enemy.get_hp()) + "/" + str(enemy.get_max_hp()) + Bcolors.ENDC + "\n") print("your hp:" + Bcolors.OKGREEN + str(player.get_hp()) + "/" + str(player.get_max_hp()) + "/" + Bcolors.ENDC) print("your mp:" + Bcolors.OKBLUE + str(player.get_mp()) + "/" + str(player.get_max_mp()) + "/" + Bcolors.ENDC + "\n") if enemy.get_hp() == 0: print(Bcolors.OKGREEN + "you win!" + Bcolors.ENDC) running = False elif player.get_hp() == 0: print(Bcolors.FAIL + "your enemy has defeated you!" + Bcolors.ENDC) running = False
elif item.type == "elixir": player.hp = player.maxhp player.mp = player.maxmp print(item.name, "fully restored your HP/MP.", "Your HP: ", str(player.hp) + ",", " Your MP:", str(player.mp), "Your HP:", str(player.hp) + "/" + str(player.maxhp)) elif item.type == "attack": enemy.damage_intake(item.property) print(colors.failure + "You attacked the enemy with", item.name, "for:", str(item.property), "HP." + colors.end) enemy_choice = 1 target = random.randrange(0, 2) enemy_dmg = enemy.damage_generator() players[target].damage_intake(enemy_dmg) print("Enemy attacked you for", enemy_dmg, "points of damage.") print("###################") print( "Enemy Health:", colors.failure + str(enemy.get_hp()) + "/" + str(enemy.get_max_hp()) + colors.end) if enemy.get_hp() == 0: print(colors.okgreen + "You win!" + colors.end) res = False elif player.get_hp() == 0: print(colors.failure + "You died! Enemy won!" + colors.end)
}, { "item": elixir, "quantity": 1 }] # enemy inventory enemy_bag = [] # instantiating the players player = Person(100, 100, 40, 30, player_magic, player_bag) enemy = Person(200, 200, 20, 50, enemy_magic, enemy_bag) print(bgcolor.BOLD + "NAME HP MP" + bgcolor.ENDC) print(bgcolor.BOLD + "SAM: " + str(player.get_hp()) + "/" + str(player.get_max_hp()) + bgcolor.ENDC + bgcolor.OKLIGHTGREEN + "|█████████████████████████|" + bgcolor.ENDC + " " + bgcolor.BOLD + str(player.get_mp()) + "/" + str(player.get_max_hp()) + bgcolor.OKBLUE + "|█████|" + bgcolor.ENDC) print(bgcolor.BOLD + "NIKHIL: " + str(player.get_hp()) + "/" + str(player.get_max_hp()) + bgcolor.ENDC + bgcolor.OKLIGHTGREEN + "|█████████████████████████|" + bgcolor.ENDC + " " + bgcolor.BOLD + str(player.get_mp()) + "/" + str(player.get_max_hp()) + bgcolor.OKBLUE + "|█████|" + bgcolor.ENDC) print(bgcolor.BOLD + "SID: " + str(player.get_hp()) + "/" + str(player.get_max_hp()) + bgcolor.ENDC + bgcolor.OKLIGHTGREEN + "|█████████████████████████|" + bgcolor.ENDC + " " + bgcolor.BOLD + str(player.get_mp()) + "/" + str(player.get_max_hp()) + bgcolor.OKBLUE + "|█████|" + bgcolor.ENDC)
"*\nRound #", round_count,"\n") # Choose action to take player.choose_action() choice = input("Choose action:") if choice == "quit": break index = int(choice) - 1 # Attack physically if index == 0: dmg = player.generate_damage() enemy.take_damage(dmg) print("You attacked for", dmg, "damage.\nEnemy HP:", enemy.get_hp()) # Attack with magic elif index == 1: player.choose_magic() magic_choice = int(input("Choose magic:")) - 1 if magic_choice == -1: continue spell = player.magic[magic_choice] magic_dmg = spell.generate_damage() current_mp = player.get_mp() if spell.cost > current_mp: dmg = player.generate_damage(disad=2)
i=0 ##PLAYER CHOICE FOR ATTACK## print(colored("ATTACK", "red")) while running: print("*************************************") #Allowing player to choose between attack and magic player.choose_action() #minus 1 as indexing starts from 0 choice=int(input("Choose action:"))-1 print("You choose {}".format(player.actions[int(choice)])) #Attack choosen if choice == 0: dmg = player.generate_damage() enemy.take_damage(dmg) print("You attaked with force ", dmg , " making your Enemy HP:", enemy.get_hp()) else: #Magic choosen #Allowing Player to choose Spell player.choose_magic() print("Your mp is:", player.get_mp()) magic_choice = int(input("Choose magic: "))-1 # magic_dmg =player.generate_spell_damage(magic_choice) # spell = player.get_spell_name(magic_choice) # cost = player.get_spell_mp_cost(magic_choice) spell=player.magic[magic_choice] magic_dmg=spell.generate_damage() current_mp= player.get_mp()
item = player.items[item_choice] if item.type == "potion": player.heal(item.prop) print(bcolors.OKGREEN + "\n" + item.name + " heals for", str(item.prop), "HP" + bcolors.END) enemy_choice = 1 enemy_dmg = enemy.generate_damage() player.take_damage(enemy_dmg) print("Enemy attacks for", enemy_dmg) print("----------------------------") print( "Enemy HP:", bcolors.FAIL + str(enemy.get_hp()) + "/" + str(enemy.get_max_hp()) + bcolors.END + "\n") print( "Your HP:", bcolors.OKBLUE + str(player.get_hp()) + "/" + str(player.get_max_hp()) + bcolors.END + "\n") print( "Your MP:", bcolors.OKBLUE + str(player.get_mp()) + "/" + str(player.get_max_mp()) + bcolors.END) if enemy.get_hp() == 0: print(bcolors.OKGREEN + "You win!!" + bcolors.END) elif player.get_hp() == 0: print(bcolors.FAIL + "Your enemy has defeated you!" + bcolors.END) running = False
from Classes.game import Person, bcolors from Classes.magic import Spell import random fire = Spell("Fire", 10, 100, "black") thunder = Spell("Thunder", 12, 124, "black") blizzard = Spell("Blizzard", 10, 100, "black") meteor = Spell("meteor", 20, 200, "black") quake = Spell("quake", 14, 140, "black") cure = Spell("Cure", 12, 120, "white") cura = Spell("Cura", 18, 200, "white") player = Person(460, 65, 60, 34, [fire, thunder, blizzard, meteor, cure, cura]) enemy = Person(1200, 65, 45, 25, [fire, thunder, quake]) print(bcolors.FAIL + bcolors.BOLD + "An Enemy Attacks!" + bcolors.ENDC) while player.get_hp() > 0: print("=============================") player.choose_action() choice = input("Your turn\nChoose action:") while (choice != '1') and (choice != '2'): choice = input("Choose valid action:") if choice is '1' and player.get_mp() <= 0: choice = '1' if choice is '1': print("You chose to attack") dmg = player.generate_dmg() enemy.take_dmg(dmg) print("You attacked for " + str(dmg) + " points of damage. Enemy HP at " + str(enemy.get_hp()))