added async stone detection thread
This commit is contained in:
48
litris.py
48
litris.py
@@ -45,6 +45,8 @@ class Litris(GameBase):
|
||||
|
||||
self.stone_id_thread = NewStoneID()
|
||||
|
||||
self.move_mode = 1
|
||||
|
||||
|
||||
def reset_field(self):
|
||||
self.state = [[' ' for cols in range(Field.WIDTH)]
|
||||
@@ -93,14 +95,24 @@ class Litris(GameBase):
|
||||
offset_col = current_tetromino.get_offset_column(rotation)
|
||||
print("offset column:", offset_col)
|
||||
self.field.drop(current_tetromino, column)
|
||||
#self.move_stone(column - offset_col, rotation)
|
||||
for i in range(1,5,1):
|
||||
self.move_stone(column - offset_col, rotation)
|
||||
for i in range(1,8,1):
|
||||
self.keyboard.press(Key.down)
|
||||
self.keyboard.release(Key.down)
|
||||
print("direction pressed: drop down")
|
||||
cv.waitKey(50)
|
||||
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()
|
||||
|
||||
|
||||
def update_move_mode(self):
|
||||
if self.move_mode <=3:
|
||||
self.move_mode = self.move_mode + 1
|
||||
elif self.move_mode == 4:
|
||||
self.move_mode = 1
|
||||
|
||||
def get_current_board_state(self):
|
||||
# get an updated image of the game
|
||||
@@ -241,12 +253,30 @@ class Litris(GameBase):
|
||||
else:
|
||||
return None
|
||||
|
||||
def move_stone(self, col_movement, rotation):
|
||||
def move_stone(self, col_movement, rotation, move_mode):
|
||||
if col_movement is None:
|
||||
return
|
||||
|
||||
if move_mode == 1:
|
||||
down = Key.down
|
||||
left = Key.left
|
||||
right = Key.right
|
||||
elif move_mode == 2:
|
||||
down = Key.left
|
||||
left = Key.up
|
||||
right = Key.down
|
||||
elif move_mode == 3:
|
||||
down = Key.up
|
||||
left = Key.right
|
||||
right = Key.left
|
||||
elif move_mode == 4:
|
||||
down = Key.right
|
||||
left = Key.down
|
||||
right = Key.up
|
||||
|
||||
# Press and release space
|
||||
self.keyboard.press(Key.down)
|
||||
self.keyboard.release(Key.down)
|
||||
self.keyboard.press(down)
|
||||
self.keyboard.release(down)
|
||||
print("direction pressed: down")
|
||||
cv.waitKey(120)
|
||||
|
||||
@@ -280,14 +310,14 @@ class Litris(GameBase):
|
||||
|
||||
if col_movement < 0:
|
||||
for i in range(0, col_movement, - 1):
|
||||
self.keyboard.press(Key.left)
|
||||
self.keyboard.release(Key.left)
|
||||
self.keyboard.press(left)
|
||||
self.keyboard.release(left)
|
||||
print("move left 3 pressed")
|
||||
cv.waitKey(40)
|
||||
else:
|
||||
for i in range(0, col_movement, 1):
|
||||
self.keyboard.press(Key.right)
|
||||
self.keyboard.release(Key.right)
|
||||
self.keyboard.press(right)
|
||||
self.keyboard.release(right)
|
||||
print("move right 3 pressed")
|
||||
cv.waitKey(40)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user