Ejemplo n.º 1
0
    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")
Ejemplo n.º 2
0
 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")
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
 def test_add_weapons(self):
     self.fighter_weapons = FighterWeapons()
     self.bow_weapon = Weapon(
         "MDC 8", "MDC",
         dict([(1, 8), (2, 8), (3, 8), (4, 8), (5, 8), (6, 8)]), 6, 24,
         108000)
     self.left_weapon = Weapon(
         "NPC 9", "NPC",
         dict([(1, 1), (2, 6), (3, 6), (4, 9), (5, 9), (6, 9)]), 7, 16,
         104000)
     self.right_weapon = Weapon(
         "EPC 9", "EPC",
         dict([(1, 9), (2, 5), (3, 5), (4, 3), (5, 3), (6, 3)]), 25, 6,
         125000)
     self.one_weapon = Weapon("1.5/6", "LASER",
                              dict([(1, 7), (2, 6), (3, 6)]), 10, 10,
                              120000)
     self.two_weapon = Weapon("1.5/3", "LASER",
                              dict([(1, 4), (2, 3), (3, 3)]), 5, 5, 60000)
     self.fighter_weapons.add_weapon("bow", self.bow_weapon)
     self.fighter_weapons.add_weapon("left", self.left_weapon)
     self.fighter_weapons.add_weapon("right", self.right_weapon)
     self.assertEquals(1, self.fighter_weapons.bow.__len__(),
                       "Bow weapon size must match")
     self.assertEquals(1, self.fighter_weapons.left.__len__(),
                       "Left weapon size must match")
     self.assertEquals(1, self.fighter_weapons.right.__len__(),
                       "Right weapon size must match")
     self.assertTrue(self.fighter_weapons.bow.__contains__(self.bow_weapon),
                     "Bow weapons must include MDC 8")
     self.assertTrue(
         self.fighter_weapons.left.__contains__(self.left_weapon),
         "Left weapons must include NPC 9")
     self.assertTrue(
         self.fighter_weapons.right.__contains__(self.right_weapon),
         "Right weapons must include EPC 9")
Ejemplo n.º 5
0
    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")