Ejemplo n.º 1
0
 def setUp(self):
     self.level = SnakeLevel(box)
Ejemplo n.º 2
0
class SnakeLevelTests(TestCase):
    def setUp(self):
        self.level = SnakeLevel(box)

    def test_get_set(self):
        self.assertEqual(str(self.level), box)
        self.level.set_level(empty_box)
        self.assertEqual(str(self.level), empty_box)

    def test_place_fruit(self):
        self.level.place_fruit(Vector(2, 2), "b")
        self.assertEqual(str(self.level), twofruit_box)

    def test_place_random_fruit(self):
        self.level.place_random_fruit()

    def test_remove_fruit(self):
        self.level.remove_fruit(Vector(5, 3))
        self.assertEqual(str(self.level), empty_box)

    def test_get(self):
        self.assertEqual(self.level.get(Vector(5, 3)), "a")
        self.assertEqual(self.level.get(Vector(4, 4)), ".")
        self.assertEqual(self.level.get(Vector(0, 0)), "#")

    def test_display(self):
        gf = GameFactory("data/settings.txt")
        frame = Frame(gf.screen, Rect(0, 0, 512, 256))
        gf.tile_factory.add_tile_synonyms(TILE_SYNONYMS)
        self.level.place_fruit(Vector(2, 2), "b")
        tmap = TiledMap(frame, gf.tile_factory)
        tmap.fill_map(str(self.level))
        tmap.cache_map()
        tmap.draw()
        pygame.display.update()
        time.sleep(1)