예제 #1
0
파일: tests.py 프로젝트: yizow/hexgame
    def test_ring_full(self):
        hexmap = HexMap.HexMap(10, 10, False)

        expected = [(3, 3), (4, 3), (5, 3), (5, 4), (4, 5), (3, 4)]
        self.assertEqual(expected, hexmap.get_ring(4, 4, 1))

        expected = [(2, 3), (3, 2), (4, 2), (5, 2), (6, 3), (6, 4), (6, 5),
                    (5, 5), (4, 6), (3, 5), (2, 5), (2, 4)]
        self.assertEqual(expected, hexmap.get_ring(4, 4, 2))
예제 #2
0
    def __init__(self, surface, radius=50, should_wrap=False):
        """
        Args:
            surface (pygame.Surface):
            radius (int): Pixels between center and vertex of hexagon

        """
        self.surface = surface
        self.radius = radius
        self.inradius = HexTile(self, self.radius, 0, 0).inradius

        self.width = type(self).calc_num_columns(self.surface.get_width(),
                                                 self.radius)
        self.x_offset = (self.surface.get_width() - self.width_used()) // 2

        self.height = type(self).calc_num_rows(self.surface.get_height(),
                                               self.inradius)
        self.y_offset = (self.surface.get_height() - self.height_used()) // 2

        self.tiles = []
        self.indices = {}
        for col in range(self.width):
            column = []
            for tile in range(self.height):
                center_q = self.x_offset + self.radius * (1.5 * col + 1)
                center_r = self.y_offset + self.inradius * (2 * tile + 1)
                if col % 2:
                    center_r += self.inradius
                column.append(
                    HexTile(self, self.radius, round(center_q),
                            round(center_r)))
                self.indices[column[-1]] = (col, tile)
            self.tiles.append(column)

        self.hexmap = HexMap.HexMap(self.width,
                                    self.height,
                                    should_wrap=should_wrap)

        self.previous_selected = None
예제 #3
0
파일: tests.py 프로젝트: yizow/hexgame
    def test_ring_clipped(self):
        hexmap = HexMap.HexMap(7, 5, False)

        expected = [(2, 3), (3, 2), (4, 2), (5, 2), (6, 3), (6, 4), (2, 4)]
        self.assertEqual(expected, hexmap.get_ring(4, 4, 2))
예제 #4
0
파일: tests.py 프로젝트: yizow/hexgame
 def test_get_neighbors_distance(self):
     hexmap = HexMap.HexMap(0, 0, False)
     expected = [(2, -1), (2, 1), (0, 2), (-2, 1), (-2, -1), (0, -2)]
     self.assertEqual(expected, hexmap.get_neighbors(0, 0, 2))
예제 #5
0
파일: tests.py 프로젝트: yizow/hexgame
 def test_get_neighbors_middle(self):
     hexmap = HexMap.HexMap(5, 2, False)
     expected = [(2, 0), (2, 1), (1, 1), (0, 1), (0, 0)]
     self.assertEqual(expected, hexmap.get_neighbors(1, 0))
예제 #6
0
파일: tests.py 프로젝트: yizow/hexgame
 def test_get_neighbors_clamp_horiz_infinite_vert(self):
     hexmap = HexMap.HexMap(3, 0, False)
     expected = [(1, -1), (1, 0), (0, 1), (0, -1)]
     self.assertEqual(expected, hexmap.get_neighbors(0, 0))
예제 #7
0
파일: tests.py 프로젝트: yizow/hexgame
 def test_get_neighbors_clamp(self):
     hexmap = HexMap.HexMap(3, 3, False)
     expected = [(1, 0), (0, 1)]
     self.assertEqual(expected, hexmap.get_neighbors(0, 0))
예제 #8
0
파일: tests.py 프로젝트: yizow/hexgame
 def test_get_neighbors_infinite(self):
     hexmap = HexMap.HexMap(0, 0, False)
     expected = [(1, -1), (1, 0), (0, 1), (-1, 0), (-1, -1), (0, -1)]
     self.assertEqual(expected, hexmap.get_neighbors(0, 0))
예제 #9
0
파일: tests.py 프로젝트: yizow/hexgame
 def test_contains_infinite(self):
     hexmap = HexMap.HexMap(0, 0, False)
     self.assertEqual(True, hexmap.contains(0, 0))
     self.assertEqual(True, hexmap.contains(5, 5))
     self.assertEqual(True, hexmap.contains(-5, -5))
예제 #10
0
파일: tests.py 프로젝트: yizow/hexgame
 def test_contains(self):
     hexmap = HexMap.HexMap(8, 8, False)
     self.assertEqual(True, hexmap.contains(0, 0))
     self.assertEqual(True, hexmap.contains(5, 5))
     self.assertEqual(False, hexmap.contains(10, 10))
     self.assertEqual(False, hexmap.contains(-5, -5))