added score and new delete all the row completed
parent
2cc5862032
commit
cda443d33f
|
@ -33,14 +33,15 @@ class Afutc:
|
|||
self.current_move = np.zeros(shape=(HEIGHT, WIDTH))
|
||||
self.board_center = WIDTH // 2
|
||||
self.current_piece = None
|
||||
self.score = 0
|
||||
self.char = "▣"
|
||||
self.debug = ""
|
||||
|
||||
def is_valid(self, board):
|
||||
for field in (board + self.board).flat:
|
||||
if field == 2:
|
||||
return True
|
||||
return False
|
||||
return False
|
||||
return True
|
||||
|
||||
def get_size(self):
|
||||
return self.stdscr.getmaxyx()
|
||||
|
@ -50,7 +51,7 @@ class Afutc:
|
|||
height_start = (height // 2) - (WIDTH // 2)
|
||||
try:
|
||||
print = lambda x: self.print((" " * height_start) + x + "\n")
|
||||
row = "═" * (self.board.shape[1])
|
||||
row = str(self.score).center(self.board.shape[1], "═")
|
||||
print("ANOTHER F TETRIS CLONE")
|
||||
print(f"╔{row}╗")
|
||||
for n, row in enumerate(self.board + self.current_move):
|
||||
|
@ -64,10 +65,18 @@ class Afutc:
|
|||
self.pause()
|
||||
|
||||
def new_random_piece(self):
|
||||
if all(self.board[-1:, :].flat):
|
||||
new_row = np.zeros(shape=(1, WIDTH))
|
||||
self.board = np.concatenate((new_row, self.board[:-1, :]))
|
||||
|
||||
# Clear rows completed
|
||||
count = 0
|
||||
for i, row in enumerate(self.board):
|
||||
if all(row):
|
||||
count += 1
|
||||
upper = self.board[:i]
|
||||
down = self.board[i + 1:]
|
||||
new_row = np.zeros(shape=(1, WIDTH))
|
||||
self.board = np.concatenate((new_row, upper, down))
|
||||
if count:
|
||||
self.score += 100 if count < 3 else 150
|
||||
# Generate a new piece
|
||||
self.current_move.fill(0.)
|
||||
new_piece = np.array(choice(PIECES))
|
||||
self.current_piece = new_piece.copy()
|
||||
|
@ -75,6 +84,8 @@ class Afutc:
|
|||
for i, row in enumerate(new_piece):
|
||||
for j, value in enumerate(row):
|
||||
self.current_move[i, position + j] = value
|
||||
if not self.is_valid(self.current_move):
|
||||
self.running = False
|
||||
self.pivot = [0, position]
|
||||
|
||||
def move(self, direction):
|
||||
|
@ -87,7 +98,7 @@ class Afutc:
|
|||
temp_board = temp_board[:-1, :]
|
||||
new_row = np.zeros(shape=(1, WIDTH))
|
||||
temp_board = np.concatenate((new_row, temp_board))
|
||||
if self.is_valid(temp_board):
|
||||
if not self.is_valid(temp_board):
|
||||
self.board = self.board + self.current_move
|
||||
self.new_random_piece()
|
||||
else:
|
||||
|
@ -98,7 +109,7 @@ class Afutc:
|
|||
temp_board = temp_board[:, 1:]
|
||||
new_column = np.zeros(shape=(HEIGHT, 1))
|
||||
temp_board = np.concatenate((temp_board, new_column), axis=1)
|
||||
if self.is_valid(temp_board):
|
||||
if not self.is_valid(temp_board):
|
||||
return
|
||||
self.current_move = temp_board
|
||||
self.pivot[1] -= 1
|
||||
|
@ -108,16 +119,12 @@ class Afutc:
|
|||
temp_board = temp_board[:, :-1]
|
||||
new_column = np.zeros(shape=(HEIGHT, 1))
|
||||
temp_board = np.concatenate((new_column, temp_board), axis=1)
|
||||
if self.is_valid(temp_board):
|
||||
if not self.is_valid(temp_board):
|
||||
return
|
||||
self.current_move = temp_board
|
||||
self.pivot[1] += 1
|
||||
|
||||
def rotate(self):
|
||||
# if not self.debug:
|
||||
# self.debug = "-1"
|
||||
|
||||
# self.debug = str(int(self.debug) + 1)
|
||||
temp_board = self.current_move.copy()
|
||||
temp_board.fill(0.)
|
||||
temp_piece = self.current_piece.copy()
|
||||
|
@ -136,7 +143,7 @@ class Afutc:
|
|||
self.rotate()
|
||||
return
|
||||
|
||||
if not self.is_valid(temp_board):
|
||||
if self.is_valid(temp_board):
|
||||
self.current_move = temp_board.copy()
|
||||
self.current_piece = temp_piece.copy()
|
||||
|
||||
|
|
Loading…
Reference in New Issue