حل اللعبة faling bricks

main.py

from turtle import Turtle,Screen
import random
import time
from shapes import Shapes
from padle import Paddle
from score_board import Score

root = Screen()
root.setup(width=800,height=600)
root.bgcolor(“black”)
root.title(“masa game”)
root.tracer(0)

paddle = Paddle()
shape = Shapes()
score = Score()

sleep = 0.01

root.listen()
root.onkey(paddle.go_right,“Right”)
root.onkey(paddle.go_left,“Left”)
root.update()

game_on = True

while game_on:
root.update()
shape.goto(shape.xcor(),shape.ycor()-1)
time.sleep(sleep)

if shape.ycor() == -250 and shape.distance(paddle) <=50 and shape.shape() == "circle":
    score.score_increas_1()
    shape.shape_pos()

if shape.ycor() == -250 and shape.distance(paddle) <=50 and shape.shape() == "square":
    score.score_increas_2()
    shape.shape_pos()

if shape.ycor() == -250 and shape.distance(paddle) <=50 and shape.shape() == "triangle":
    score.score_zero()
    shape.shape_pos()

if shape.ycor() == -250 and shape.distance(paddle) <=50 and shape.shape() == "turtle" and shape.color()[0] != "white":
    score.score_increas_5()
    shape.shape_pos()

if shape.ycor() <= -300 :
    shape.shape_pos() 



if shape.ycor() == -250 and shape.distance(paddle) <=50 and shape.shape() == "turtle" and shape.color()[0] == "white":
    game_on = False
    break

root.bgcolor(“red”)
score.game_over()

score_board.py
from turtle import Turtle

class Score(Turtle):
def init(self):
super().init()
self.penup()
self.goto(0,250)
self.pencolor(“white”)
self.hideturtle()
self.score = 0
self.display()

def display(self):
    self.write(f"Score : {self.score}",font=("arial",18,"bold"),align="center")

def score_increas_1(self):
    self.clear()
    self.score +=1
    self.display()

def score_increas_2(self):
    self.clear()
    self.score +=2
    self.display()  

def score_zero(self):
    self.clear()
    self.score *= 0
    self.display()          

def score_increas_5(self):
    self.clear()
    self.score += 5
    self.display()     

def game_over(self):
    self.clear()
    self.goto(0,0)
    self.write(f"Game Over",align="center",font=("arial",24,"bold"))         

paddle.py
rom turtle import Turtle

class Paddle(Turtle):
def init(self):
super().init(“square”)
self.penup()
self.color(“white”)
self.goto(0,-270)
self.shapesize(1,5)

def go_right(self):
    self.goto(self.xcor()+30,self.ycor()) 
def go_left(self):
    self.goto(self.xcor()-30,self.ycor())

shapes.py
from turtle import Turtle
import random

class Shapes(Turtle):
def init(self):
super().init()
self.shapes = [“square”,“triangle”,“circle”,“turtle”]
self.colors = [“red”,“white”,“blue”,“yellow”]
self.size = [1,0.75,0.5,1.50,2]
self.position = [-300,300,-250,250,-150,150,-50,50]
self.penup()
self.shape(random.choice(self.shapes))
self.color(random.choice(self.colors))
self.shapesize(random.choice(self.size))
self.goto(self.xcor()+random.choice(self.position),self.ycor()+350)
self.speed(0)

def shape_pos(self):
    self.shape(random.choice(self.shapes))
    self.color(random.choice(self.colors))
    self.shapesize(random.choice(self.size))
    self.goto(0,0)
    self.goto(self.xcor()+random.choice(self.position),350)

ارائكم

إعجاب واحد (1)

رائع اخي احمد :heart_eyes: :heart_eyes: :star_struck: :star_struck:

تجربة اللعبة كانت رائعة وممتعة احسنت في العمل ولكن اقترح عليك ارسال الكود بشكل منسق حتى يسهل على الاخرين تجربة اللعبة

إعجابَين (2)