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 inputHeroName(): ''' The function that will create the hero and ask the user for a name ''' name = input("Input the name of the warrior") player = Hero(name) return player
def test_hero_weapon_attack_mean_value(): kkrunch = Hero("Kaptain Krunch") strength = random.randint(10, 30000) min_attack = strength // 2 big_strength = Weapon("Sword of Whimsy", strength) kkrunch.add_ability(big_strength) calculated_mean = (strength - min_attack) // 2 + min_attack accepted_window = 400 iterations = 6000 sum_of_sqr = 0 total_attack = 0 for _ in range(iterations): attack_value = kkrunch.attack() assert attack_value >= min_attack and attack_value <= strength total_attack += attack_value deviation = attack_value - calculated_mean sum_of_sqr += deviation * deviation 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 Min: {} | Acceptable Max: {}".format( actual_mean - accepted_window, actual_mean + accepted_window)) print("Tested Result: {}".format(actual_mean)) assert actual_mean <= calculated_mean + accepted_window assert actual_mean >= calculated_mean - accepted_window
def test_hero_properties_default(self): h = Hero() h.lvl = 7 h.maxHp = 100 h.nowHp = 75 h.maxXp = 40 h.nowXp = 20 h.gold = 100 h.attackLvl = 5 h.defenseLvl = 6 h.zoneVisitCounts = {ZoneDefinitionFields.ASTEROID_FIELD:3,ZoneDefinitionFields.CAVE:11} h.zone = Zone(ZoneDefinitionFields.EMPTY_SPACE) h.monster = Monster(MonsterDefinitionFields.AMBUSH_PIRATES) h.shipName = "USS KickAss" self.assertEqual(h.lvl,7) self.assertEqual(h.maxHp,100) self.assertEqual(h.nowHp,75) self.assertEqual(h.maxXp,40) self.assertEqual(h.nowXp,20) self.assertEqual(h.gold,100) self.assertEqual(h.attackLvl,5) self.assertEqual(h.defenseLvl,6) self.assertDictEqual(h.zoneVisitCounts,{ZoneDefinitionFields.ASTEROID_FIELD:3,ZoneDefinitionFields.CAVE:11}) self.assertEqual(h.zone.definitionKey,ZoneDefinitionFields.EMPTY_SPACE) self.assertEqual(h.monster.definitionKey,MonsterDefinitionFields.AMBUSH_PIRATES) self.assertEqual(h.shipName,"USS KickAss")
def lets_play(): command_list = [{ 'w': 'up', 's': 'down', 'a': 'left', 'd': 'right' }, 'f', 'spawn', 'status', 'u', 'p'] print('\nLets play a game!\n ') name = input('Write a name for your hero: ') title = input('How is your hero known as: ') h = Hero(name=name, title=title, health=100, mana=100, mana_regeneration_rate=2) name = input('Give a name to your weapon: ') w = Weapon(name=name, damage=20) h.equip(w) print('\n{} will fight with {} to save The Princess!\n'.format( h.known_as(), w.name)) input('Press enter to start the game!') map = Dungeon("level1.txt") map.spawn(h) map.print_map() input_data = input( "\nType w/s/a/d to move your hero up/down/left/right\ , f for fight, spawn for spawn, status to show hero's status, u for update spell/weapon or e for exitd: " ) while (input_data != 'e'): if input_data in command_list[0].keys(): map.move_hero(command_list[0][input_data]) map.print_map() elif input_data == command_list[1]: map.hero_attack() map.print_map() elif input_data == command_list[2]: map.spawn(h) map.print_map() elif input_data == command_list[3]: print('\n', h, h.weapon, h.spell) elif input_data == command_list[4]: which = input('Type spell/weapon: ') print( 'Are you sure. You have {} and the update is 20. Type y or n:' .format(map.hero.money)) result = input() if result == 'y': map.hero.update(which) else: print('Update not successful') elif input_data == 'm': print("\nType w/s/a/d to move your hero up/down/left/right\ , f for fight, spawn for spawn, status to show hero's status, u for update spell/weapon or e for exit" ) else: print('Comming soon!') print('Type m to see the curret command menu.') print('\n') input_data = input('Command: ')
def test(): import Room ### remove the monotany of recreating player name every time # link = create_player() link = Hero("linko") enemy = Room.create_opponent() zelda_battle(link, enemy)
def __init__(self): # 初始化pygame pygame.init() self.setting = Setting() self.offset = {pygame.K_LEFT: 0, pygame.K_RIGHT: 0, pygame.K_UP: 0, pygame.K_DOWN: 0} # 初始化游戏 self.screen = pygame.display.set_mode(self.setting.windows) # 初始化一个用于显示的窗口 pygame.display.set_caption('This is my first pygame-program') # 设置窗口标题 self.background = pygame.image.load('image/background.jpg') self.feiji = pygame.image.load('image/fj.png') self.bullet = pygame.image.load('image/bullet.png') self.enemy_img = pygame.image.load('image/enemy.png') self.gameover_img = pygame.image.load('image/gameover.jpg') self.pass_img = pygame.image.load('image/pass.jpg') # 创建敌人组 self.enemy_group = pygame.sprite.Group() # 创建击毁敌人组 self.enemy_down_group = pygame.sprite.Group() # 飞机出事位置 feiji_pos = [(self.setting.windows[0] - self.feiji.get_rect().width) / 2, self.setting.windows[1] - 100] # 飞机对象 self.heros = Hero(self.feiji, feiji_pos) # 限制游戏帧数 self.clock = pygame.time.Clock() # 重绘次数 self.ticks = 0 # 分数 self.makes = 0 # 最高分数 self.makesMax = 99999
def startGame(): print '************************************************' print '* H E R O Q U E S T * ' print '************************************************' print """ .-. {{@}} <> 8@8 .::::. 888 @\\\\/W\/\/W\//@ 8@8 \\\\/^\/\/^\// _ )8( _ \_O_<>_O_/ (@)__/8@8\__(@) ____________________ `~"-=):(=-"~` |<><><> | | <><><>| |.| |<> | | <>| |S| |<> | | <>| |'| |<> .--------. <>| |.| | | () | | |P| |_____| (O\/O) |_____| |'| | \ /\ / | |.| |------\ \/ /------| |U| | '.__.' | |'| | | | | |.| : | | : |N| \<> | | <>/ |'| \<> | | <>/ |.| \<> | | <>/ |K| `\<> | | <>/' |'| `-.| |.-` \ / '--' ^""" return Hero(raw_input("What is thy name brave hero?\n> "))
def test(self): myHero = Hero() self.assertEqual(myHero.name, 'Hero') self.assertEqual(myHero.experience, 0) self.assertEqual(myHero.health, 100) self.assertEqual(myHero.position, '00') self.assertEqual(myHero.damage, 5)
def main(): hero_name = input("Enter hero's name: ") hero_title = input("Enter hero's title: ") hero = Hero(hero_name, hero_title, 150, 150, 5) hero.equip(Weapon("Sword", 30)) hero.learn(Spell("KillALL", 35, 30, 3)) dungeon = Dungeon("map.txt", "basic_loot_list_example.json") dungeon.spawn(hero) dict_commands = {"mu": "up", "md": "down", "ml": "left", "mr": "right", "au": "up", "ad": "down", "al": "left", "ar": "right", "h": "help"} dict_commands_move = {"mu": "up", "md": "down", "ml": "left", "mr": "right"} dict_commands_attack = {"au": "up", "ad": "down", "al": "left", "ar": "right"} index_of_hero = [1, 1] print_commands() while not dungeon.end_of_game: dungeon.print_map() print() player_input = "" while player_input not in dict_commands.keys(): player_input = str(input(">>> ")) if player_input == "h": print_commands() if player_input in dict_commands_move.keys(): dungeon.move_hero(dict_commands_move[player_input]) if player_input in dict_commands_attack.keys(): dungeon.hero_atack(dict_commands_attack[player_input]) if dungeon.end_of_game: break
def main(): pat = Hero('Pat') gobbles = Goblin('gobbles') while gobbles.is_alive and pat.is_alive: # print("You have %d health and %d power." % (pat.health, pat.power)) print(pat.health_power_status()) # print("The gobbles has %d health and %d power." % (gobbles.health, gobbles.power)) print(gobbles.health_power_status()) print() print("What do you want to do?") print("1. fight gobbles") print("2. do nothing") print("3. flee") print("> ", ) user_input = input() if user_input == "1": pat.attack(gobbles) elif user_input == "2": pass elif user_input == "3": print("Goodbye.") break else: print("Invalid input %r" % user_input) if gobbles.health > 0: gobbles.attack(pat) pat.die() gobbles.die()
def setUp(self): self.hero = Hero("Gosho", 30, "Goshko") self.orc = Orc("Pesho", 100, 1.3) self.fight = Fight(self.hero, self.orc) self.weapon = Weapon("qax", 40, 0.3) self.hero.weapon = self.weapon self.orc.weapon = self.weapon
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 test_team_remove_unlisted(): # Test that if no results found return 0 team = Team("One") jodie = Hero("Jodie Foster") team.add_hero(jodie) code = team.remove_hero("Athena") assert code == 0
def test_team_remove_hero(): team = Team("One") jodie = Hero("Jodie Foster") team.add_hero(jodie) assert team.heroes[0].name == "Jodie Foster" team.remove_hero("Jodie Foster") assert len(team.heroes) == 0
def test_attack_with_spell_if_hero__doesnt_know_spell(self): h = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2) self.assertEqual(h.attack(by='magic'), 0)
def main(): my_map = Dungeon("basic_dungeon.txt") my_map.print_map() bron_hero = Hero("Bron", 100, "Broncho") my_orc = Orc("Orc", 80, 1.3) my_map.spawn("fdsfd", bron_hero) my_map.print_map()
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_check_for_enemy_down(self): d = Dungeon('map.txt', 'basic_loot_list_example.json') d.spawn(Hero("nz", "nz", 200, 120, 2)) d.hero.learn(Spell("idk", 20, 20, 2)) d.hero_place = [0, 5] d.change_map("H") result = d.check_for_enemy("down") self.assertEqual(result, 2)
def test_move_hero_(self): d = Dungeon('map.txt', 'basic_loot_list_example.json') d.spawn(Hero("nz", "nz", 200, 120, 2)) d.move_hero("right") d.move_hero("down") d.move_hero("right") d.move_hero("down") self.assertEqual(d.hero_place, [2, 1])
def test_take_healing_and_overflow_max(self): h = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2) h.take_healing(50) self.assertEqual(h.health, 100)
def test_attack_with_weapon_if_hero_doesnt_have_weapon(self): h = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2) damage = h.attack(by='weapon') self.assertEqual(damage, 0)
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 test_take_damage_and_die(self): h = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2) h.take_damage(120) self.assertEqual(h.health, 0)
def test_attack_without_weapon_or_spell(self): h = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2) damage = h.attack() self.assertEqual(damage, 0)
def test_take_healing_but_not_reach_max(self): h = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2) h.health = 10 h.take_healing(70) self.assertEqual(h.health, 80)
def test_can_cast_if_possible(self): h = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2) spell = Spell('abra kadabra', 30, 20, 2) h.learn(spell) self.assertTrue(h.can_cast())
def test_known_as(self): h = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2) expected = 'Bron the Dragonslayer' returned = h.known_as() self.assertEqual(returned, expected)
def test_learn_spell(self): h = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2) spell = Spell('abra kadabra', 30, 20, 2) h.learn(spell) self.assertEqual(h.spell, spell)
def test_equip_weapon(self): h = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2) wpn = Weapon('sword', 20) h.equip(wpn) self.assertEqual(h.equiped, wpn)