Block breaker game

A classic! Here's a simple implementation of a block breaker game in the console:

Game Rules:

Game Code:

import random

# Initialize the game grid
grid = [['#' for _ in range(10)] for _ in range(10)]

# Initialize the ball and paddle positions
ball_x = 5
ball_y = 0
paddle_x = 5
paddle_y = 9

# Game loop
while True:
    # Print the current game state
    for y in range(10):
        for x in range(10):
            if x == ball_x and y == ball_y:
                print('*', end='')
            elif x == paddle_x and y == paddle_y:
                print('-', end='')
            else:
                print(grid[y][x], end='')
        print()

    # Get user input
    user_input = input('Enter arrow key (left/right): ')

    # Move the paddle
    if user_input == 'a':
        paddle_x -= 1
    elif user_input == 'd':
        paddle_x += 1

    # Move the ball
    ball_y += 1
    if ball_y >= 10:
        print('Game Over!')
        break

    # Check for collisions
    if ball_x == paddle_x and ball_y == paddle_y:
        # Ball hits paddle, bounce it back
        ball_y = 0
    elif ball_x == 0 or ball_x == 9:
        # Ball hits wall, bounce it back
        ball_x = 5
    elif ball_y == 9:
        # Ball hits bottom, game over
        print('Game Over!')
        break

    # Check for block breaks
    if grid[ball_y][ball_x] == '#':
        # Block broken, remove it
        grid[ball_y][ball_x] = ' '

    # Check for win condition
    if all(all(cell == ' ' for cell in row) for row in grid):
        print('You win!')
        break

How to Play:

  1. Run the code in your console or terminal.
  2. Use the arrow keys to move the paddle left and right.
  3. The ball will automatically move down the screen.
  4. Try to hit the blocks with the ball to break them.
  5. If the ball hits the bottom of the screen, the game is over.
  6. If you break all the blocks, you win!

Note: This is a very basic implementation, and you can add features like scoring, power-ups, and smoother animations to make the game more engaging.