def __init__(self, display, *args, **kwargs): b_size = WIDTH / SIZE Square.__init__(self, *args, **kwargs) self.rect = pygame.Rect(self.x * b_size, self.y * b_size, b_size, b_size) self.surface = pygame.Surface((b_size, b_size)) self.surface.fill(random_color()) #self.display = kwargs.get('display') self.display = display
def test_init(): s = Square(1, 2) p = (3, 4) t = Square(p, value=1) assert s.x == 1 assert s.y == 2 assert t.x == 3 assert t.y == 4
def test_grid_and_squares(): SIZE = 3 grid = Grid([Column([Square(x,y) for y in range(SIZE)]) for x in range(SIZE)]) assert isinstance(grid[0][0], Square) square = grid[0][0] print square assert (square.x, square.y) == (0,0) square0 = grid[1][2] print square0 assert (square0.x, square0.y) == (1,2)
def execute(self, b, twinId): if 'Move' == self.name: b.move(self.args[0], self.args[1]) elif 'Exchange' == self.name: p = b.board[self.args[1]] b.move(self.args[0], self.args[1]) b.add(p, self.args[0]) elif 'Remove' == self.name: b.drop(self.args[0]) elif 'Add' == self.name: self.args[0].assignOrigin(self.args[1], twinId) b.add(self.args[0], self.args[1]) elif 'Rotate' == self.name: b.rotate(str(self.args[0])) elif 'Mirror' == self.name: b.mirror("%s<-->%s" % (Square(self.args[0]).alg(), Square(self.args[1]).alg())) elif 'Shift' == self.name: p, q = Square(self.args[0]), Square(self.args[1]) b.shift(q.x-p.x, q.y-p.y) elif 'PolishType' == self.name: b.invertColors() elif 'Imitator' == self.name: b.imitators = self.args
def setEnPassant(self): dep = Square(self.departure) arr = Square(self.arrival) self.capture = Square(arr.x, dep.y).value return self
def test_toggle_fails(): s = Square((1,2), value=0) s.toggle(2)
def test_toggle(): s = Square((0,0)) s.toggle(1) assert s.value == 1
def test_toggle_fails(): s = Square((1, 2), value=0) s.toggle(2)
def test_toggle(): s = Square((0, 0)) s.toggle(1) assert s.value == 1