شباب دا كود اللعبة ال المستر قال اعملوها :
ف نقطة معرفتش اعملها…
هي ازاي اغير الحجم بشكل متناسق
الملف الرئيسى:
from turtle import Screen
from player import Paddle
from shapes import Shape
import time
from score import Score
window=Screen()
window.bgcolor('black')
window.setup(700,700)
window.title("The challenge")
window.tracer(0)
paddle=Paddle()
segment=Shape()
score=Score()
window.listen()
window.onkey(paddle.go_right,"Right")
window.onkey(paddle.go_left,"Left")
default_sleep=.1
while True:
window.update()
time.sleep(default_sleep)
segment.move()
# اذا اصطدم بالمضرب
if segment.ycor() <= -300 and paddle.distance(segment) <= 50:
if segment.shape() == "turtle" and segment.color()[0] == 'white' :
score.game_over()
break
elif segment.shape() == "circle" or segment.shape() == 'turtle':
score.increase_score(1)
elif segment.shape() == "square":
score.increase_score(2)
elif segment.shape() == 'triangle':
score.score = 0
score.update_score()
segment.appear()
default_sleep *=.8 # Increase the speed
# اذا خرج من الاسفل
if segment.ycor()<=-350:
segment.appear()
default_sleep =.1
window.exitonclick()
ملف اللاعب :
from turtle import Turtle
class Paddle(Turtle):
def __init__(self):
super().__init__()
self.penup()
self.shape('square')
self.shapesize(1,5)
self.color('white')
self.goto(0,-300)
def go_right(self):
if self.xcor() < 300 :
self.goto(self.xcor()+50,self.ycor())
def go_left(self):
if self.xcor() > -300 :
self.goto(self.xcor()-50,self.ycor())
ملف الاشكال
from turtle import Turtle
import random
class Shape(Turtle):
def __init__(self):
super().__init__()
self.penup()
self.shapes=('circle','square','triangle',"turtle")
self.colors=('teal','green','white',"dark olive green",'cyan','lavender','dark gray')
self.appear()
def appear(self):
self.shape(random.choice(self.shapes)) # change the shape
self.color(random.choice(self.colors)) # change the color
self.goto(random.randint(-300,300),350) # change the postion
# self.shapesize(1,random.random()*2)
def move(self):
self.goto(self.xcor(),self.ycor()-10)
ملف السكور
from turtle import Turtle
class Score(Turtle):
def __init__(self):
super().__init__()
self.score=0
self.color("white")
self.penup()
self.goto(0,300)
self.hideturtle()
self.update_score()
def update_score(self):
self.clear()
self.write(self.score,font=('courier',26,'normal'),align='center')
def increase_score(self,point):
self.score += point
self.update_score()
def game_over(self):
# self.getscreen().bgcolor('red')
self.home()
self.write(f"Game over",font=('courier',32,'normal'),align='center')
نتيجة الكود: