Compare commits
2 Commits
069f98910e
...
8850c5de85
Author | SHA1 | Date | |
---|---|---|---|
|
8850c5de85 | ||
8aa0621395 |
13
main.py
13
main.py
@ -38,6 +38,8 @@ def clear_rows(board):
|
||||
board = np.delete(board, clear_indices, axis=0)
|
||||
new_rows = np.zeros((len(clear_indices), board.shape[1]))
|
||||
board = np.vstack([new_rows, board])
|
||||
global score
|
||||
score = update_score(score, len(clear_indices))
|
||||
return board
|
||||
|
||||
|
||||
@ -48,7 +50,7 @@ def calculate_shadow(piece, board, i, j):
|
||||
return i
|
||||
|
||||
|
||||
def display_board(board, piece, i, j):
|
||||
def display_board(board, piece, i, j, score):
|
||||
display = board.copy()
|
||||
shadow_i = calculate_shadow(piece, board, i, j)
|
||||
n, m = piece.shape
|
||||
@ -69,7 +71,7 @@ def display_board(board, piece, i, j):
|
||||
for row in display
|
||||
)
|
||||
)
|
||||
print()
|
||||
print(f"Score: {score}\n")
|
||||
|
||||
|
||||
def game_over(board):
|
||||
@ -80,7 +82,12 @@ def game_over(board):
|
||||
) # Clear the board and continue or call sys.exit() to end
|
||||
|
||||
|
||||
def update_score(score, cleared_rows):
|
||||
return score + cleared_rows
|
||||
|
||||
|
||||
def main():
|
||||
score = 0
|
||||
board = np.zeros((20, 10), dtype=int)
|
||||
piece_types = list(PIECES.keys())
|
||||
current_piece = PIECES[np.random.choice(piece_types)]
|
||||
@ -89,7 +96,7 @@ def main():
|
||||
auto_gravity = True # Auto-gravity enabled by default
|
||||
|
||||
while True:
|
||||
display_board(board, current_piece, i, j)
|
||||
display_board(board, current_piece, i, j, score)
|
||||
if not check_placement(current_piece, board, *START_POS):
|
||||
board = game_over(board)
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user