mirror of
https://github.com/kristoferssolo/2048.git
synced 2026-03-22 00:26:26 +00:00
feat(game): add movement
This commit is contained in:
@@ -24,7 +24,22 @@ class Game2048:
|
|||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
def move(self, direction: Direction) -> None:
|
def move(self, direction: Direction) -> None:
|
||||||
pass
|
tmp_board = np.copy(self.board)
|
||||||
|
|
||||||
|
match direction:
|
||||||
|
case Direction.LEFT:
|
||||||
|
self.board = np.apply_along_axis(self.merge, 1, self.board)
|
||||||
|
case Direction.RIGHT:
|
||||||
|
self.board = np.apply_along_axis(self.merge, 1, self.board)
|
||||||
|
self.board = np.flip(self.board, axis=1)
|
||||||
|
case Direction.UP:
|
||||||
|
self.board = np.apply_along_axis(self.merge, 0, self.board)
|
||||||
|
case Direction.DOWN:
|
||||||
|
self.board = np.apply_along_axis(self.merge, 0, self.board)
|
||||||
|
self.board = np.flip(self.board, axis=0)
|
||||||
|
|
||||||
|
if not np.array_equal(self.board, tmp_board):
|
||||||
|
self.add_random_tile()
|
||||||
|
|
||||||
def merge(self, row: np.ndarray) -> np.ndarray:
|
def merge(self, row: np.ndarray) -> np.ndarray:
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user