def action(self): factory = self.__outer.unit() garrison = factory.structure_garrison() if garrison: direction = random.choice(list(bc.Direction)) if self.__outer._gc.can_unload(factory.id, direction): self.__outer._gc.unload(factory.id, direction) location = factory.location.map_location().add(direction) unit = self.__outer._gc.sense_unit_at_location(location) if unit: # TODO: Add other unit types' tree containers strategy.Strategy.getInstance().removeInProduction( unit.unit_type) strategy.Strategy.getInstance().addUnit(unit.unit_type) if unit.unit_type == bc.UnitType.Worker: self.__outer._my_units.append( Worker(unit.id, self.__outer._gc, self.__outer._maps, self.__outer._my_units)) elif unit.unit_type == bc.UnitType.Knight: self.__outer._my_units.append( Knight(unit.id, self.__outer._gc)) elif unit.unit_type == bc.UnitType.Healer: self.__outer._my_units.append( Healer(unit.id, self.__outer._gc, self.__outer._maps)) elif unit.unit_type == bc.UnitType.Ranger: self.__outer._my_units.append( Ranger(unit.id, self.__outer._gc)) elif unit.unit_type == bc.UnitType.Mage: self.__outer._my_units.append( Mage(unit.id, self.__outer._gc, self.__outer._maps)) self._status = bt.Status.SUCCESS
def main(): seed(datetime.now()) orcs = [ Character("Orc-" + str(i + 1), Equipment(uniform(1.1, 1.5), uniform(1.1, 1.3)), 2, randrange(4)) for i in range(5) ] orcs += [ Tank("Orc Tank" + str(i + 1), Equipment(uniform(1.1, 1.5), uniform(1.1, 1.3)), 2, randrange(4)) for i in range(5) ] night_elves = [ Character("Night Elf" + str(i + 1), Equipment(uniform(1.1, 1.5), uniform(1.1, 1.3)), 3, randrange(3)) for i in range(3) ] night_elves += [ Mage("Night Elf Mage" + str(i + 1), Equipment(uniform(1.1, 1.5), uniform(1.1, 1.3)), 2, randrange(4)) for i in range(5) ] a = Arena(orcs, night_elves) a.play()
def stage_three(self) -> None: """ Sets up stage two :return: none """ # transition self.transition = arcade.load_texture("images/level_3_screen.png") # setting up player self.player = Player(50, 50) # setting up enemies self.enemies_engine = [] self.towers_engine = [] self.enemies = Sprites() self.towers = Sprites() self.obstacles = arcade.SpriteList() self.enemies.append(Slime(750, 700)) self.enemies.append(Executioner(750, 700, 10)) self.enemies.append(Slime(750, 100)) self.enemies.append(Executioner(750, 100, 10)) self.enemies.append(Slime(80, 700)) self.enemies.append(Executioner(80, 700, 10)) self.enemies.append(Executioner(400, 400, 20)) for enemy in self.enemies: self.enemies_engine.append( CollisionDetection(enemy, self.obstacles)) # self.towers.append(WizardTower(400, 300, 48, 52)) # self.towers.append(WizardTower(400, 500, 48, 52)) self.towers.append(Mage(300, 400, 48, 52)) self.towers.append(Mage(500, 400, 48, 52)) for tower in self.towers: self.towers_engine.append( CollisionDetection(tower.fireball, self.rooms[self.world].wall_list)) self.enemies.append(tower.fireball) for item in self.rooms[self.world].wall_list: self.obstacles.append(item) for item in self.rooms[self.world].traps_list: self.obstacles.append(item) # create engines self.player_engine = CollisionDetection(self.player, self.rooms[self.world].wall_list, self.rooms[self.world].traps_list)
def robotPlayer(self): robotClass = str((randint(1, 2))) if robotClass == str(1): roboClass = Mage() print("Computer:") roboClass.robotAttack() elif robotClass == str(2): roboClass = Monster() print("Computer:") roboClass.robotAttack()
def getCharacter(): print("Warrior Mage Ranger") character = None answer = raw_input("Answer:") if answer.lower() in ['w','warrior']: character = Warrior() if answer.lower() in ['m','mage']: character = Mage() #Character("mage") if answer.lower() in ['r','ranger']: character = Ranger() #Character("ranger") if answer.lower() in ['quit','q']: sys.exit() return character
def take_turn(self, offensive_units): #[Unit] => void all_enemies = self.gc.sense_nearby_units_by_team( bc.MapLocation(self.gc.planet(), 0, 0), 1000000, Helper.get_opposing_team(self.gc.team())) if len(all_enemies) > 0: self.rally_point = all_enemies[0].location.map_location() self.on_alert = True else: self.rally_point = self.get_default_rally_point() self.on_alert = False for unit in offensive_units: soldier = self.unit_info.get(unit.id) if soldier is None: if unit.unit_type == bc.UnitType.Knight: soldier = Knight(self.gc, self.intel_map, self.mov, self.astro, Role.Attack, unit) elif unit.unit_type == bc.UnitType.Ranger: soldier = Ranger(self.gc, self.intel_map, self.mov, self.astro, Role.Attack, unit) elif unit.unit_type == bc.UnitType.Mage: soldier = Mage(self.gc, self.intel_map, self.mov, self.astro, Role.Attack, unit) elif unit.unit_type == bc.UnitType.Healer: soldier = Healer(self.gc, self.intel_map, self.mov, self.astro, Role.Attack, unit, self) else: soldier = Soldier(self.gc, self.intel_map, self.mov, self.astro, Role.Scout, unit) soldier.set_rally_point(self.rally_point) self.unit_info[unit.id] = soldier if self.gc.planet() == bc.Planet.Mars: soldier.set_role(Role.Scout) soldier.set_rally_point(self.rally_point) soldier.take_turn(unit, self.on_alert) #Carry out soldier move soldier.move_and_attack()
def take_extra_turn(self, unit): # Unit => void if (self.gc.can_sense_unit(unit.id)): unit = self.gc.unit(unit.id) else: print("Commander: Can't sense soldier !!") #print("Commander: Overcharged unit attack heat is: " + str(unit.attack_heat())); soldier = self.unit_info.get(unit.id) if soldier is None: if unit.unit_type == bc.UnitType.Knight: soldier = Knight(self.gc, self.intel_map, self.mov, self.astro, Role.Attack, unit) elif unit.unit_type == bc.UnitType.Ranger: soldier = Ranger(self.gc, self.intel_map, self.mov, self.astro, Role.Attack, unit) elif unit.unit_type == bc.UnitType.Mage: soldier = Mage(self.gc, self.intel_map, self.mov, self.astro, Role.Attack, unit) elif unit.unit_type == bc.UnitType.Healer: soldier = Healer(self.gc, self.intel_map, self.mov, self.astro, Role.Attack, unit, self) if not (soldier is None): soldier.take_turn(unit, self.on_alert) soldier.move_and_attack()
def room_tutorial(self) -> None: """ loads room tutorial :return: none """ # setting up player self.player = Player(50, 50) # setting up enemies self.enemies_engine = [] self.towers_engine = [] self.enemies = Sprites() self.towers = Sprites() self.obstacles = arcade.SpriteList() self.enemies.append(Slime(750, 750)) self.enemies.append(Slime(750, 50)) self.enemies.append(Slime(50, 750)) self.enemies.append(Executioner(750, 750, 3)) self.enemies.append(Executioner(750, 50, 3)) self.enemies.append(Executioner(50, 750, 3)) self.enemies.append(Slime(400, 400)) self.enemies.append(Executioner(400, 400, 3)) for enemy in self.enemies: self.enemies_engine.append( CollisionDetection(enemy, self.obstacles)) self.towers.append(Mage(400, 400, 48, 52)) for tower in self.towers: self.towers_engine.append( CollisionDetection(tower.fireball, self.rooms[self.world].wall_list)) self.enemies.append(tower.fireball) for item in self.rooms[self.world].wall_list: self.obstacles.append(item) for item in self.rooms[self.world].traps_list: self.obstacles.append(item) # create engines self.player_engine = CollisionDetection(self.player, self.rooms[self.world].wall_list, self.rooms[self.world].traps_list)
def onePlayer(self): playerOne = (input( "Which class would you like to play? Press 1 for a Mage, 2 for a Monster or 3 to hear about both classes!" )) if playerOne == str(1): playClass = Mage() self.robotPlayer() print("Player 1:") playClass.humanAttack() elif playerOne == str(2): playClass = Monster() self.robotPlayer() print("Player 1:") playClass.humanAttack() elif playerOne == str(3): print( "The Mage is has higher health but his attacks are more random in damage." ) print( "The Monster has lower health, but his attacks are consistant." ) self.onePlayer() else: self.onePlayer()
return def drawText(text, font, surface, x, y): textobj = font.render(text, 1, WHITE) textrect = textobj.get_rect() textrect.topleft = (x, y) surface.blit(textobj, textrect) #This will be a list that will contain all the sprites we intend to use in our game. all_sprites_list = pygame.sprite.Group() baddie_sprites_list = pygame.sprite.Group() spell_sprites_list = pygame.sprite.Group() playerMage = Mage(BLACK, 20, 30) playerMage.rect.x = 200 playerMage.rect.y = 300 all_sprites_list.add(playerMage) # The loop will carry on until the user exit the game (e.g. clicks the close button). carryOn = True # The clock will be used to control how fast the screen updates clock = pygame.time.Clock() spell = [] direction = [] kills = 0 baddies = [] max_Baddies = 10 baddie_Counter = 0 previous_time = pygame.time.get_ticks()
#num_secs = 0 # Keeping track of the number of steps #time_step_resolution = 0.1 # How many seconds each step is #seconds_to_run = 20 # Time simulator runs in seconds #GCD = 1.5 # in seconds if __name__ == "__main__": print("Starting WoW Classic DPS Simulator Version 0.01...") g_vars = Global_Vars() g_vars.init() if "-spec" in sys.argv: spec = sys.argv[sys.argv.index("-spec") + 1] else: spec = "Frost" if "-spell_priority" in sys.argv: spell_priority = sys.argv[sys.argv.index("-spell_priority") + 1].split(',') else: spell_priority = ['Fire Blast r7','Frostbolt r11','Arcane Explosion r1','Fireball r1'] print("Running sim for " + str(spec) + " mage...") print("Running for " + str(g_vars.seconds_to_run) + " seconds...") player = Mage(spec,spell_priority,g_vars) while int(g_vars.num_secs) != g_vars.seconds_to_run: player.run_step() g_vars.num_secs = g_vars.num_secs + g_vars.time_step_resolution print("Mana left: " + str(player.mana)) print("Your DPS is: " + str(player.damage / g_vars.seconds_to_run)) print("Your mana efficiency: " + str((player.damage/player.mana_spent)))
self.Champ_1() self.Champ_2() self.attack(self.h_2.display_battle_stats) if self.h_1.health <= 0 or self.h_2.health <= 0: if self.h_1.health > 0: self.text_screen("Player 1 WINS!!", None, 250, 150) elif h_2.health > 0: self.text_screen("Player 1 WINS!!", None, 300, 180) if self.h_1.health > 0: self.print_screen("Player 1 Attacking", 260, 200) sleep(2) if self.h_2.health > 0: self.print_screen("Player 2 Attacking", 280, 230) sleep(2) pygame.display.update() p1 = Mage("Sasuke", 1, 1) print(p1) p2 = Fighter("Pekka", 1, 1) print(p2) h = Game(p1, p2) h.game_intro() game_loop() pygame.quit() quit()
for x in directions: if gc.can_harvest(unit.id, x): gc.harvest(unit.id, x) continue if gc.round() < 10 and gc.can_replicate(unit.id, x): gc.replicate(unit.id, x) continue if(random.random() < 0.5): hs = HarvestStrategy(bc,gc,gd,unit) hs.move() if unit.unit_type == bc.UnitType.Mage: # for x in directions: #random movement for now # if gc.is_move_ready(unit.id) and gc.can_move(unit.id, x) and move == 0: # gc.move_robot(unit.id, x) m = Mage(gc, unit) if unit.location.is_in_garrison() == False: m.target() # first, let's look for nearby blueprints to work on location = unit.location if location.is_on_map(): nearby = gc.sense_nearby_units(location.map_location(), 1000) #m = MapLocation for other in nearby: if unit.unit_type == bc.UnitType.Worker and gc.can_build(unit.id, other.id): gc.build(unit.id, other.id) move = 1; # print('built a factory!') print(other.unit_type)
from fighter import Fighter from mage import Mage from rogue import Rogue from champ import Champ from base import Base from time import sleep battle = __import__('battle').battle create_champ = __import__('create_champ').create_champ if __name__ == '__main__': """obj = tuple() obj = create_champ() print(obj)""" name = "Andrew" race = "Human" gender = "Male" element = "Void" """dic = Fighter.load_from_file("Andrew") p1 = Fighter("Dummy", 1, 1) p1.update(**dic) p1.level_up() p1.increase_stats(health=1, defence=1, armor=1)""" p1 = Mage(name, race, gender, element) p2 = Fighter("Sasuke", "Elf", "Male", "Arc") """print(p1, end="\n") print(p2, end="\n")""" battle(p1, p2)
def __init__(self, _engine): super(Scene, self).__init__(_engine) self.side = utils.loadImage('data/gfx/side.png') self._background = pygame.Surface((self._resx, self._resy)) self._background.blit(self.side, (self._resx - 232, self._resy - 1500)) self.surface = self._background.copy() self._actual = [] self._level = utils.loadLevel('data/level.dat') self._map = Map(_engine, self, self._level) self._minimap = Minimap(_engine, self._map) self._cursor = Cursor(_engine, self._map) self._creatureLayer = CreatureLayer(self._map, self._cursor) # Warstwa potworów self._map.addLayer('Creatures', 2, self._creatureLayer) self._map.addLayer('Missiles', 3, MissilesLayer( self._map)) # Warstwa pocisków(strzał, kuli ognia itp.) self._shadow = ShadowLayer(self._map) self._map.addLayer('Shadow', 5, self._shadow) # Mgła wojny self._monsters = [] self._freeobjects = pygame.sprite.Group() # Wolne obiekty na scenie _counter = 0 _start = 0 # szukanie bohatera w lochu for l, storey in enumerate(self._level): for row in storey: for cell in row: if cell.getModifier() & field.MODIFIER_HERO: self._hero = hero.Hero(self._map, cell.getGrid() + (l, )) self._hero.move((0, 0, 0)) self._map.switchStorey(l) _start = l self._creatureLayer.add( 'hero', self._hero.getSprite(self._creatureLayer, 'hero')) break # szukanie potworów for l, storey in enumerate(self._level): for row in storey: for cell in row: if cell.getModifier() & field.MODIFIER_SPIDER: _monster = Spider(self._map, cell.getGrid() + (l, )) self._monsters.append(('spider', _monster)) if l == _start: self._creatureLayer.add( 'spider_' + str(_counter), _monster.getSprite(self._creatureLayer, 'spider_' + str(_counter))) self._actual.append( ('spider_' + str(_counter), _monster)) _monster.move((0, 0, 0)) _counter += 1 elif cell.getModifier() & field.MODIFIER_SKELETON: _monster = Skeleton(self._map, cell.getGrid() + (l, )) self._monsters.append(('skeleton', _monster)) if l == _start: self._creatureLayer.add( 'skeleton_' + str(_counter), _monster.getSprite(self._creatureLayer, 'skeleton_' + str(_counter))) self._actual.append( ('skeleton_' + str(_counter), _monster)) _monster.move((0, 0, 0)) _counter += 1 elif cell.getModifier() & field.MODIFIER_MAGE: _monster = Mage(self._map, cell.getGrid() + (l, )) self._monsters.append(('mage', _monster)) if l == _start: self._creatureLayer.add( 'mage_' + str(_counter), _monster.getSprite(self._creatureLayer, 'mage_' + str(_counter))) self._actual.append( ('mage_' + str(_counter), _monster)) _monster.move((0, 0, 0)) _counter += 1 elif cell.getModifier() & field.MODIFIER_TROLL: _monster = Troll(self._map, cell.getGrid() + (l, )) self._monsters.append(('troll', _monster)) if l == _start: self._creatureLayer.add( 'troll_' + str(_counter), _monster.getSprite(self._creatureLayer, 'troll_' + str(_counter))) self._actual.append( ('troll_' + str(_counter), _monster)) _monster.move((0, 0, 0)) _counter += 1 if not self._hero: raise Exception('Brak bohatera w lochu!?') self._statusbar = StatusBar( _engine, self._hero) # pasek życia/many itp. / statusu self.inventory = Inventory(_engine, self._hero, self._hero.inventory, self._freeobjects) self.chestitems = ChestItems(_engine, self._hero, self._freeobjects) self._submodules = (self._map, self._minimap, self._statusbar, self.inventory, self.chestitems, self._cursor) self._play = True self._refresh = True
from combat import Combat from warrior import Warrior from mage import Mage from ranger import Ranger if __name__ == "__main__": testPlayer = Warrior() testMonster = Warrior() print "You attack a testMonster" Combat(Warrior(), testMonster) print "You attack a mage" Combat(Mage(), Mage()) print "You attack a Ranger" Combat(Mage(), Ranger())
def load_champion(): # print("Enter Champions Type") # ch_type = input(">> ") # print("Enter Champions name") # ch_name = input(">> ") jsonfiles = [] for f in glob.glob("*.json"): jsonfiles.append(f) if jsonfiles == []: print("\nNo champions saved\n") input("Press enter to continue") return None print("===== Load Champion =====") for i, n in enumerate(jsonfiles): print("{}-{}".format(i + 1, n[:-5])) try: print("*Any other option to go back") l_op = int(input(">> ")) l_op -= 1 if l_op < 0 or l_op >= len(jsonfiles): raise Exception except: # os.system("clear") # print("\nWrong option\n") # input("Press enter to continue") return None champ_f = jsonfiles[l_op][:-5].split("_") ch_type = champ_f[0] ch_name = champ_f[1] ch_dict = BaseChampion.load_character(ch_type, ch_name) if ch_dict == {}: print("no champion found") return None if ch_type == "Cleric": my_champ = Cleric(ch_dict["name"], ch_dict["raze"], ch_dict["gender"], ch_dict["level"], ch_dict["nv_exp"], ch_dict["current_exp"], ch_dict["total_exp"], ch_dict["stat_points"]) if ch_type == "Paladin": my_champ = Paladin(ch_dict["name"], ch_dict["raze"], ch_dict["gender"], ch_dict["level"], ch_dict["nv_exp"], ch_dict["current_exp"], ch_dict["total_exp"], ch_dict["stat_points"]) if ch_type == "Figther": my_champ = Figther(ch_dict["name"], ch_dict["raze"], ch_dict["gender"], ch_dict["level"], ch_dict["nv_exp"], ch_dict["current_exp"], ch_dict["total_exp"], ch_dict["stat_points"]) if ch_type == "Mage": my_champ = Mage(ch_dict["name"], ch_dict["raze"], ch_dict["gender"], ch_dict["level"], ch_dict["nv_exp"], ch_dict["current_exp"], ch_dict["total_exp"], ch_dict["stat_points"]) if ch_type == "Rogue": my_champ = Rogue(ch_dict["name"], ch_dict["raze"], ch_dict["gender"], ch_dict["level"], ch_dict["nv_exp"], ch_dict["current_exp"], ch_dict["total_exp"], ch_dict["stat_points"]) if ch_type == "Ranger": my_champ = Ranger(ch_dict["name"], ch_dict["raze"], ch_dict["gender"], ch_dict["level"], ch_dict["nv_exp"], ch_dict["current_exp"], ch_dict["total_exp"], ch_dict["stat_points"]) my_champ.stats = ch_dict["stats"] os.system("clear") print(my_champ) input("Press enter to continue") return my_champ