0% found this document useful (0 votes)
202 views3 pages

Ludo

This document is a Python script that uses Pygame to create a simple Ludo game interface. It initializes a game window, defines colors and grid size, and includes functions to draw the game board and player pieces. The main game loop handles events and continuously updates the display with the board and randomly placed player pieces.

Uploaded by

askandleawuni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
202 views3 pages

Ludo

This document is a Python script that uses Pygame to create a simple Ludo game interface. It initializes a game window, defines colors and grid size, and includes functions to draw the game board and player pieces. The main game loop handles events and continuously updates the display with the board and randomly placed player pieces.

Uploaded by

askandleawuni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

import pygame

import sys

import random

# Initialize Pygame

pygame.init()

# Constants

WIDTH, HEIGHT = 600, 600

FPS = 30

GRID_SIZE = 15

CELL_SIZE = WIDTH // GRID_SIZE

# Colors

WHITE = (255, 255, 255)

RED = (255, 0, 0)

GREEN = (0, 255, 0)

BLUE = (0, 0, 255)

YELLOW = (255, 255, 0)

# Player colors

PLAYER_COLORS = [RED, GREEN, BLUE, YELLOW]

# Create the game window

screen = pygame.display.set_mode((WIDTH, HEIGHT))


pygame.display.set_caption("Ludo Game")

# Function to draw the board

def draw_board():

for i in range(GRID_SIZE):

for j in range(GRID_SIZE):

color = (255, 255, 255) if (i + j) % 2 == 0 else (200, 200, 200)

pygame.draw.rect(screen, color, (i * CELL_SIZE, j * CELL_SIZE, CELL_SIZE, CELL_SIZE))

# Function to draw a player piece

def draw_piece(x, y, color):

pygame.draw.circle(screen, color, (x * CELL_SIZE + CELL_SIZE // 2, y * CELL_SIZE + CELL_SIZE // 2),


CELL_SIZE // 2)

# Game loop

clock = pygame.time.Clock()

while True:

for event in pygame.event.get():

if event.type == pygame.QUIT:

pygame.quit()

sys.exit()

# Draw the board

draw_board()
# Draw player pieces

for i, color in enumerate(PLAYER_COLORS):

draw_piece(random.randint(0, GRID_SIZE - 1), random.randint(0, GRID_SIZE - 1), color)

# Update the display

pygame.display.flip()

# Cap the frame rate

clock.tick(FPS)

You might also like