Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
862 B
1
Indexable
import random
import math

# Define the size of the board (width and height)
BOARD_SIZE = 30

# Create a list to represent the cells of the board
board = []
for i in range(1, BOARD_SIZE):
    row = []
    for j in range(BOARD_SIZE):
        row.append(" ")
    board.append(row)

# Set initial position of the snake at cell [5, 5]
snake_x = 5
snake_y = 5
direction = "right"
speed = 1

def draw_cell(cx, cy, text):
    print(f"[{text}]")

def move():
    if direction == "up":
        new_y = min(cy + speed, BOARD_SIZE - 2)
    elif direction == "down":
        new_y = max(cy - speed, 0)
    elif direction == "left":
        new_x = max(cx - speed, 0)
    else:
        new_x = min(cx + speed, BOARD_SIZE - 1)
    x += new_x - cx
    y += new_y - cy

draw_cell(snake_x, snake_y, "#")
move()
print("Game Over! You lost.")