def test_hero_add_multi_ability(): big_strength = Ability("Overwhelming Strength", 300) speed = Ability("Lightning Speed", 500) Athena = Hero("Athena") assert len(Athena.abilities) == 0 Athena.add_ability(big_strength) assert len(Athena.abilities) == 1 Athena.add_ability(speed) assert len(Athena.abilities) == 2 assert "Ability" in str(Athena.abilities[0]) assert Athena.abilities[0].name == "Overwhelming Strength"
def test_ability_attack(): # Test for correct attack value test_runs = 400 big_strength = Ability("Overwhelming Strength", 400) for _ in range(0, test_runs): attack = big_strength.attack() assert attack >= 0 and attack <= 400
def test_hero_ability_attack_mean_value(): athena = Hero("Athena") strength = random.randint(10, 30000) big_strength = Ability("Overwhelming Strength", strength) athena.add_ability(big_strength) calculated_mean = strength // 2 iterations = 6000 accepted_window = 400 total_attack = 0 for _ in range(iterations): attack_value = athena.attack() assert attack_value >= 0 and attack_value <= strength total_attack += attack_value actual_mean = total_attack / iterations print("Max Allowed Damage: {}".format(strength)) print("Attacks Tested: {}".format(iterations)) print("Mean -- calculated: {} | actual: {}".format(calculated_mean, actual_mean)) print("Acceptable Distance from Mean: {} | Average distance from mean: {}". format(accepted_window, abs(calculated_mean - actual_mean))) print("Acceptable min attack: {} | Acceptable max attack: {}".format( actual_mean - accepted_window, actual_mean + accepted_window)) assert actual_mean <= calculated_mean + accepted_window and actual_mean >= calculated_mean - accepted_window
def test_hero_attack(): flash = Hero("The Flash") assert flash.attack() == 0 pesto = Ability("Pesto Sauce", 8000) flash.add_ability(pesto) attack = flash.attack() assert attack <= 8000 and attack >= 4000
def test_hero_attack_ability(): big_strength = Ability("Overwhelming Strength", 30000) athena = Hero("Athena") assert athena.attack() == 0 athena.add_ability(big_strength) attack = athena.attack() assert attack <= 30000 and attack >= 0
def create_ability(self): """Promp for Ability information. It will return Ability with values from user input""" name = input('What is the ability name? ') max_damage = input('What is the max damage of the ability? ') return Ability(name, max_damage)
def __init__(self, init_rolls=None): if not init_rolls: init_rolls = [10 for _ in range(6)] super().__init__( {ability: Ability(name=ability, base=init_rolls[i]) for i, ability in enumerate(ABILITY) })
def create_ability(self): ''' Prompt for ability information. return ability with values from user input ''' name = input("What is the ability name? ") max_damage = input("What is the max damage of the ability? ") return Ability(name, max_damage)
def test_hero_add_ability(): big_strength = Ability("Overwhelming Strength", 300) Athena = Hero("Athena") assert len(Athena.abilities) == 0 Athena.add_ability(big_strength) assert len(Athena.abilities) == 1 assert "Ability" in str(Athena.abilities[0]) assert Athena.abilities[0].name == "Overwhelming Strength"
def __init__(self, level): self.level = level self.name = "Monster #" + str(random.randint(1, 10000000)) self.max_hp = random.randint(40 + level * 4, 60 + level * 6) self.curr_hp = self.max_hp self.str = random.randint(10 + level * 1, 15 + int(level * 1.5)) self.gold_reward = int((self.max_hp * self.str) / 100) self.abilities = [Ability("Punch", ["Fist"], {"Atk": 1.0})]
def test_hero_weapon_ability_attack(): quickness = Ability("Quickness", 1300) sword_of_truth = Weapon("Sword of Truth", 700) Athena = Hero("Athena") Athena.add_ability(quickness) Athena.add_ability(sword_of_truth) assert len(Athena.abilities) == 2 attack_avg(Athena, 0, 2000)
def test_hero_attack_weapon(): big_strength = Ability("Overwhelming Strength", 200) Athena = Hero("Athena") Athena.add_ability(big_strength) test_runs = 100 for _ in range(0, test_runs): attack = big_strength.attack() assert attack <= 200 and attack >= 0
def create_ability(self): """Return ability with values from user input.""" name = input('What is the ability name? ') try: max_damage = int(input('What is the max damage? ')) except ValueError: print("Please enter a number.") max_damage = int(input('What is the max damage? ')) return Ability(name, max_damage)
def create_ability(): abilities = [ "Alien Attack", "Science", "Star Power", "Immortality", "Grandmas Cookies", "Blinding Strength", "Cute Kittens", "Team Morale", "Luck", "Obsequious Destruction", "The Kraken", "The Fire of A Million Suns", "Team Spirit", "Canada" ] name = abilities[random.randint(0, len(abilities) - 1)] power = random.randint(45, 700000) return Ability(name, power)
def loadFromPkmnXML(name): """ Load an ability with the given name from an XML file """ # Get Ability XML tree = AbilityFactory.getAbilitydexTree() tree = AbilityFactory.getAbilityXML(tree, name) # Build the Ability if tree == None: print "Could not find ability:", name ability = Ability(name) else: ability = AbilityFactory.buildAbilityFromXML(tree) return ability
def test_team_attack_deaths(): team_one = Team("One") jodie = Hero("Jodie Foster") aliens = Ability("Alien Friends", 10000) jodie.add_ability(aliens) team_one.add_hero(jodie) team_two = Team("Two") athena = Hero("Athena") socks = Armor("Socks", 10) athena.add_armor(socks) team_two.add_hero(athena) assert team_two.heroes[0].deaths == 0 team_one.attack(team_two) assert team_two.heroes[0].deaths == 1
def __str__(self): output = ("{}\n" "HP Total: {}\n" "{}\n" "{}\n" "Ability: {}\n" " {}\n" "Base Stats{}\n" " HP: {}\n" " Atk: {}\n" " Def: {}\n" " SpAtk: {}\n" " SpDef: {}\n" " Speed: {}\n" "Current Stats {}\n" " HP: {}\n" " Atk: {}\n" " Def: {}\n" " SpAtk: {}\n" " SpDef: {}\n" " Speed: {}\n" "Type: {}/{}\n" "WeightClass: {}\n" "Size: {}\n" "Sex: {}\n" "Capture Rate: {}\n" "Exp Drop: {}\n" "Capabilities: {}\n" " Int: {}\n" " Power: {}\n" " Overland: {}\n" " Surface: {}\n" " Underwater: {}\n" " Sky: {}\n" " Burrow: {}\n" " Jump: {}\n" " Capability Name: {}\n" " {}\n") return output.format(self.name, self.finalHPtotal, self.shiny, Nature(self.nature), "", Ability((self.ability_id, )), "", self.HP, self.Atk, self.Def, self.SpAtk, self.SpDef, self.Speed, "", self.finalHP, self.finalAtk, self.finalDef, self.finalSpAtk, self.finalSpDef, self.finalSpeed, self.Type1, self.Type2, self.WeightClass, self.Size, self.Sex(), self.caprate, self.exp * self.level, "", self.Int, self.Power, self.Overland, self.Surface, self.Underwater, self.Sky, self.Burrow, self.Jump, self.capability_name, self.capability_desc)
def create_ability(self): #prompty used for ability information name = "" while len(name) < 1: name = input("What is the ability name? ") max_damage = 0 while max_damage < 1: max_damage = input("What is the max damage of the ability? ") try: max_damage = int(max_damage) print(f"{name} has been added.") break except (ValueError, TypeError): max_damage = 0 print("Please enter a number.") return Ability(name, max_damage)
def test_hero_ability_attack_standard_deviation(): willow_waffle = Hero("Willow Waffle") strength = random.randint(400, 30000) willow = Ability("Willowness", strength) willow_waffle.add_ability(willow) attacks = list() total_attack = 0 number_tests = 1000 for _ in range(number_tests): cur_attack = willow_waffle.attack() attacks.append(cur_attack) total_attack += cur_attack mean = total_attack / number_tests # Get Square Deviations for index, value in enumerate(attacks): attacks[index] = math.pow(value - mean, 2) standard_dev = math.sqrt(sum(attacks) / len(attacks)) print("Standard Deviation Cannot be 0.\nRandom Numbers not generated for attack.") assert standard_dev != 0.0
if not self.is_alive(): print(f"\n{self.name} has been defeated by {opponent.name}\n". upper()) elif not opponent.is_alive(): print(f"\n{opponent.name} has been defeated by {self.name}\n". upper()) else: print("Draw!") #print(f'{random.choice(hero_choice)} wins!') def is_alive(self): #checks to see if the hero is still alive if self.current_health <= 0: return False else: return True if __name__ == "__main__": my_hero = Hero('Grace Hopper', 200) hero1 = Hero('Dumbledore', 200) ability = Ability("Shmoove", 25) ability2 = Ability("Ice", 15) ability3 = Ability("Laugh", 30) shield = Armor("Shield", 50) my_hero.add_ability(ability) hero1.add_ability(ability2) my_hero.add_ability(ability3) my_hero.add_armor(shield) my_hero.fight(hero1) #hero1.fight(hero2)
def create_ability(self): name = input("What is the ability name? ") max_damage = input("What is the max damage of the ability? ") return Ability(name, max_damage)
def create_ability(self): '''Prompt for Ability information. return Ability with values from user Input ''' name = input("What is the ability name? ") max_damage = input( "What is the max damage of the ability? ") return Ability(name, max_damage) def create_weapon(self): '''Prompt user for Weapon information return Weapon with values from user input. ''' weapon_name = input("what is the name of your weapon") weapon_description = input("What does this weapon do?") return Weapon(weapon_name, weapon_description) def create_armor(self): '''Prompt user for Armor information return Armor with values from user input. ''' armor_name = input("what piesce of armor do you want") armor_specs = input("what materails do you need") return Armor(armor,armor_specs) def create_hero(self): '''Prompt user for Hero information return Hero with values from user input. ''' hero_name = input("Hero's name: ") hero = Hero(hero_name) add_item = None while add_item != "4": add_item = input("[1] Add ability\n[2] Add weapon\n[3] Add armor\n[4] Done adding items\n\nYour choice: ") if add_item == "1": ability = self.create_ability() hero.create_ability() elif add_item == "2": weapon = self.create_weapon() hero.create_weapon() elif add_item == "3": armor = self.create_armor() hero.create_armor() return hero def build_team_one(self): '''Prompt the user to build team_one ''' numOfTeamMembers = int(input("How many members would you like on Team One?\n")) for i in range(numOfTeamMembers): hero = self.create_hero() self.team_one.add_hero(hero) def build_team_two(self): '''Prompt the user to build team_two''' numOfTeamMembers2 = int(input("How many members would you like on Team two?\n")) for i in range(numOfTeamMembers2): hero = self.create_hero() self.team_two.add_hero(hero) def team_battle(self): '''Battle team_one and team_two together.''' team_one.attack(team_two) def show_stats(self): '''Prints team statistics to terminal.''' print("\n") print(self.team_one.name + " statistics: ") self.team_one.stats() print("\n") print(self.team_two.name + " statistics: ") self.team_two.stats() print("\n") # This is how to calculate the average K/D for Team One team_kills = 0 team_deaths = 0 for hero in self.team_one.heroes: team_kills += hero.kills team_deaths += hero.deaths if team_deaths == 0: team_deaths = 1 print(self.team_one.name + " average K/D was: " + str(team_kills/team_deaths)) # Now display the average K/D for Team Two team_kills = 0 team_deaths = 0 for hero in self.team_two.heroes: team_kills += hero.kills team_deaths += hero.deaths if team_deaths == 0: team_deaths = 1 print(self.team_two.name + " average K/D was: " + str(team_kills/team_deaths)) # Here is a way to list the heroes from Team One that survived for hero in self.team_one.heroes: if hero.deaths == 0: print("survived from " + self.team_one.name + ": " + hero.name) #Now list the heroes from Team Two that survived for hero in self.team_two.heroes: if hero.deaths == 0: print("survived from " + self.team_two.name + ": " + hero.name) if __name__ == "__main__": game_is_running = True # Instantiate Game Arena arena = Arena() #Build Teams arena.build_team_one() arena.build_team_two() while game_is_running: arena.team_battle() arena.show_stats() play_again = input("Play Again? Y or N: ") #Check for Player Input if play_again.lower() == "n": game_is_running = False else: #Revive heroes to play again arena.team_one.revive_heroes() arena.team_two.revive_heroes()git
def __init__(self): super().__init__(prerequisite=AbilityRequirement( Ability(name=ABILITY.INT, base=13), Ability(name=ABILITY.WIS, base=13)))
def new_ability(ability_id, inventory): if ability_dict.get(ability_id) is not None: return ability_dict[ability_id](inventory) return Ability(ability_id, inventory)
def __init__(self): super().__init__(prerequisite=AbilityRequirement( Ability(name=ABILITY.DEX, base=20)), )
# This is just to gen a single mon For right now I am gonna quick and dirty copy and paste so I can use this tonight. Later I plan to put all the modules and classes in their own directory and import them from that location. import random, sys, sqlite3, getopt from collections import Counter from operator import itemgetter sys.path.insert(0, "modules/") from monmods import GetNature from monmods import Shiny from monmods import RareRoll from nature import Nature from pokemon import Pokemon from move import Move from ability import Ability ability = sys.argv[1] xability = (ability, ) # In order to use our move function to print out info about a move first we need to know the ID of the move. conn = sqlite3.connect('PTA_ORAS.db') data = conn.execute('SELECT id FROM ORAS_ability WHERE name=?', xability) for x in data: ability_id = x print Ability(ability_id)
self.kills += num_kills def add_death(self, num_deaths): ''' Update deaths with num_deaths''' self.deaths += num_deaths if __name__ == "__main__": hero1 = Hero("Grace Hopper", 200) hero1.take_damage(150) print(hero1.is_alive()) hero1.take_damage(15000) print(hero1.is_alive()) hero1 = Hero("Wonder Woman") hero2 = Hero("Dumbledore") ability1 = Ability("Super Speed", 300) ability2 = Ability("Super Eyes", 130) ability3 = Ability("Wizard Wand", 80) ability4 = Ability("Wizard Beard", 20) hero1.add_ability(ability1) hero1.add_ability(ability2) hero2.add_ability(ability3) hero2.add_ability(ability4) hero1.fight(hero2) hero = Hero("Wonder Woman") weapon = Weapon("Lasso of Truth", 90) hero.add_weapon(weapon) print(hero.attack())
def create_ability(self): # prompts for the info to make an ability + max_damage name = input("What is the ability name?") max_damage = input("What is the max damage of the ability?") return Ability(name, max_damage)
def test_ability_instance(): # Test instantiation without error big_strength = Ability("Overwhelming Strength", 300) assert big_strength
def test_ability_name(): # Test for Correct Name big_strength = Ability("Overwhelming Strength", 300) assert big_strength.name == "Overwhelming Strength"