عايز حل لي المشكل بتاعت امضرب
جربو الكود دة و خلو الكورة تخبط في اول المضرب علشان يحصل المشكلة عندكو
main.py
from paddle import Paddles
from ball import Ball
from turtle import Screen
import time
screen = Screen()
ball = Ball()
screen.setup(800, 600)
screen.tracer(0)
screen.bgcolor("black")
screen.title("PING PONG")
nemo_R = Paddles((350, 0))
nemo_L = Paddles((-350, 0))
screen.listen()
screen.onkey(nemo_R.go_Up, "Up")
screen.onkey(nemo_R.go_Down, "Down")
screen.onkey(nemo_L.go_Up, "1")
screen.onkey(nemo_L.go_Down, "2")
game_on = True
while game_on:
screen.update()
time.sleep(0.1)
ball.goto(ball.xcor()+ball.move_x,ball.ycor()+ball.move_y)
if ball.ycor() >= 290 or ball.ycor() <= -290 :
ball.move_y *=-1
if (ball.xcor()>=330 and ball.distance(nemo_R)<=50) or( ball.xcor()<=-330 and ball.distance(nemo_L)<=50):
ball.move_x *= -1
if ball.xcor() >= 350 or ball.xcor() <= -350:
ball.goto(0, 0)
ball.goto(ball.xcor()-ball.move_x,ball.ycor()-ball.move_y)
ball.move_x *= -1
screen.exitonclick()
ball.py
from turtle import Turtle
class Ball(Turtle):
def __init__(self):
super().__init__()
self.shape("circle")
self.color("white")
self.penup()
self.move_x=10
self.move_y=10
0
paddle.py
from turtle import Turtle
class Paddles(Turtle): # Capitalize the class name
def __init__(self, position): # Fix the spelling of "position"
super().__init__()
self.shape("square")
self.color("white")
self.penup()
self.goto(position)
self.shapesize(stretch_wid=5, stretch_len=1) # stretch_wid for height, stretch_len for width
def go_Up(self):
new_y = self.ycor() + 20 # Increase the movement step if needed
self.goto(self.xcor(), new_y)
def go_Down(self):
new_y = self.ycor() - 20
self.goto(self.xcor(), new_y)