def you_won(): global WON_MSG_SCREEN screen.fill(BLACK) display_message("AtariSmall.ttf", 30, 'YOU SAVED THE HUMAN RACE!! Play again? [y]/[n]', 30, 350) pygame.display.flip() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_n or event.key == pygame.K_ESCAPE: pygame.quit() quit() if event.key == pygame.K_y: for alien in alien_vessels_list: alien.kill() alien_generator(GREEN) global hero_spaceship hero_spaceship = Hero(WHITE, hero_height, hero_width, hero_health) hero_spaceship.rect.x = 350 hero_spaceship.rect.y = 700 all_sprites_list.add(hero_spaceship) WON_MSG_SCREEN = False return WON_MSG_SCREEN
def create_hero(weapons=False, armors=False, health=False): heroes = [ "Athena", "Jodie Foster", "Christina Aguilera", "Gamora", "Supergirl", "Wonder Woman", "Batgirl", "Carmen Sandiego", "Okoye", "America Chavez", "Cat Woman", "White Canary", "Nakia", "Mera", "Iris West", "Quake", "Wasp", "Storm", "Black Widow", "San Luis Obispo", "Ted Kennedy", "San Francisco", "Bananas" ] name = heroes[random.randint(0, len(heroes) - 1)] if health: power = health else: power = random.randint(3, 700000) hero = Hero(name, power) if weapons and armors: for weapon in weapons: hero.add_ability(weapon) for armor in armors: hero.add_armor(armor) if armors and not weapons: for armor in armors: hero.add_armor(armor) return hero
def setUp(self): self.h = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2) self.enemy = Enemy(_health=100, _mana=100, _damage=20)
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_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 __init__(self): self.is_playing = False self.all_players = pygame.sprite.Group() self.hero = Hero(self) self.all_players.add(self.hero) self.all_zombies = pygame.sprite.Group() self.pressed = {}
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 setUp(self): self.d = Dungeon('dungeon1.txt') self.test_hero = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=5)
def change_essences(self): essences.clear() for es in self.data: if es["type"] == "hero": essences.append( Hero(es["name"], es['health'], es['damage'], es['location'], es['texture'], es["gold"])) essences[-1].mainHero = es["code"] == self.your_hero_id essences[-1].move_distance = es["move"] essences[-1].maxGold = es["maxGold"] essences[-1].invisible = es["invise"] essences[-1].level.level = es["level"][0] essences[-1].level.exp = es["level"][1] essences[-1].level.max_exp = es["level"][2] essences[-1].level.lvl_points = es["lvl_points"] elif es["type"] == "essence": essences.append( Being(es["name"], es['health'], es['damage'], es['location'], es['texture'], es['gold'])) if es["code"] == self.your_hero_id: essences[-1].name = self.nick self.alive = True print("DHJLT YJHV") essences[-1].essence_code = es["code"] essences[-1].maxHealth = es["maxHealth"] essences[-1].shield = es["shield"] essences[-1].maxShield = es["maxShield"]
def run_game(): pygame.init() # intitialize all the pygame modules game_settings = Settings() screen = pygame.display.set_mode( game_settings.screen_size) # Set the screen size with set_mode pygame.display.set_caption( "Monster Attack") # set teh message on the status bar hero = Hero( screen) # set a variable equal to the class and pass it the screen bullets = Group() #set the bullets to group bad_guy = Group() bad_guy.add(Bad_guy(screen)) tick = 0 while 1: # run this loop forever... gf.check_events( hero, bullets, game_settings, screen ) # call gf (aliased for game_functions module) and get the check_events method hero.update() #update the hero location bad_guy.update(hero, game_settings.enemy_speed) groupcollide(bullets, bad_guy, True, True) tick += 1 if tick % 150 == 0: bad_guy.add(Bad_guy(screen)) bullets.update() # call the update method in the while loop gf.update_screen(game_settings, screen, hero, bullets, bad_guy) # call the update_screen for bullet in bullets: #get rid of bullets that are off the screen if bullet.rect.left <= 1000: #bullet bottom is at the top of the screen bullets.remove(bullet) #call remove() against the group
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": self.create_ability() hero.add_ability(self.create_ability()) elif add_item == "2": self.create_weapon() hero.add_weapon(self.create_weapon) elif add_item == "3": self.create_armor() hero.add_armor(self.create_armor) elif add_item == "4": break return hero
def __init__(self, client_socket, dungeon): self.connected = True self.can_receive = True self.can_send = True self.clientID = "" self.username = "******" # Game states self.state = ClientInfo.LoginPanel self.current_hero = Hero(self, dungeon) # Queues self.input_queue = Queue() self.output_queue = Queue() self.client_socket = client_socket self.encryption_key = b"ATERRIBLEKEYYYYY" # must match key in client and be 16 chars # client_receive_thread starter client_receive_thread = threading.Thread( target=ClientInfo.receive_thread, args=(self, )) client_receive_thread.start() # client_send_thread starter client_send_thread = threading.Thread(target=ClientInfo.send_thread, args=(self, )) client_send_thread.start()
def run_game(): pygame.display.init() pygame.display.set_caption("Air Battle") screen = pygame.display.set_mode((480, 852)) background = pygame.image.load("../images/background.png") settings = Settings() bullets = pygame.sprite.Group() hero = Hero(settings, screen, bullets) enemies = pygame.sprite.Group() enemy_bullets = pygame.sprite.Group() enemies_blowup = pygame.sprite.Group() while True: event_handler(settings, hero) hero.update() handle_enemies(settings, screen, enemies, enemy_bullets) bullets.update() enemy_bullets.update() handle_enemies_hit(bullets, enemies, enemies_blowup) if not hero.is_hit: # hero hit by enemies or enemy_bullets handle_hero_hit(hero, enemies, enemy_bullets) screen_update(screen, background, hero, bullets, enemies, enemy_bullets, enemies_blowup) settings.counter += 1 if settings.counter == settings.max_count: settings.counter = 0
def test_hero_defense_mean_value(): athena = Hero("Athena") strength = random.randint(400, 30000) big_strength = Armor("Overwhelming Shield", strength) athena.add_armor(big_strength) calculated_mean = strength // 2 iterations = 8000 total_attack = 0 accepted_window = 400 for _ in range(iterations): attack_value = athena.defend() assert attack_value >= 0 and attack_value <= strength total_attack += attack_value actual_mean = total_attack / iterations print("Max Allowed: {}".format(strength)) print("Defenses Tested: {}".format(iterations)) print("Mean -- calculated: {} | actual: {}".format(calculated_mean, actual_mean)) print( "Acceptable deviation from mean: {} | Current deviation from mean: {}".format( accepted_window, abs( calculated_mean - actual_mean))) print( "Acceptable Min: {} | Acceptable Max: {}".format( actual_mean - accepted_window, actual_mean + accepted_window)) assert actual_mean <= calculated_mean + \ accepted_window and actual_mean >= calculated_mean - accepted_window
def main(): hero = Hero() goblin = Goblin() while goblin.alive() and hero.alive: hero.print_status() goblin.print_status() print() print("What do you want to do?") print("1. fight goblin") print("2. do nothing") print("3. flee") print("> ",) user_input = input() if user_input == "1": # Hero attacks goblin hero.attack(goblin) if goblin.health <= 0: print("The goblin is dead.") elif user_input == "2": pass elif user_input == "3": print("Goodbye.") break else: print("Invalid input %r" % user_input) if goblin.health > 0: # Goblin attacks hero goblin.attack(hero) if hero.health <= 0: print("You are dead.")
def test_simulate_fight_orc_win(self): orc_w = Orc("Winner", 300, 2) hero_l = Hero("Loser", 300, "TheLoser") wep = Weapon("Ubiec", 15, 0.5) orc_w.equip_weapon(wep) orc_fight = Fight(hero_l, orc_w) self.assertEqual(orc_fight.simulate_fight(), orc_fight._ORC_WINNER)
def __init__(self): self.area_number = 1 self.area = Area() self.hero = Hero() self.characters = self.create_characters() self.monsters = self.characters[1:] self.kill_count = 0
def test_simulate_fight_hero_win(self): orc_l = Orc("Loser", 300, 2) hero_w = Hero("Winner", 300, "TheWinner") wep = Weapon("Ubiec", 15, 0.5) hero_w.equip_weapon(wep) hero_fight = Fight(hero_w, orc_l) self.assertEqual(hero_fight.simulate_fight(), hero_fight._HERO_WINNER)
def create_hero(self): """Prompt user for Hero information. It will 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.add_ability(ability) elif add_item == "2": weapon = self.create_weapon() hero.add_weapon(weapon) elif add_item == "3": armor = self.create_armor() hero.add_armor(armor) return hero
def test_move_onto_an_obstacle_returns_false_but_others_true(self): h = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2) a = Dungeon.from_string('''..##.....T ..##..###. #.###E###E #.ES..###. ###.#####G''') a.spawn(h) moved_successfully1 = a.move_hero('down') moved_successfully2 = a.move_hero('right') moved_successfully3 = a.move_hero('left') moved_successfully4 = a.move_hero('up') moved_successfully5 = a.move_hero('right') moved_successfully6 = a.move_hero('right') moved_successfully7 = a.move_hero('right') self.assertTrue(moved_successfully1, "cannot move") self.assertFalse(moved_successfully2, "got onto an obstacle") self.assertFalse(moved_successfully3, "got onto an obstacle") self.assertTrue(moved_successfully4, "cannot move") self.assertTrue(moved_successfully5, "cannot move") self.assertTrue(moved_successfully6, "cannot move") self.assertFalse(moved_successfully7, "got onto an obstacle")
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 create_new_hero(hero_xml_element): parser = XMLParser() id = hero_xml_element.getAttribute('id') information = parser.create_info_object_with_attributes( hero_xml_element, Hero.keys) new_hero = Hero(id, information) return new_hero
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 __init__(self, map_name="level1", spawn_name="spawn1"): pygame.init() self.FPS = 60 self.BG_COLOR = pygame.Color("black") self.GAME_AREA_POS = Position(96, 32) self.GAME_AREA_SIZE = (15, 15) self.GAME_AREA_SIZE_PIXELS = (self.GAME_AREA_SIZE[0] * 16, self.GAME_AREA_SIZE[1] * 16) self.screen = pygame.display.set_mode( (self.GAME_AREA_SIZE_PIXELS[0] + self.GAME_AREA_POS.x, self.GAME_AREA_SIZE_PIXELS[1] + self.GAME_AREA_POS.y), pygame.SCALED) self.clock = pygame.time.Clock() self.hero = Hero() self.wait = False # Wait for something to end, stop character updates self.actions = [] # Map data self.map_surface = pygame.Surface(self.GAME_AREA_SIZE_PIXELS) self.tmx_data = None self.map_data = None self.map_layer = None self.map_sprite_group = None self.spawns = None self.impassables = None self.doors = None self.load_map(map_name, spawn_name)
def test_team_attack(): 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].health == 100 team_one.attack(team_two) assert team_two.heroes[0].health <= 0
def __init__(self): """Инициализирует игру и создает игровые ресурсы.""" global ai pygame.init() self.settings = Settings() if self.settings.fullscreen: self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) self.settings.screen_width = self.screen.get_rect().width self.settings.screen_height = self.screen.get_rect().height else: self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height)) pygame.display.set_caption("Alien Invasion") # Создание экземпляра для хранения игровой статистики. self.stats = GameStats(self) self.sb = Scoreboard(self) self.ship = Ship(self) self.hero = Hero(self.screen) self.bullets = pygame.sprite.Group() self.aliens = pygame.sprite.Group() self._create_fleet() self.play_button = Button(self, "Play")
def setUp(self): self.w = Weapon(name="The Axe of Destiny", damage=20) self.h = Hero(name="Bron", title="Dragonslayer", health=100, mana=100, mana_regeneration_rate=2)
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 enter(): global boss_exist, middle_boss_exist boss_exist = 0 middle_boss_exist = 0 global boss_gauge boss_gauge = 0 global hero global cursor global boss global boss_right_arm global boss_left_arm global enemy_genarate global middle_boss map = Map() cursor = Cursor() boss = Boss() boss_right_arm = Boss_right_arm() boss_left_arm = Boss_left_arm() middle_boss = Middle_boss() hero = Hero() hide_cursor() game_world.add_object(map, 0) enemy_genarate = Enemy_genarate() game_world.add_object(hero, 1) game_world.add_object(cursor, 4) game_world.add_object(enemy_genarate, 0)
def you_lost(): global LOST_MSG_SCREEN screen.fill(BLACK) display_message("AtariSmall.ttf", 30, 'Humanity is doomed. Continue? [y]/[n]', 50, 350) pygame.display.flip() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_n or event.key == pygame.K_ESCAPE: pygame.quit() quit() if event.key == pygame.K_y: for alien in alien_vessels_list: alien.kill() alien_generator(GREEN) global hero_spaceship del hero_spaceship hero_spaceship = Hero(WHITE, hero_height, hero_width, hero_health) hero_spaceship.rect.x = 350 hero_spaceship.rect.y = 700 all_sprites_list.add(hero_spaceship) LOST_MSG_SCREEN = False return LOST_MSG_SCREEN