added first draft litris
This commit is contained in:
50
litris.py
50
litris.py
@@ -41,18 +41,30 @@ BLOCK_FULL = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]]
|
||||
BLOCK_SMALL = [[1, 1], [1, 1]]
|
||||
BLOCK_COL = 9
|
||||
|
||||
BL3_FULL = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 0, 1, 0], [0, 0, 0, 0]]
|
||||
Bl3_COL = 9
|
||||
|
||||
L1_FULL = [[0, 0, 0, 0], [0, 0, 1, 0], [1, 1, 1, 0], [0, 0, 0, 0]]
|
||||
L1_SMALL = [[0, 0, 1], [1, 1, 1]]
|
||||
L1_COL = 8
|
||||
|
||||
L2_FULL = [[0, 0, 0, 0], [1, 1, 1, 0], [0, 0, 1, 0], [0, 0, 0, 0]]
|
||||
L2_COL = 8
|
||||
|
||||
LINE_FULL = [[0, 0, 0, 0], [1, 1, 1, 1], [0, 0, 0, 0], [0, 0, 0, 0]]
|
||||
LINE_SMALL = [[1, 1, 1, 1]]
|
||||
LINE_COL = 8
|
||||
|
||||
DOT_FULL = [[0, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
|
||||
DOT_SMALL = [[1]]
|
||||
DOT_COL = 10
|
||||
|
||||
DDOT_FULL = [[0, 0, 0, 0], [0, 1, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
|
||||
DDOT_COL = 9
|
||||
|
||||
DDDOT_FULL = [[0, 0, 0, 0], [0, 1, 1, 1], [0, 0, 0, 0], [0, 0, 0, 0]]
|
||||
DDDOT_COL = 9
|
||||
|
||||
Z1_FULL = [[0, 0, 0, 0], [0, 0, 1, 1], [0, 1, 1, 0], [0, 0, 0, 0]]
|
||||
Z1_COL = 9
|
||||
|
||||
class Litris(GameBase):
|
||||
|
||||
def __init__(self, overlay):
|
||||
@@ -193,6 +205,12 @@ class Litris(GameBase):
|
||||
for i in range(0, 19, 1):
|
||||
if current_board[e][i] == 0 and current_board[e - 1][i] == 0 and current_board[e][i + 1] == 0 and current_board[e - 1][i + 1] == 0:
|
||||
return i - BLOCK_COL
|
||||
if np.array_equal(stone, BL3_FULL):
|
||||
# block
|
||||
for e in range(19, 17, - 1):
|
||||
for i in range(0, 19, 1):
|
||||
if current_board[e - 1][i] == 0 and current_board[e][i + 1] == 0 and current_board[e - 1][i + 1] == 0:
|
||||
return i - Bl3_COL
|
||||
elif np.array_equal(stone, L1_FULL):
|
||||
# L1
|
||||
for e in range(19, 17, - 1):
|
||||
@@ -200,6 +218,13 @@ class Litris(GameBase):
|
||||
if current_board[e][i] == 0 and current_board[e][i + 1] == 0 and current_board[e][i + 2] == 0 and \
|
||||
current_board[e - 1][i + 2] == 0:
|
||||
return i - L1_COL
|
||||
elif np.array_equal(stone, L2_FULL):
|
||||
# L1
|
||||
for e in range(19, 17, - 1):
|
||||
for i in range(0, 19, 1):
|
||||
if current_board[e - 1][i] == 0 and current_board[e - 1][i + 1] == 0 and current_board[e - 1][i + 2] == 0 and \
|
||||
current_board[e][i + 2] == 0:
|
||||
return i - L2_COL
|
||||
elif np.array_equal(stone, LINE_FULL):
|
||||
# Line
|
||||
for e in range(19, 18, - 1):
|
||||
@@ -213,7 +238,18 @@ class Litris(GameBase):
|
||||
for i in range(0, 19, 1):
|
||||
if current_board[e][i] == 0:
|
||||
return i - DOT_COL
|
||||
|
||||
elif np.array_equal(stone, DDOT_FULL) :
|
||||
# DDot
|
||||
for e in range(19, 18, - 1):
|
||||
for i in range(0, 19, 1):
|
||||
if current_board[e][i] == 0 and current_board[e][i + 1] == 0:
|
||||
return i - DDOT_COL
|
||||
elif np.array_equal(stone, DDDOT_FULL) :
|
||||
# DDot
|
||||
for e in range(19, 18, - 1):
|
||||
for i in range(0, 19, 1):
|
||||
if current_board[e][i] == 0 and current_board[e][i + 1] == 0 and current_board[e][i + 2] == 0:
|
||||
return i - DDDOT_COL
|
||||
|
||||
def move_stone(self, col_movement):
|
||||
if col_movement is None:
|
||||
@@ -221,17 +257,17 @@ class Litris(GameBase):
|
||||
# Press and release space
|
||||
self.keyboard.press(Key.down)
|
||||
self.keyboard.release(Key.down)
|
||||
cv.waitKey(500)
|
||||
cv.waitKey(250)
|
||||
if col_movement < 0:
|
||||
for i in range(0, col_movement, - 1):
|
||||
self.keyboard.press(Key.left)
|
||||
self.keyboard.release(Key.left)
|
||||
cv.waitKey(500)
|
||||
cv.waitKey(250)
|
||||
else:
|
||||
for i in range(0, col_movement, 1):
|
||||
self.keyboard.press(Key.right)
|
||||
self.keyboard.release(Key.right)
|
||||
cv.waitKey(500)
|
||||
cv.waitKey(250)
|
||||
|
||||
def point_in_rect(self, point):
|
||||
for e in range(0, 20, 1):
|
||||
|
||||
Reference in New Issue
Block a user