litris fixes
This commit is contained in:
6
field.py
6
field.py
@@ -13,7 +13,8 @@ class Field():
|
||||
else:
|
||||
self.state = [[' ' for cols in range(Field.WIDTH)]
|
||||
for rows in range(Field.HEIGHT)]
|
||||
self.cleared_rows = 0
|
||||
self.rotate_90_degree_clckwise(self.state)
|
||||
self.cleared_rows = 1
|
||||
|
||||
def __str__(self):
|
||||
BAR = ' ' + '-' * (Field.WIDTH * 2 + 1) + '\n ' + \
|
||||
@@ -22,7 +23,7 @@ class Field():
|
||||
'{:2d} |'.format(i) + ' '.join(row) + '|'
|
||||
for i, row in enumerate(self.state)]) + '\n' + BAR
|
||||
|
||||
def rotate_90_degree_clckwise(matrix):
|
||||
def rotate_90_degree_clckwise(self, matrix):
|
||||
new_matrix = []
|
||||
for i in range(len(matrix[0])):
|
||||
li = list(map(lambda x: x[i], matrix))
|
||||
@@ -98,6 +99,7 @@ class Field():
|
||||
while len(self.state) < Field.HEIGHT:
|
||||
self.state.insert(0, [' ' for col in range(Field.WIDTH)])
|
||||
self.cleared_rows = self.cleared_rows + 1
|
||||
print("cleared rows: ", self.cleared_rows)
|
||||
|
||||
def copy(self):
|
||||
"""
|
||||
|
||||
42
litris.py
42
litris.py
@@ -96,18 +96,38 @@ class Litris(GameBase):
|
||||
print("offset column:", offset_col)
|
||||
self.field.drop(current_tetromino, column)
|
||||
self.move_stone(column - offset_col, rotation)
|
||||
for i in range(1, 10, 1):
|
||||
self.keyboard.press(Key.down)
|
||||
self.keyboard.release(Key.down)
|
||||
print("direction pressed: drop down")
|
||||
cv.waitKey(50)
|
||||
self.drop_down()
|
||||
self.stone_id_thread.set_pick_up_status(False)
|
||||
print(self.field)
|
||||
if self.field.get_line_count() % 5 == 0:
|
||||
self.field.rotate_state()
|
||||
self.update_move_mode()
|
||||
#if self.field.get_line_count() % 6 == 0:
|
||||
# self.field.rotate_state()
|
||||
# self.update_move_mode()
|
||||
# self.field.cleared_rows = 1
|
||||
|
||||
|
||||
def drop_down(self):
|
||||
if self.move_mode == 1:
|
||||
down = Key.down
|
||||
left = Key.left
|
||||
right = Key.right
|
||||
elif self.move_mode == 2:
|
||||
down = Key.left
|
||||
left = Key.up
|
||||
right = Key.down
|
||||
elif self.move_mode == 3:
|
||||
down = Key.up
|
||||
left = Key.right
|
||||
right = Key.left
|
||||
elif self.move_mode == 4:
|
||||
down = Key.right
|
||||
left = Key.down
|
||||
right = Key.up
|
||||
for i in range(1, 10, 1):
|
||||
self.keyboard.press(down)
|
||||
self.keyboard.release(down)
|
||||
print("drop down pressed:", down)
|
||||
cv.waitKey(50)
|
||||
|
||||
def update_move_mode(self):
|
||||
if self.move_mode <=3:
|
||||
self.move_mode = self.move_mode + 1
|
||||
@@ -277,7 +297,7 @@ class Litris(GameBase):
|
||||
# Press and release space
|
||||
self.keyboard.press(down)
|
||||
self.keyboard.release(down)
|
||||
print("direction pressed: down")
|
||||
print("direction pressed: ", down)
|
||||
cv.waitKey(120)
|
||||
|
||||
if rotation == 3:
|
||||
@@ -312,13 +332,13 @@ class Litris(GameBase):
|
||||
for i in range(0, col_movement, - 1):
|
||||
self.keyboard.press(left)
|
||||
self.keyboard.release(left)
|
||||
print("move left 3 pressed")
|
||||
print("move left 3 pressed:", left)
|
||||
cv.waitKey(40)
|
||||
else:
|
||||
for i in range(0, col_movement, 1):
|
||||
self.keyboard.press(right)
|
||||
self.keyboard.release(right)
|
||||
print("move right 3 pressed")
|
||||
print("move right 3 pressed:", right)
|
||||
cv.waitKey(40)
|
||||
|
||||
def point_in_rect(self, point):
|
||||
|
||||
Reference in New Issue
Block a user