Posts

Showing posts from September, 2023

පයිතන් වලින් නයි ගේම් එකක් හදමු

Image
  YouTube ලින්ක් එක Python code import pygame import random # Initialize Pygame pygame.init() # Constants WIDTH, HEIGHT = 400, 400 GRID_SIZE = 20 GRID_WIDTH = WIDTH // GRID_SIZE GRID_HEIGHT = HEIGHT // GRID_SIZE SNAKE_SPEED = 5 # Colors WHITE = (255, 255, 255) GREEN = (0, 255, 0) RED = (255, 0, 0) BLACK = (0, 0, 0,) # Directions UP = (0, -1) DOWN = (0, 1) LEFT = (-1, 0) RIGHT = (1, 0) # Font score = 0 # Initialize the screen screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Snake Game") # Initialize the snake snake = [(GRID_WIDTH // 2, GRID_HEIGHT // 2)] snake_direction = RIGHT # Initialize the food food = (random.randint(0, GRID_WIDTH - 1), random.randint(0, GRID_HEIGHT - 1)) # Game loop running = True clock = pygame.time.Clock() # Display "Press any key to start" message font = pygame.font.Font(None, 36) start_text = font.render("Press any key to start", True, GREEN) screen.fill(WHITE) screen.blit(start_text, (WIDTH // 2 - 140...