So my code is a supposed to be a ascii playable version of tetris, I myself wrote maybe 50% with the other half coming from chatgpt but quality checked and rewrote to made sure it worked, neither chatgpt nor replit can find an error in it but it refuses to show ascii or any graphics at all within the console/terminal.
import curses
import time
import random
# Define the game settings
ROWS = 20
COLS = 10
BLOCK_TYPES = ["I", "J", "L", "O", "S", "T", "Z"]
BLOCK_SHAPES = {
"I": ["####"],
"J": ["# ", "###"],
"L": [" #", "###"],
"O": ["##", "##"],
"S": [" ##", "## "],
"T": [" # ", "###"],
"Z": ["## ", " ##"]
}
BLOCK_COLORS = {
"I": curses.COLOR_CYAN,
"J": curses.COLOR_BLUE,
"L": curses.COLOR_YELLOW,
"O": curses.COLOR_MAGENTA,
"S": curses.COLOR_GREEN,
"T": curses.COLOR_RED,
"Z": curses.COLOR_WHITE
}
SCORES = {
1: 40,
2: 100,
3: 300,
4: 1200
}
def create_block():
"""Create a new random block"""
block_type = random.choice(BLOCK_TYPES)
block_shape = BLOCK_SHAPES[block_type]
block_color = BLOCK_COLORS[block_type]
block_x = COLS // 2 - len(block_shape[0]) // 2
block_y = 0
return {
"type": block_type,
"shape": block_shape,
"color": block_color,
"x": block_x,
"y": block_y
}
def draw_block(screen, block):
"""Draw the block on the screen"""
block_shape = block["shape"]
block_color = block["color"]
block_x = block["x"]
block_y = block["y"]
for i in range(len(block_shape)):
for j in range(len(block_shape[i])):
if block_shape[i][j] == "#":
screen.addstr(block_y + i, block_x + j, "#", curses.color_pair(block_color))
def erase_block(screen, block):
"""Erase the block from the screen"""
block_shape = block["shape"]
block_x = block["x"]
block_y = block["y"]
for i in range(len(block_shape)):
for j in range(len(block_shape[i])):
if block_shape[i][j] == "#":
screen.addstr(block_y + i, block_x + j, " ")
def move_block(block, dx, dy):
"""Move the block by dx and dy"""
block["x"] += dx
block["y"] += dy
def update_board(board, block):
"""Update the board with the current block"""
block_shape = block["shape"]
block_x = block["x"]
block_y = block["y"]
block_type = block["type"]
for i in range(len(block_shape)):
for j in range(len(block_shape[i])):
if block_shape[i][j] == "#":
x = block_x + j
y = block_y + i
board[y][x] = block_type
def check_rows(board):
"""Check if any rows are complete"""
complete_rows = []
for i in range(ROWS):
if 0 not in board[i]:
complete_rows.append(i)
return complete_rows
def remove_rows(board, rows):
"""Remove the complete rows from the board"""
for row in rows:
for i in range(row, 0, -1):
board[i] = board[i-1][:]
board[0] = [0] * COLS
name = __name__
def check_collision(board, block):
"""Check if the block has collided with the board"""
block_shape = block["shape"]
block_x = block["x"]
block_y = block["y"]
for i in range(len(block_shape)):
for j in range(len(block_shape[i])):
if block_shape[i][j] == "#":
x = block_x + j
y = block_y + i
if y >= ROWS or x < 0 or x >= COLS or board[y][x] != 0:
return True
return False
def draw_board(screen, board):
"""Draw the board on the screen"""
for i in range(ROWS):
for j in range(COLS):
if board[i][j] != 0:
color = BLOCK_COLORS[board[i][j]]
screen.addstr(i, j*2, " ", curses.color_pair(color) | curses.A_REVERSE)
def draw_score(screen, score):
"""Draw the score on the screen"""
screen.addstr(ROWS+2, 0, "Score: {}".format(score), curses.color_pair(7))
if name == "main":
curses.wrapper(main)