def get_team(team_limit, team): valid_classes = ['T', 'P', 'K', 'TH'] say = ['YOUR TEAM', 'ENEMY TEAM'] print("\n========== {} ==========\n ====== Team limit: {} ======\n\n\ Available classes:\n\ T = Thug K = Knight\n\ P = Priest TH = Thief\n".format(say[team], team_limit)) print("e.g. To create a team of 2 Knights and 1 Priest, use: P K K\n") valid = False while not valid: try: created_team = input(">> ").upper() units_to_create = created_team.split(" ") if len(units_to_create) not in range(0, team_limit + 1): print( "There may only be {} or less units in this team!".format( team_limit)) else: valid = True for unit in units_to_create: if unit not in valid_classes: print("Invalid input \"{}\". Please try again!".format( unit)) valid = False break except IndentationError: print("what") Unit.create_units(units_to_create, team)
def __init__(self, x, y, target_x, target_y, group, listed, speed=13, shooting_range=300): Unit.__init__(self, x, y, r=7, colour='red') self.speed = speed self.shooting_range = shooting_range self.target_x = target_x self.target_y = target_y self.step = self.shooting_range/self.speed self.proj_calc(target_x, target_y) self.group = group self.listed = listed
def __init__(self, camera): Unit.__init__(self, x=start['x'], y=start['y'], r=start['hero_r'], colour='#23409E') self.counter = 0 self.max_speed = HERO_MAX_SPEED self.moving = {'up': False, 'down': False, 'right': False, 'left': False} self.speed = {'y_up': 0, 'y_down': 0, 'x_right': 0, 'x_left': 0} self.camera = camera
def __init__(self, x, y, listed, food=(), level=0, group='Enemy'): Unit.__init__(self, x, y, colour='#6d2f84') self.logic = { 1: { 'r': 14, 'max_speed': 4, 'vision_range': 0, 'health': 1, 'value': 0, 'colour': '#6d2f84', 'limit_counter': 0 }, 2: { 'r': 32, 'max_speed': 5, 'vision_range': 60, 'health': 1, 'value': 2, 'colour': '#1B702F', 'limit_counter': 1 }, 3: { 'r': 47, 'max_speed': 3, 'vision_range': 47, 'health': 2, 'value': 3, 'colour': '#a39b49', 'limit_counter': 1 } } self.group = group self.level = level self.food = food self.r = self.logic[self.level]['r'] self.max_speed = self.logic[self.level]['max_speed'] self.vision_range = self.logic[self.level]['vision_range'] self.health = self.logic[self.level]['health'] self.colour = self.logic[self.level]['colour'] self.value = self.logic[self.level]['value'] self.exp = 0 self.alive = True self.move_counter = 0 self.hit_counter = 0 self.spawn_counter = 0 self.fertility = 3 self.listed = listed self.move_y = choice([self.move_down, self.move_up]) self.move_x = choice([self.move_left, self.move_right]) self.speed = {'y': 0, 'x': 0} Enemy.limit_counter += self.logic[self.level]['limit_counter']
def set_starting_units(self): starting_units_dict = STARTING_UNITS[self.race] for unit_type in starting_units_dict.keys(): for i in range(starting_units_dict[unit_type]): this_unit = Unit.create(unit_type) this_unit.update(self.home_system_hex) self.units.add(this_unit)
def main(team_zero_limit, team_one_limit, is_multiplayer): run_game = True while run_game: #get player name and teams Unit.player_name = input("What is your name?\n> ") time.sleep(0.2) print( "------------------------[TEAM CREATION]------------------------") get_team(team_zero_limit, 0) get_team(team_one_limit, 1) input("\n<Press ENTER to start the battle>\n") os.system('cls') #begin battle while loop, stop loop when all of one team is dead while Unit.num_units(0, "alive") > 0 and Unit.num_units(1, "alive") > 0: for unit in Unit.get_units("all", 0): #for each unit in team_zero if unit.alive: #if unit is alive print( "-----------------------[Team 1's turn]-----------------------" ) unit.choose_move() #call its choose_move function #team 0 win condition if Unit.num_units(1, "alive") <= 0: break if Unit.num_units(1, "alive") <= 0: print("\nYou win!\n") break for unit in Unit.get_units("all", 1): #for each unit in list 1 if unit.alive: print( "-----------------------[Team 2's turn]-----------------------" ) unit.choose_move(is_multiplayer=is_multiplayer) if Unit.num_units(0, "alive") <= 0: #team 1 win condition print("\nYou lose!\n") # break # Unit.remove_all() run_game = play_again()
def __init__(self): Unit.__init__(self, x=spawn['x'], y=spawn['y'], r=40, speed=hero_speed, colour='blue') self.counter = 0
def __init__(self, x, y): Unit.__init__(self, x, y, colour='darkred')
def collide(self, another_object): if another_object.group == 'Enemy': Unit.move_away(self, another_object) self.camera.x = self.x - self.camera.w//2 self.camera.y = self.y - self.camera.h//2
def __init__(self): Unit.__init__(self, x, y, r=10, shooting_range=150, speed=10, visual=None, colour='red')