def test_initialization(self): self.test_shields = generate_shields(50, 40, 40, 40) self.test_armors = generate_armor(100, 60, 60, 100) self.test_weapons = FighterWeapons() self.test_weapons.add_weapon( "bow", Weapon("MDC 8", "MDC", dict([(1, 8), (2, 8), (3, 8), (4, 8), (5, 8), (6, 8)]), 6, 24, 108000)) self.fighter = Fighter("Avenger", "Heavy Fighter", 175, 3552300, 0, 1200, 1200, 7, True, False, self.test_shields, self.test_armors, self.test_weapons) self.assertEqual("Avenger", self.fighter.name, "Fighter class must match") self.assertEqual("Heavy Fighter", self.fighter.fighter_class, "Fighter class must match") self.assertEqual(175, self.fighter.mass, "Mass must match") self.assertEqual(3552300, self.fighter.cost, "Cost must match") self.assertEqual(0, self.fighter.center_engine, "Center engine must match") self.assertEqual(1200, self.fighter.right_engine, "Right engine must match") self.assertEqual(1200, self.fighter.left_engine, "Left engine must match") self.assertEqual(7, self.fighter.thrust, "Thrust must match") self.assertEqual(True, self.fighter.streamlining, "Streamlining must match") self.assertEqual(False, self.fighter.antigrav, "Antigrav must match") self.assertEqual(self.test_shields, self.fighter.shields, "Shields must match") self.assertEqual(self.test_armors, self.fighter.armors, "Armor must match") self.assertEqual(self.test_weapons, self.fighter.weapons, "Weapons must match")
def test_turning(self): self.test_shields = generate_shields(50, 40, 40, 40) self.test_armors = generate_armor(100, 60, 60, 100) self.test_weapons = FighterWeapons() self.test_weapons.add_weapon( "bow", Weapon("MDC 8", "MDC", dict([(1, 8), (2, 8), (3, 8), (4, 8), (5, 8), (6, 8)]), 6, 24, 108000)) self.fighter = Fighter("Avenger", "Heavy Fighter", 175, 3552300, 0, 1200, 1200, 7, True, False, self.test_shields, self.test_armors, self.test_weapons) self.assertEqual(0, self.fighter.heading, "Starting heading must be 0") self.fighter.turn_right() self.assertEqual(5, self.fighter.heading, "Heading must have turned right") self.fighter.turn_right() self.assertEqual(4, self.fighter.heading, "Heading must have turned right") self.fighter.turn_left() self.assertEqual(5, self.fighter.heading, "Heading must have turned left") self.fighter.turn_left() self.assertEqual(0, self.fighter.heading, "Heading must have turned left") self.fighter.turn_left() self.assertEqual(1, self.fighter.heading, "Heading must have turned left")
def test_initialization_defaults(self): self.fighter = Fighter() self.assertEqual("", self.fighter.name, "Fighter class must match") self.assertEqual("Light Fighter", self.fighter.fighter_class, "Fighter class must match") self.assertEqual(0, self.fighter.mass, "Mass must match") self.assertEqual(0, self.fighter.cost, "Cost must match") self.assertEqual(0, self.fighter.center_engine, "Center engine must match") self.assertEqual(0, self.fighter.right_engine, "Right engine must match") self.assertEqual(0, self.fighter.left_engine, "Left engine must match") self.assertEqual(0, self.fighter.thrust, "Thrust must match") self.assertEqual(False, self.fighter.streamlining, "Streamlining must match") self.assertEqual(False, self.fighter.antigrav, "Antigrav must match") self.assertEqual(None, self.fighter.shields, "Shields must match") self.assertEqual(None, self.fighter.armors, "Armor must match") self.assertEqual(None, self.fighter.weapons, "Weapons must match")
def test_hex(self): self.fighter = Fighter("Test Fighter", "Light Fighter", 1, 2, 3, 4, 5, 6, True, True, None, None, None) self.pilot = Pilot("Jane", "Minerva", 7, 8, self.fighter) self.assertEqual(0, self.pilot.x, "Initial hex x should be 0") self.assertEqual(0, self.pilot.y, "Initial hex y should be 0") self.pilot.change_hex(1, 2) self.pilot.change_heading(3) self.assertEqual(1, self.pilot.x, "New hex x should be 1") self.assertEqual(2, self.pilot.y, "New hex y should be 2")
def test_initialization(self): self.fighter = Fighter("Test Fighter", "Light Fighter", 1, 2, 3, 4, 5, 6, True, True, None, None, None) self.pilot = Pilot("Jane", "Minerva", 7, 8, self.fighter) self.assertEqual("Jane", self.pilot.name, "Name must equal") self.assertEqual("Minerva", self.pilot.callsign, "Callsign must equal") self.assertEqual(7, self.pilot.piloting_skill, "Piloting skill must equal") self.assertEqual(8, self.pilot.gunnery_skill, "Gunnery Skill must equal") self.assertEqual(self.fighter, self.pilot.fighter, "Fighter must equal")
def __init__(self, name="John Doe", callsign="void", piloting_skill=0, gunnery_skill=0, fighter=None): self.name = name self.callsign = callsign if piloting_skill == 0 and gunnery_skill == 0: self.piloting_skill, self.gunnery_skill = self.generate_beginner_skill_level( ) else: self.piloting_skill = piloting_skill self.gunnery_skill = gunnery_skill if fighter is None: self.fighter = Fighter() else: self.fighter = fighter self.x = 0 self.y = 0 self.current_thrust = self.fighter.thrust
def load_fighters(filename, loaded_weapons, image_offset="../"): fighters_dict = dict() with open(filename) as json_file: json_array = json.load(json_file) for item in json_array: shields = item['shields'] shield_dict = generate_shields(shields['bow'], shields['left'], shields['right'], shields['stern']) armor = item['armor'] armor_dict = generate_armor(armor['bow'], armor['left'], armor['right'], armor['stern']) weapons = item['weapons'] fighter_weapons = FighterWeapons() for weapon in weapons: if weapon['type'] not in loaded_weapons: print( f"ERROR: Weapon Type not found in loaded weapons: {weapon['type']}" ) fighter_weapons.add_weapon(weapon['location'], loaded_weapons.get(weapon['type'])) engines = item['engines'] center_engine = engines['center'] if 'center' in engines else 0 left_engine = engines['left'] if 'left' in engines else 0 right_engine = engines['right'] if 'right' in engines else 0 image_filename = os.path.join(THIS_DIR, image_offset + item['image']) fighters_dict.update({ item['name']: Fighter(item['name'], item['class'], item['mass'], item['cost'], center_engine, right_engine, left_engine, item['thrust'], item['streamlining'], item['antigrav'], shield_dict, armor_dict, fighter_weapons, image_filename) }) return fighters_dict
def test_moving_forward(self): self.test_shields = generate_shields(50, 40, 40, 40) self.test_armors = generate_armor(100, 60, 60, 100) self.test_weapons = FighterWeapons() self.test_weapons.add_weapon( "bow", Weapon("MDC 8", "MDC", dict([(1, 8), (2, 8), (3, 8), (4, 8), (5, 8), (6, 8)]), 6, 24, 108000)) self.fighter = Fighter("Avenger", "Heavy Fighter", 175, 3552300, 0, 1200, 1200, 7, True, False, self.test_shields, self.test_armors, self.test_weapons) self.assertEqual(0, self.fighter.heading, "Starting heading must be 0") self.assertEqual(0, self.fighter.x, "Starting x position must be 0") self.assertEqual(0, self.fighter.y, "Starting y position must be 0") self.fighter.move_forward() self.assertEqual(1, self.fighter.x, "New x position must be 1") self.assertEqual(0, self.fighter.y, "New y position must be 0") self.fighter.move_forward() self.assertEqual(2, self.fighter.x, "New x position must be 2") self.assertEqual(0, self.fighter.y, "New y position must be 0") self.fighter.turn_right() self.fighter.move_forward() self.assertEqual(2, self.fighter.x, "New x position must be 2") self.assertEqual(1, self.fighter.y, "New y position must be 1") self.fighter.move_forward() self.assertEqual(3, self.fighter.x, "New x position must be 3") self.assertEqual(2, self.fighter.y, "New y position must be 2") self.fighter.turn_right() self.fighter.move_forward() self.assertEqual(2, self.fighter.x, "New x position must be 2") self.assertEqual(3, self.fighter.y, "New y position must be 3") self.fighter.move_forward() self.assertEqual(2, self.fighter.x, "New x position must be 2") self.assertEqual(4, self.fighter.y, "New y position must be 4") self.fighter.turn_right() self.fighter.move_forward() self.assertEqual(1, self.fighter.x, "New x position must be 1") self.assertEqual(4, self.fighter.y, "New y position must be 4") self.fighter.move_forward() self.assertEqual(0, self.fighter.x, "New x position must be 0") self.assertEqual(4, self.fighter.y, "New y position must be 4") self.fighter.turn_right() self.fighter.move_forward() self.assertEqual(-1, self.fighter.x, "New x position must be -1") self.assertEqual(3, self.fighter.y, "New y position must be 3") self.fighter.move_forward() self.assertEqual(-1, self.fighter.x, "New x position must be -1") self.assertEqual(2, self.fighter.y, "New y position must be 2") self.fighter.turn_right() self.fighter.move_forward() self.assertEqual(-1, self.fighter.x, "New x position must be -1") self.assertEqual(1, self.fighter.y, "New y position must be 1") self.fighter.move_forward() self.assertEqual(0, self.fighter.x, "New x position must be 0") self.assertEqual(0, self.fighter.y, "New y position must be 0")
class FighterTest(unittest.TestCase): def test_initialization_defaults(self): self.fighter = Fighter() self.assertEqual("", self.fighter.name, "Fighter class must match") self.assertEqual("Light Fighter", self.fighter.fighter_class, "Fighter class must match") self.assertEqual(0, self.fighter.mass, "Mass must match") self.assertEqual(0, self.fighter.cost, "Cost must match") self.assertEqual(0, self.fighter.center_engine, "Center engine must match") self.assertEqual(0, self.fighter.right_engine, "Right engine must match") self.assertEqual(0, self.fighter.left_engine, "Left engine must match") self.assertEqual(0, self.fighter.thrust, "Thrust must match") self.assertEqual(False, self.fighter.streamlining, "Streamlining must match") self.assertEqual(False, self.fighter.antigrav, "Antigrav must match") self.assertEqual(None, self.fighter.shields, "Shields must match") self.assertEqual(None, self.fighter.armors, "Armor must match") self.assertEqual(None, self.fighter.weapons, "Weapons must match") def test_initialization(self): self.test_shields = generate_shields(50, 40, 40, 40) self.test_armors = generate_armor(100, 60, 60, 100) self.test_weapons = FighterWeapons() self.test_weapons.add_weapon( "bow", Weapon("MDC 8", "MDC", dict([(1, 8), (2, 8), (3, 8), (4, 8), (5, 8), (6, 8)]), 6, 24, 108000)) self.fighter = Fighter("Avenger", "Heavy Fighter", 175, 3552300, 0, 1200, 1200, 7, True, False, self.test_shields, self.test_armors, self.test_weapons) self.assertEqual("Avenger", self.fighter.name, "Fighter class must match") self.assertEqual("Heavy Fighter", self.fighter.fighter_class, "Fighter class must match") self.assertEqual(175, self.fighter.mass, "Mass must match") self.assertEqual(3552300, self.fighter.cost, "Cost must match") self.assertEqual(0, self.fighter.center_engine, "Center engine must match") self.assertEqual(1200, self.fighter.right_engine, "Right engine must match") self.assertEqual(1200, self.fighter.left_engine, "Left engine must match") self.assertEqual(7, self.fighter.thrust, "Thrust must match") self.assertEqual(True, self.fighter.streamlining, "Streamlining must match") self.assertEqual(False, self.fighter.antigrav, "Antigrav must match") self.assertEqual(self.test_shields, self.fighter.shields, "Shields must match") self.assertEqual(self.test_armors, self.fighter.armors, "Armor must match") self.assertEqual(self.test_weapons, self.fighter.weapons, "Weapons must match") def test_turning(self): self.test_shields = generate_shields(50, 40, 40, 40) self.test_armors = generate_armor(100, 60, 60, 100) self.test_weapons = FighterWeapons() self.test_weapons.add_weapon( "bow", Weapon("MDC 8", "MDC", dict([(1, 8), (2, 8), (3, 8), (4, 8), (5, 8), (6, 8)]), 6, 24, 108000)) self.fighter = Fighter("Avenger", "Heavy Fighter", 175, 3552300, 0, 1200, 1200, 7, True, False, self.test_shields, self.test_armors, self.test_weapons) self.assertEqual(0, self.fighter.heading, "Starting heading must be 0") self.fighter.turn_right() self.assertEqual(5, self.fighter.heading, "Heading must have turned right") self.fighter.turn_right() self.assertEqual(4, self.fighter.heading, "Heading must have turned right") self.fighter.turn_left() self.assertEqual(5, self.fighter.heading, "Heading must have turned left") self.fighter.turn_left() self.assertEqual(0, self.fighter.heading, "Heading must have turned left") self.fighter.turn_left() self.assertEqual(1, self.fighter.heading, "Heading must have turned left") def test_moving_forward(self): self.test_shields = generate_shields(50, 40, 40, 40) self.test_armors = generate_armor(100, 60, 60, 100) self.test_weapons = FighterWeapons() self.test_weapons.add_weapon( "bow", Weapon("MDC 8", "MDC", dict([(1, 8), (2, 8), (3, 8), (4, 8), (5, 8), (6, 8)]), 6, 24, 108000)) self.fighter = Fighter("Avenger", "Heavy Fighter", 175, 3552300, 0, 1200, 1200, 7, True, False, self.test_shields, self.test_armors, self.test_weapons) self.assertEqual(0, self.fighter.heading, "Starting heading must be 0") self.assertEqual(0, self.fighter.x, "Starting x position must be 0") self.assertEqual(0, self.fighter.y, "Starting y position must be 0") self.fighter.move_forward() self.assertEqual(1, self.fighter.x, "New x position must be 1") self.assertEqual(0, self.fighter.y, "New y position must be 0") self.fighter.move_forward() self.assertEqual(2, self.fighter.x, "New x position must be 2") self.assertEqual(0, self.fighter.y, "New y position must be 0") self.fighter.turn_right() self.fighter.move_forward() self.assertEqual(2, self.fighter.x, "New x position must be 2") self.assertEqual(1, self.fighter.y, "New y position must be 1") self.fighter.move_forward() self.assertEqual(3, self.fighter.x, "New x position must be 3") self.assertEqual(2, self.fighter.y, "New y position must be 2") self.fighter.turn_right() self.fighter.move_forward() self.assertEqual(2, self.fighter.x, "New x position must be 2") self.assertEqual(3, self.fighter.y, "New y position must be 3") self.fighter.move_forward() self.assertEqual(2, self.fighter.x, "New x position must be 2") self.assertEqual(4, self.fighter.y, "New y position must be 4") self.fighter.turn_right() self.fighter.move_forward() self.assertEqual(1, self.fighter.x, "New x position must be 1") self.assertEqual(4, self.fighter.y, "New y position must be 4") self.fighter.move_forward() self.assertEqual(0, self.fighter.x, "New x position must be 0") self.assertEqual(4, self.fighter.y, "New y position must be 4") self.fighter.turn_right() self.fighter.move_forward() self.assertEqual(-1, self.fighter.x, "New x position must be -1") self.assertEqual(3, self.fighter.y, "New y position must be 3") self.fighter.move_forward() self.assertEqual(-1, self.fighter.x, "New x position must be -1") self.assertEqual(2, self.fighter.y, "New y position must be 2") self.fighter.turn_right() self.fighter.move_forward() self.assertEqual(-1, self.fighter.x, "New x position must be -1") self.assertEqual(1, self.fighter.y, "New y position must be 1") self.fighter.move_forward() self.assertEqual(0, self.fighter.x, "New x position must be 0") self.assertEqual(0, self.fighter.y, "New y position must be 0")
class Pilot(object): beginning_skill_table = dict([(1, (6, 6)), (2, (5, 5)), (3, (5, 4)), (4, (5, 4)), (5, (5, 4)), (6, (5, 4)), (7, (5, 4)), (8, (5, 4)), (9, (4, 3)), (10, (3, 2))]) def __init__(self, name="John Doe", callsign="void", piloting_skill=0, gunnery_skill=0, fighter=None): self.name = name self.callsign = callsign if piloting_skill == 0 and gunnery_skill == 0: self.piloting_skill, self.gunnery_skill = self.generate_beginner_skill_level( ) else: self.piloting_skill = piloting_skill self.gunnery_skill = gunnery_skill if fighter is None: self.fighter = Fighter() else: self.fighter = fighter self.x = 0 self.y = 0 self.current_thrust = self.fighter.thrust # TODO for alpha, pilots and fighers are always in the same hex. def change_hex(self, x, y): self.x = x self.y = y self.fighter.change_hex(x, y) def update_coordinates(self): self.x = self.fighter.x self.y = self.fighter.y def change_heading(self, heading): self.fighter.change_heading(heading) self.update_coordinates() def turn_left(self): self.fighter.turn_left() self.update_coordinates() def turn_right(self): self.fighter.turn_right() self.update_coordinates() def move_forward(self): self.fighter.move_forward() self.update_coordinates() # Returns a tuple of piloting skill and gunnery skill @staticmethod def generate_beginner_skill_level(): roll = random.randint(1, 10) return Pilot.beginning_skill_table[roll] def draw(self, screen, hexgrid, scale): self.fighter.draw(screen, hexgrid, scale)