def battle(): dino_player_herd = Herd() robot_player_fleet = Fleet() print(dino_player_herd) print(robot_player_fleet) def dino_turn(): for dino in dino_player_herd.dinos: print( f'{dino.Name} has {dino.Health} health and {dino.Attack_Power} attack power' ) choice = input('\nWhich dino would you like to use to attack? ') for dino in dino_player_herd.dinos: if choice == dino.Name: for robot in robot_player_fleet.robots: print( f'{robot.Name} has {robot.Health} health and {robot.Attack_Power} attack power' ) target = input('\nWhich robot would you like to attack? ') for robot in robot_player_fleet.robots: if target == robot.Name: robot.damage_taken(dino.Attack_Power) if robot.Health < 1: robot_player_fleet.robots.pop( robot_player_fleet.robots.index(robot)) print(len(robot_player_fleet.robots)) def robot_turn(): for robot in robot_player_fleet.robots: print( f'{robot.Name} has {robot.Health} health and {robot.Attack_Power} attack power' ) choice = input('\nWhich robot would you like to use to attack? ') for robot in robot_player_fleet.robots: if choice == robot.Name: for dino in dino_player_herd.dinos: print( f'{dino.Name} has {dino.Health} health and {dino.Attack_Power} attack power' ) target = input('\nWhich dino would you like to attack? ') for dino in dino_player_herd.dinos: if target == dino.Name: dino.damage_taken(robot.Attack_Power) if dino.Health < 1: dino_player_herd.dinos.pop( dino_player_herd.dinos.index(dino)) print(len(dino_player_herd.dinos)) while len(dino_player_herd.dinos) != 0 or len( robot_player_fleet.robots) != 0: dino_turn() robot_turn() if len(dino_player_herd.dinos) == 0: print('Congrats RoboMan, You won!') else: print('Congrats DinoMan, You won!')
def __init__(self): self.fleet = Fleet() self.herd = Herd() self.dino_count = 0 self.robo_count = 0 self.fleet_health = 0 self.herd_health = 0 self.turn_arrow = '' for robo in self.fleet.robots: self.fleet_health += robo.health for dino in self.herd.dinos: self.herd_health += dino.health
def run_game(self): fleet = Fleet() herd = Herd() player = self.display_welcome() team_size = user_prompt( "How many on each team? Less than 10 please. :", 10) herd.create_herd(team_size) fleet.create_fleet(team_size, player) self.fleet = fleet self.herd = herd print("\n" * 10) display(self.fleet, self.herd) input("Press enter to start the game...") winner = None game_on = True while game_on: choice = None print("Your turn!\n") if player == 1: choice = self.show_robo_opponent_options() if choice != "skip": self.robo_turn(int(choice)) # Computer Turn print(f"Computer's turn!\n") self.dino_turn(1, 2) else: choice = self.show_dino_opponent_options() if choice != "skip": attack_type = user_prompt( "What type of attack?\n1: Slam (more damage, higher energy cost)\n2: Bite\n:", 2) self.dino_turn(int(choice), int(attack_type)) # Computer Turn print(f"Computer's turn!\n") self.robo_turn(1) # Check for dead if self.herd.dinosaurs[0].health <= 0: print(f"{self.herd.dinosaurs[0].type} has died!") self.herd.dinosaurs.remove(self.herd.dinosaurs[0]) if self.fleet.robots[0].health <= 0: print(f"{self.fleet.robots[0].name} has died!") self.fleet.robots.remove(self.fleet.robots[0]) if len(self.herd.dinosaurs) < 1: winner = "Robots Win!" game_on = False if len(self.fleet.robots) < 1: winner = "Dinosaurs Win!" game_on = False self.display_winner(winner)
def fight_sequence(self): robotOne = Fleet() dinosaurOne = Herd() turn = 'Dinosaur' while not robotOne.defeated() and not dinosaurOne.defeated(): if turn == 'Dinosaur': for robot in robotOne.robots: robot.health -= dinosaurOne.dinosaurs[0].attack_power turn = 'Robot' elif turn == 'Robot': for dinosaur in dinosaurOne.dinosaurs: dinosaur.health -= robotOne.robots[0].attack_power turn = 'Dinosaur' print("The dinosaurs won: ", robotOne.defeated()) print("The robots won: ", dinosaurOne.defeated())
def __init__(self): self.turn = 1 self.user_selector = 0 self.enemy_selector = 0 self.target = 0 self.fleet = Fleet() self.herd = Herd() self.user_choice = "" self.user = None self.enemy = None self.user_attacker = None self.enemy_attacked = None self.enemy_attacker = None self.user_attacked = None self.try_again = 0
def __init__(self): self.fleet = Fleet() self.herd = Herd() match_over = False while match_over: if Fleet.health == 0: match_over = True del self print('DINOSAURS WIN!') print('GAME OVER') elif Herd.health == 0: match_over = True print('ROBOTS WIN!') print('GAME OVER') del self
def get_herd(input_xml): yaks_list = list() root_element = XMLParser.fromstring(input_xml) if root_element.tag != 'herd': raise Exception('The root element must be "herd".') for element in root_element.iter('labyak'): yak_name = element.get('name') if yak_name is None: raise Exception('The "name" is not in labyak.') yak_age = element.get('age') if yak_age is None: raise Exception('The "age" is not in labyak.') yak_age = float(yak_age) * 100 yak_sex = element.get('sex') if yak_sex is None or yak_sex not in ['f', 'm']: raise Exception('The "sex" is not in labyak or is not m/f.') yak_sex = Sex.FEMALE if yak_sex == 'f' else Sex.MALE yaks_list.append(Yak(name=yak_name, age=yak_age, sex=yak_sex)) if len(yaks_list) == 0: raise Exception('No labyak in XML file.') return Herd(yaks_list)
from robots import Robot from dinosaurs import Dinosaur from fleet import Fleet from herd import Herd from battlefield import Battlefield r1 = Robot('WALL-E') r2 = Robot('T-800') r3 = Robot('Roomba') d1 = Dinosaur('Trogdor', 55) d2 = Dinosaur('Allosaurus', 42) d3 = Dinosaur('Spinosaurus', 55) Fleet(3) Fleet.create_fleet(r1) Fleet.create_fleet(r2) Fleet.create_fleet(r3) print(Fleet.robot_fleet) Herd(3) Herd.create_herd(d1) Herd.create_herd(d2) Herd.create_herd(d3) print(Herd.dinosaur_herd)
dino_two = Dinosaur("Stegosaurus") dino_two.attack_power = 60 # weapons.choose_attack(dino_two) dino_three = Dinosaur("Velociraptor") dino_three.attack_power = 85 # weapons.choose_attack(dino_three) #Fleet robot_fleet = Fleet() robot_fleet.add_to_fleet([robot_megaman, robot_marvin, robot_wally]) #print(robot_fleet.fleet) #Herd dino_herd = Herd() dino_herd.add_to_herd([dino_one, dino_two, dino_three]) # print(dino_herd.herd) for robot in robot_fleet.fleet[0]: weapons.choose_weapon(robot) for dinosaur in dino_herd.herd[0]: weapons.choose_attack(dinosaur) #Actions def battle(fleet, herd): counter = 0 for element in fleet: fleet_health = 0 for i in range(0, len(element)): fleet_health += element[i].health
def battle_action(): # NOTE: THIS REALLY SHOULD BE DONE USING A DATABASE OR AN ARRAY/LIST # RATHER THAN SEPARATE INSTANCES OF ROBOTS AND DINOSAURS. # AN ARRAY/LIST WOULD BE MUCH MORE EFFICIENT # Assemble the robots print('\n================================') robot1 = Robot('Able', 50, 50, 'Phaser').robot_attr_list() robot2 = Robot('Baker', 50, 50, 'Phaser').robot_attr_list() robot3 = Robot('Sarge', 125, 100, '').robot_attr_list() robot_fleet = Fleet('Armageddon') robot_fleet.assign_member(robot3.name, robot3.attack_power, robot3.health) robot_fleet.assign_member(robot1.name, robot1.attack_power, robot1.health) robot_fleet.assign_member(robot2.name, robot2.attack_power, robot2.health) robot_fleet.fleet_status() # Assemble the dinosaurs print('\n================================') dinosaur1 = Dinosaur('Triceratops', 75, 30, 'Bash').dino_attr_list() dinosaur2 = Dinosaur('Velociraptor', 50, 100, 'Tail whip').dino_attr_list() dinosaur3 = Dinosaur('T-Rex', 100, 70, '').dino_attr_list() dinosaur_herd = Herd('R-r-raw-R!') dinosaur_herd.add_member(dinosaur3.dino_type, dinosaur3.attack_power, dinosaur3.health) dinosaur_herd.add_member(dinosaur1.dino_type, dinosaur1.attack_power, dinosaur1.health) dinosaur_herd.add_member(dinosaur2.dino_type, dinosaur2.attack_power, dinosaur2.health) dinosaur_herd.herd_status() # Create the battle field water_loo = Battlefield('Water Loo') water_loo.side1_name = robot_fleet.name water_loo.side2_name = dinosaur_herd.name water_loo.side1_points = robot_fleet.defense_points water_loo.side2_points = dinosaur_herd.defense_points # Now fight battle_ended = False counter = 0 engagements = len(robot_fleet.members) water_loo.battle_status() print('\n\n ***** Battle commencing *****') detail_print = input('Do you wish to see the details? (y/n): ') while not battle_ended: side1_damage = 0 side2_damage = 0 damage1 = 0 # battle strikes happen here... # Individual engagements (eg. 1 vs 1, 2 vs 2, 3 vs 3) if (robot1.health > 0 and robot1.power_level > 0) and (dinosaur1.health > 0 and dinosaur1.energy > 0): robot_attack_damage = make_an_attack(robot1.attack_power) dino_attack_damage = make_an_attack(dinosaur1.attack_power) dinosaur1.update_health(robot_attack_damage).update_energy(10) robot1.update_health(dino_attack_damage).update_power_level(10) if detail_print == 'y': print(f'Robot {robot1.name} hits {dinosaur1.dino_type} for {robot_attack_damage} damage ' f'and it has {dinosaur1.health} health ' f'and {dinosaur1.energy} energy left.') print(f'The {dinosaur1.dino_type} hits {robot1.name} for {dino_attack_damage} damage ' f'and it has {robot1.health} health ' f'and {robot1.power_level} power left.\n') side1_damage += dino_attack_damage side2_damage += robot_attack_damage else: # One member has been defeated, the other may or may not be left standing. engagements -= 1 if (robot2.health > 0 and robot2.power_level > 0) and (dinosaur2.health > 0 and dinosaur2.energy > 0): robot_attack_damage = make_an_attack(robot2.attack_power) dino_attack_damage = make_an_attack(dinosaur2.attack_power) dinosaur2.update_health(robot_attack_damage).update_energy(10) robot2.update_health(dino_attack_damage).update_power_level(10) if detail_print == 'y': print(f'Robot {robot2.name} hits {dinosaur2.dino_type} for {robot_attack_damage} damage ' f'and it has {dinosaur2.health} health ' f'and {dinosaur2.energy} energy left.') print(f'The {dinosaur2.dino_type} hits {robot2.name} for {dino_attack_damage} damage ' f'and it has {robot2.health} health ' f'and {robot2.power_level} power left.\n') side1_damage += dino_attack_damage side2_damage += robot_attack_damage else: # One member has been defeated, the other may or may not be left standing. engagements -= 1 if (robot3.health > 0 and robot3.power_level > 0) and (dinosaur3.health > 0 and dinosaur3.energy > 0): robot_attack_damage = make_an_attack(robot3.attack_power) dino_attack_damage = make_an_attack(dinosaur3.attack_power) dinosaur3.update_health(robot_attack_damage).update_energy(10) robot3.update_health(dino_attack_damage).update_power_level(10) if detail_print == 'y': print(f'Robot {robot3.name} hit the {dinosaur3.dino_type} for {robot_attack_damage} damage ' f'and it has {dinosaur3.health} health ' f'and {dinosaur3.energy} energy left.') print(f'The {dinosaur3.dino_type} hit robot {robot3.name} for {dino_attack_damage} damage ' f'and it has {robot3.health} health ' f'and {robot3.power_level} power left.\n') side1_damage += dino_attack_damage side2_damage += robot_attack_damage else: # One member has been defeated, the other may or may not be left standing. engagements -= 1 water_loo.update_battle_status(side1_damage, side2_damage) if detail_print == 'y': water_loo.battle_status() counter += 1 # Check to see if either side has been wiped out or at a tactical advantage battle_ended = water_loo.battle_results(counter, engagements, detail_print) # Tactical advantage equals all engagements are complete (0). if engagements == 0: battle_ended = True elif counter > 15: # The soldiers are too wimpy and their hearts are in not in the fight! print('Battle has stalemated. Troops are going home.') battle_ended = True
def __init__(self): self.bot_fleet = Fleet() self.dino_herd = Herd() self.bot_fleet.create_robots() self.dino_herd.create_dinosaurs()
def __init__(self): self.dino_herd = Herd().dinosaurs self.robot_fleet = Fleet().robots self.robot_defeated = [] self.dinosaurs_defeated = []
from dinosaur import Dinosaur from herd import Herd from fleet import Fleet from battlefield import Battlefield star_fleet = Fleet("Star Fleet") star_fleet.create_fleet() the_dinos = Herd("The Dinos") the_dinos.create_herd()
def __init__(self): self.fleet = Fleet().robots self.herd = Herd().dinosaurs
def initialize_battle(): #Weapons List weapons = Weapons() #Fighters marvin = Robot('Marvin') megaman = Robot('Megaman') wall_E = Robot('Wall-e') stegosaurus = Dinosaur('Stegosaurus') velociraptor = Dinosaur('Velociraptor') tyrannosaurus = Dinosaur('Tyrannosaurus') #Select Weapon/Attack weapons.choose_weapon(marvin) weapons.choose_weapon(megaman) weapons.choose_weapon(wall_E) weapons.choose_attack(stegosaurus) weapons.choose_attack(velociraptor) weapons.choose_attack(tyrannosaurus) #Robots marvin.power_level = 120 marvin.attack_power = 70 megaman.power_level = 110 megaman.attack_power = 100 wall_E.power_level = 100 wall_E.attack_power = 60 #Dinos stegosaurus.attack_power = 60 velociraptor.attack_power = 80 tyrannosaurus.attack_power = 100 #Fleet robot_fleet = Fleet() robot_fleet.add_to_fleet([marvin, megaman, wall_E]) # print(robot_fleet.fleet) #Herd dino_herd = Herd() dino_herd.add_to_herd([stegosaurus, velociraptor, tyrannosaurus]) # print(dino_herd.herd) #Display fighters and battlefield display(battlefield) # --- Fighters will attack each other randomly, last fighter standing wins!--- def battle(fleet, herd): counter = 0 for element in fleet: fleet_health = 0 for i in range(0, len(element)): fleet_health += element[i].health for obj in herd: herd_health = 0 for a in range(0, len(obj)): herd_health += obj[a].health while counter <= 100 or fleet_health <= 0 or herd_health <= 0: n = random.randint(0, 2) i = random.randint(0, 2) obj[n].attack_robo(element[n]) element[n].attack_dino(obj[i]) counter += 1 battle(robot_fleet.fleet, dino_herd.herd) #Stats print(wall_E) print(megaman) print(marvin) print(stegosaurus) print(velociraptor) print(tyrannosaurus) def conclude_battle(robot_fleet, dino_herd): for element in robot_fleet.fleet: count = 0 while count <= len(element): for robot in element: if robot.status == 'Defeated' or robot.status == 'Resting': element.remove(robot) count += 1 if len(element) == 0: return ctypes.windll.user32.MessageBoxW( 0, 'Battle concluded: Dinos have won!', 'Robots vs Dinosaurs', 64) for element in dino_herd.herd: count = 0 while count <= len(element): for dino in element: if dino.health <= 0 or dino.status == 'Resting': element.remove(dino) count += 1 if len(element) == 0: return ctypes.windll.user32.MessageBoxW( 0, 'Battle concluded: Robos have won!', 'Robots vs Dinosaurs', 64) return ctypes.windll.user32.MessageBoxW(0, 'Battle is Ongoing!', 'Robots vs Dinosaurs', 64) conclude_battle(robot_fleet, dino_herd)
def __init__(self): self.fleet = Fleet() self.herd = Herd() self.turn = "robot" self.run = False self.winner = ''
def __init__(self): self.fleet = Fleet() self.herd = Herd()
from fleet import Fleet from herd import Herd dinosaur_herd = Herd() robot_fleet = Fleet() class Battlefield: robot_fleet.robot_fleet_health() dinosaur_herd.dinosaur_herd_health()