コード例 #1
0
ファイル: test_fighter.py プロジェクト: wolvzor/interceptor
    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")
コード例 #2
0
ファイル: test_fighter.py プロジェクト: wolvzor/interceptor
 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")
コード例 #3
0
ファイル: test_weapon.py プロジェクト: wolvzor/interceptor
 def test_defaults(self):
     self.weapon = Weapon()
     self.assertEqual(0, self.weapon.cost, "Cost must be zero")
     self.assertEqual("weapon_name", self.weapon.name,
                      "Weapon name must be default")
     self.assertEqual("laser", self.weapon.type,
                      "Weapon type must be default")
     self.assertEqual(0, self.weapon.power, "Power must be zero")
     self.assertEqual(0, self.weapon.tonnage, "Tonnage must be zero")
     print(self.weapon.ranges)
     for i in range(1, 15):
         self.assertEqual(0, self.weapon.ranges.get(i),
                          f"Range for {i} must be zero")
コード例 #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")
コード例 #5
0
def load_weapons(filename='data/weapon_data.csv'):
    raw_data = open(filename, 'rt')
    reader = csv.reader(raw_data, delimiter=',', quoting=csv.QUOTE_NONE)
    x = list(reader)
    weapon_list = dict()
    for line in x:
        if line[0] != 'Name':
            weapon_range = dict([(1, line[2]), (2, line[3]), (3, line[3]),
                                 (4, line[4]), (5, line[4]), (6, line[4]),
                                 (7, line[5]), (8, line[5]), (9, line[5]),
                                 (10, line[6]), (11, line[6]), (12, line[6]),
                                 (13, line[6]), (14, line[6]), (15, line[6])])
            weapon_list.update({
                line[0]:
                Weapon(line[0], line[1], weapon_range, line[7], line[8],
                       line[9])
            })
    raw_data.close()
    return weapon_list
コード例 #6
0
ファイル: test_weapon.py プロジェクト: wolvzor/interceptor
 def test_arguments(self):
     self.weapon = Weapon(
         "MDC 8", "MDC",
         dict([(1, 8), (2, 8), (3, 8), (4, 8), (5, 8), (6, 8)]), 6, 24,
         108000)
     self.assertEqual(108000, self.weapon.cost, "Cost must match argument")
     self.assertEqual("MDC 8", self.weapon.name,
                      "Weapon name must match argument")
     self.assertEqual("MDC", self.weapon.type,
                      "Weapon type must match argument")
     self.assertEqual(6, self.weapon.power, "Power must match argument")
     self.assertEqual(24, self.weapon.tonnage,
                      "Tonnage must match argument")
     print(self.weapon.ranges)
     for i in range(1, 6):
         self.assertEqual(8, self.weapon.ranges.get(i),
                          f"Range for {i} must be 8")
     for i in range(7, 15):
         self.assertEqual(0, self.weapon.ranges.get(i),
                          f"Range for {i} must be 0")
コード例 #7
0
ファイル: test_weapon.py プロジェクト: wolvzor/interceptor
 def test_calculate_damage(self):
     self.weapon = Weapon(
         "NPC 9", "NPC",
         dict([(1, 1), (2, 6), (3, 6), (4, 9), (5, 9), (6, 9)]), 7, 16,
         104000)
     self.assertEqual(("NPC", 1), self.weapon._calculate_damage(1),
                      "Damage at range 1 must be 1 NPC")
     self.assertEqual(("NPC", 6), self.weapon._calculate_damage(2),
                      "Damage at range 2 must be 6 NPC")
     self.assertEqual(("NPC", 6), self.weapon._calculate_damage(3),
                      "Damage at range 3 must be 6 NPC")
     self.assertEqual(("NPC", 9), self.weapon._calculate_damage(4),
                      "Damage at range 4 must be 9 NPC")
     self.assertEqual(("NPC", 9), self.weapon._calculate_damage(5),
                      "Damage at range 5 must be 9 NPC")
     self.assertEqual(("NPC", 9), self.weapon._calculate_damage(6),
                      "Damage at range 6 must be 9 NPC")
     self.assertEqual(("NPC", 0), self.weapon._calculate_damage(7),
                      "Damage at range 7 must be 0 NPC")
     self.assertEqual(("NPC", 0), self.weapon._calculate_damage(57),
                      "Damage at range 47 must be 0 NPC")
コード例 #8
0
ファイル: test_fighter.py プロジェクト: wolvzor/interceptor
    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")