Найти тему
Простая игра Баскетбол на Python
import random def create_basketball_game(): teams = ["Team A", "Team B"] score = [0, 0] while True: team = random.choice(teams) points = random.randint(1, 3) if team == "Team A": score[0] += points else: score[1] += points print(f"{team} scored {points} points!") print(f"Score: {teams[0]} {score[0]} - {score[1]} {teams[1]}") if score[0] >= 21 or score[1] >= 21: break if score[0] > score[1]: print(f"{teams[0]} wins!") else: print(f"{teams[1]}...
1 год назад
Базовая реализация игры в пинг-понг с использованием модуля черепахи в Python.
import turtle # Create the game window window = turtle.Screen() window.title("Ping Pong Game") window.bgcolor("black") window.setup(width=800, height=600) window.tracer(0) # Create the paddle A paddle_a = turtle.Turtle() paddle_a.speed(0) paddle_a.shape("square") paddle_a.color("white") paddle_a.shapesize(stretch_wid=6, stretch_len=1) paddle_a.penup() paddle_a.goto(-350, 0) # Create the paddle B paddle_b = turtle.Turtle() paddle_b.speed(0) paddle_b.shape("square") paddle_b.color("white") paddle_b.shapesize(stretch_wid=6, stretch_len=1) paddle_b.penup() paddle_b.goto(350, 0) # Create the ball ball = turtle...
1 год назад
Код игры Змейка (Python)
import pygame import time import random # Initialize the game pygame.init() # Define the colors white = (255, 255, 255) yellow = (255, 255, 102) black = (0, 0, 0) red = (213, 50, 80) green = (0, 255, 0) blue = (50, 153, 213) # Set the width and height of the display window dis_width = 800 dis_height = 600 # Create the display window dis = pygame.display.set_mode((dis_width, dis_height)) pygame.display.set_caption('Snake Game') clock = pygame.time.Clock() snake_block = 10 snake_speed = 30 font_style = pygame.font.SysFont(None, 50) score_font = pygame.font.SysFont(None, 35) def our_snake(snake_block, snake_list): for x in snake_list: pygame...
1 год назад
Базовая структура игры Angry Birds
import pygame from pygame.locals import * # Initialize the game pygame.init() # Set up the game window screen_width = 800 screen_height = 600 screen = pygame.display.set_mode((screen_width, screen_height)) pygame.display.set_caption("Angry Birds") # Game loop running = True while running: for event in pygame.event.get(): if event.type == QUIT: running = False # Update game logic # Render graphics pygame.display.update() # Quit the game pygame.quit() В этом фрагменте кода я создал базовую структуру игры Angry Birds, используя язык программирования Python и библиотеку Pygame...
1 год назад
Angry birds game (Python code)
import pygame import random # Initialize the game pygame.init() # Set up the game window screen_width = 288 screen_height = 512 screen = pygame.display.set_mode((screen_width, screen_height)) pygame.display.set_caption("Flappy Bird") # Load the background image background = pygame.image.load("background.png") # Load the bird image bird = pygame.image.load("bird.png") bird_rect = bird.get_rect(center=(50, screen_height // 2)) # Set up the gravity and bird movement variables gravity = 0.25 bird_movement = 0 # Set up the pipe variables pipe_width = 52 pipe_height = random.randint(150, 350) pipe_gap = 100 pipe_x = screen_width pipe_y = random...
1 год назад