def setUp(self):
        cells = [[0, 0, 0],
                 [0, 0, 1]]
        ctypes = [('Floor',), ('Exit',)]
        self.lfile = MockDataFile(cells, ctypes)
        self.level = ChipsChallenge(self.lfile)

        self.player = self.level.add_sprite('Player', (2, 1))
Example #2
0
    def setUp(self):
        cells = [[0, 0, 0]]
        ctypes = [('Floor',)]
        self.level = ChipsChallenge(MockDataFile(cells, ctypes))

        self.player = self.level.add_sprite('Player', (0, 0))
        self.chipdoor = self.level.add_sprite('ChipDoor', (1, 0))
        self.player.carrying.add(self.level.add_sprite('Chip', (0, 0)))
Example #3
0
class Test_ChipDoor(unittest.TestCase):
    def setUp(self):
        cells = [[0, 0, 0]]
        ctypes = [('Floor',)]
        self.level = ChipsChallenge(MockDataFile(cells, ctypes))

        self.player = self.level.add_sprite('Player', (0, 0))
        self.chipdoor = self.level.add_sprite('ChipDoor', (1, 0))
        self.player.carrying.add(self.level.add_sprite('Chip', (0, 0)))


    def test_chipdoor_opens_if_chip_quota_met(self):
        self.level.chipquota = 1
        self.player.attempt_move(1)
        self.assertFalse(self.chipdoor.is_solid)


    def test_chipdoor_doesnt_open_if_chip_quota_not_met(self):
        self.level.chipquota = 2
        self.player.attempt_move(1)
        self.assertTrue(self.chipdoor.is_solid)
class Test_ChipsChallenge(unittest.TestCase):
    def setUp(self):
        cells = [[0, 0, 0],
                 [0, 0, 1]]
        ctypes = [('Floor',), ('Exit',)]
        self.lfile = MockDataFile(cells, ctypes)
        self.level = ChipsChallenge(self.lfile)

        self.player = self.level.add_sprite('Player', (2, 1))


    def test_level_doesnt_succeed_if_player_not_on_exit(self):
        self.player.pos = 2, 0
        self.assertFalse(self.level.check_for_success())


    def test_level_succeeds_if_no_chips_and_player_on_exit(self):
        self.assertTrue(self.level.check_for_success())


    def test_level_doesnt_succeed_if_chips_remaining(self):
        self.level.add_sprite('Chip', (1, 1))
        self.level.chipquota += 1
        self.assertFalse(self.level.check_for_success())


    def test_level_succeeds_if_chips_all_carried(self):
        chip = self.level.add_sprite('Chip', (2, 1))
        self.level.chipquota += 1
        self.player.carrying.add(chip)
        self.assertTrue(self.level.check_for_success())


    def test_chipquota_equals_property_if_passed(self):
        self.lfile.properties['chipquota'] = 2
        level = ChipsChallenge(self.lfile)
        self.assertEqual(level.chipquota, 2)


    def test_chip_quota_equals_number_of_chips_if_no_property_passed(self):
        self.lfile.spritedata = [('Chip', (0, 0)), ('Chip', (0, 1)), ('Chip', (0, 2))]
        level = ChipsChallenge(self.lfile)
        self.assertEqual(level.chipquota, 3)


    def test_level_succeeds_if_chips_carried_meets_quota(self):
        self.level.add_sprite('Chip', (0, 0))
        chip2 = self.level.add_sprite('Chip', (1, 0))
        chip3 = self.level.add_sprite('Chip', (2, 0))
        self.level.chipquota = 2
        self.assertFalse(self.level.check_for_success())
        self.player.carrying.add(chip2)
        self.assertFalse(self.level.check_for_success())
        self.player.carrying.add(chip3)
        self.assertTrue(self.level.check_for_success())


    def test_level_fails_if_player_destroyed(self):
        self.assertFalse(self.level.check_for_failure())
        self.player.destroy()
        self.assertTrue(self.level.check_for_failure())