Tetris game code ­čÄ«

# Renkler
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)

# Pencere boyutu
WINDOW_WIDTH = 400
WINDOW_HEIGHT = 500

# Pencere olu┼čturma
window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
pygame.display.set_caption("Tetris")

# Blok boyutlar─▒
BLOCK_SIZE = 20
BORDER = 5

# Oyun alan─▒ boyutlar─▒
GAME_WIDTH = 10 * BLOCK_SIZE
GAME_HEIGHT = 20 * BLOCK_SIZE

# Oyun alan─▒ koordinatlar─▒
GAME_X = (WINDOW_WIDTH - GAME_WIDTH) // 2
GAME_Y = WINDOW_HEIGHT - GAME_HEIGHT - BORDER

# Blok ┼čekilleri
SHAPES = [
    [(0, 0), (0, 1), (0, 2), (0, 3)],  # I
    [(0, 0), (0, 1), (1, 0), (1, 1)],  # O
    [(0, 0), (1, 0), (2, 0), (2, 1)],  # L
    [(0, 1), (1, 1), (2, 1), (2, 0)],  # J
    [(0, 1), (1, 1), (1, 0), (2, 0)],  # S
    [(0, 0), (1, 0), (1, 1), (2, 1)],  # Z
    [(0, 1), (1, 0), (1, 1), (2, 1)]   # T
]

# Renkler
SHAPE_COLORS = [
    RED,
    GREEN,
    BLUE,
    YELLOW,
    PURPLE,
    ORANGE,
    PINK
]

# Yeni blok olu┼čturma
def new_block():
    shape = random.choice(SHAPES)
    color = random.choice(SHAPE_COLORS)
    x = (GAME_WIDTH - BLOCK_SIZE * max([p[1] for p in shape])) // 2
    y = -BLOCK_SIZE * max([p[0] for p in shape])
    return {"shape": shape, "color": color, "x": x, "y": y}

# Blok ├žizimi
def draw_block(x, y, color):
    pygame.draw.rect(window, color, (GAME_X + x * BLOCK_SIZE, GAME_Y + y * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE))

# Oyun d├Âng├╝s├╝
def game_loop():
    # Ba┼člang─▒├ž de─čerleri
    game_over = False
    score = 0
    clock = pygame.time.Clock()
    current_block = new_block()
    next_block = new_block()
    hold_block = None
    game_board = [[None] * 10 for _ in range(20)]

    # Ana oyun d├Âng├╝s├╝
    while not game_over:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                game_over = True
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    current_block["x"] -= 1

Hello @KayaKartal1! Please edit your postÔÇÖs code to be formatted like this:

```py
Your code here
```

So that it is easier for staff and members of the community to help you with your issue!

PS: if you cannot edit your post, please read around a little to increase your trust level and let you access editing your posts.

Also see this guide on how to share your code:

Do you have a problem with this code? If not this post shouldnÔÇÖt be in the Code Help category but you should share it in the General category. You could show your code to people via YouTube or something similar if you havenÔÇÖt posted this code on Replit. Have a great day :slight_smile: !

1 Like

Are you asking for help or sharing code?