شغال دلوقتي علي لعبت" Breakout " و دة الكود الي وصلتلو الي الحين
بس حابب اسمع تعليقاتقم علي الكود و لو في ميزة ممكن اضيفها
ملف main.py
from turtle import Turtle, Screenfrom turtle import Turtle, Screen
from ball import Balls
from paddles import Paddels
from Paddles_target import PaddlesTarget
import time
# إعداد الشاشة
w = Screen()
w.bgcolor("#ADD8E6")
w.setup(width=2000, height=1000)
w.tracer(0)
# إنشاء كائنات
hh = Turtle()
hch = Paddels()
w.listen()
w.onkeypress(hch.run_Left, "Left")
w.onkeypress(hch.run_Right, "Right")
def make_paddles_for():
paddle_pos_1 = [(-850 + i * 190, 470) for i in range(10)]
paddle_pos_2 = [(-850 + i * 170, 150) for i in range(11)]
paddle_pos_3 = [(-850 + i * 150, 310) for i in range(12)]
paddle_pos_4 = [(-850 + i * 130, 230) for i in range(14)]
paddle_pos_5 = [(-850 + i * 110, 390) for i in range(16)]
for position in paddle_pos_1:
PaddlesTarget(position, 7)
for position in paddle_pos_5:
PaddlesTarget(position, 3)
for position in paddle_pos_3:
PaddlesTarget(position, 5)
for position in paddle_pos_4:
PaddlesTarget(position, 4)
for position in paddle_pos_2:
PaddlesTarget(position, 6)
make_paddles_for()
w.update()
w.exitonclick()
ملف ball
لسا شغال علية
from turtle import Turtle
from .Paddles_target import PaddlesTarget
import random
class Balls(Turtle):
def __init__(self):
super().__init__()
self.turtle_shapes = ["turtle", "circle", "square", "triangle"]
self.turtle_colors = ["red","white","blue","green"]
self.choice_0 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
self.choice_weights = [0.2 , 0.2 , 0.2 , 0.1 , 0.2 ,0.2, 0.2 , 0.2 , 0.2]
self.penup()
self.goto(random.randint(-370, 370), 370)
self.check_turtle_properties()
def check_turtle_properties(self):
self.shape_=self.shape(random.choice(self.turtle_shapes))
self.color_=self.color(random.choice(self.turtle_colors))
self.size_=self.shapesize(random.uniform(0.5,1.5))
if (self.shape_ =="turtle" ) and (self.color_ == "white") and ( random.choices(self.choice_0, weights=self.choice_weights[5] ,k=1 == 4 )):
self.shape_
self.color_
elif (self.shape_ =="turtle" ) and (self.color_ != "white") :
self.shape_
self.color_
else:
self.shape_
self.color_
def reset_pos (self):
pass
ملف paddles
from turtle import Turtle
class Paddels(Turtle):
def __init__(self):
super().__init__()
self.color_=["blue","white","green","braen"]
self.shape("square")
self.color("black")
self.shapesize(stretch_wid=1, stretch_len=6)
self.penup()
self.goto(0, -475)
self.move_distance = 30
def run_Left(self):
if self.xcor() > -930:
self.setx(self.xcor() - self.move_distance)
def run_Right(self):
if self.xcor() < 930:
self.setx(self.xcor() + self.move_distance)
ملف Paddles_target
import random
class PaddlesTarget(Turtle):
def __init__(self, position, len__):
super().__init__()
self.color_options = ["blue", "green", "brown"]
self.penup()
self.make_paddles()
self.goto(position)
self.shapesize(stretch_wid=1, stretch_len=len__)
def make_paddles(self):
self.shape("square")
self.color(random.choice(self.color_options))
# Paddle width in the game with different values of stretch_len
# Maximum width
# max_width = 1900
# badding_lift=50
# badding_Right=50
# If stretch_len = 7:
# paddles = 10 * 140 = 700
# distance = 9 * 50 = 200
# total = 1400 + 450 = 1850px
# If stretch_len = 6:
# paddles = 11* 120 = 1320
# distance = 10 * 50 = 500
# total = 1320 + 500 = 1820px
# If stretch_len = 5:
# paddles = 12 * 100 = 600
# distance = 11 * 50 = 250
# total = 1200 + 550 = 1750px
# If stretch_len = 4:
# paddles = 14 * 80 = 560
# distance = 13 * 50 = 300
# total = 1120 + 650 = 1770px
# If stretch_len = 3:
# paddles = 16 * 60 = 960
# distance = 15 * 50 = 350
# total = 960 + 750 = 1710px