لعبة الطائرة و الوحش

main.py

from turtle import Screen
from player import Plane
from wall import Wall
from monesters import Monesters
from time import sleep
from random import randint
from far import Far
from score import Score

def cre_far(x,y):
                    Far(plane.pos())
def cre_mon():
                    Mon()

screen = Screen()
screen.bgcolor("black")
screen.setup(1000,700)
screen.title("Plane & Monesters")
screen.tracer(0)

wall1 = Wall((0,270))
wall2 = Wall((0,-270))
plane = Plane()
cre_mon()
score = Score()
game = True
sleepp = 0.1
while game:
                    screen.update()
                    sleep(sleepp)
                    screen.listen()
                    screen.onkey(plane.up,"Up")
                    screen.onkey(plane.down,"Down")
                    screen.onkey(plane.up,"w")
                    screen.onkey(plane.down,"s")
                    screen.onscreenclick(cre_far)
                    if Far.distance(Mon):
                                        Mon.goto(450,randint(-140,140))
                                        sleepp * 0.9
                                        score.update_score()
                    if Mon.distance(plane):
                                        game = False
                                        score.game_over()
                    if score.score == 50:
                                        game = False
                                        score.win()
                   if Mon.xcor() > -500:
                                        game = False
                                        score.game_over()
                                        

screen.exitonclick()

score.py

# الاستورادات
from turtle import Turtle
# بداية الكلاس
class Score(Turtle):
                    # الانت ماثد
                    def __init__(self):
                                        super().__init__()
                                        self.score=0
                                        self.color("white")
                                        self.penup()
                                        self.pencolor("white")
                                        self.goto(0,300)
                                        self.hideturtle()
                                        self.write_score()

                    def write_score(self):
                                        self.clear()
                                        self.write(f"Score: {self.score}",font=('Courier',30,'normal'),align='center')

                    def update_score(self):
                                        self.score += 1
                                        self.write_score()

                    def game_over(self):
                                        self.screen.bgcolor("red")
                                        self.home()
                                        self.write(f"GAME OVER\nYoulost",font=('courier',32,'normal'),align='center')
                    def win(self):
                                        self.screen.bgcolor("blue")
                                        self.home()
                                        self.write(f"GAME OVER\nYou Win!",font=('courier',32,'normal'),align='center')

player.py

from turtle import Turtle

class Plane(Turtle):
                    def __init__(self):
                                        super().__init__()
                                        self.color("white")
                                        self.pencolor("red")
                                        self.shapesize(4,5,8)
                                        self.penup()
                                        self.goto(-400,0)
                    def up(self):
                                        if self.ycor() < 140:
                                                            self.goto(self.xcor(),self.ycor() + 20)
                    def down(self):
                                        if self.ycor() > -140:
                                                            self.goto(self.xcor(),self.ycor() - 20)
                                        

monester.py

from turtle import Turtle
from random import randint

class Mon(Turtle):
                    def __init__(self):
                                        super().__init__()
                                        self.color("#BDB76B")
                                        self.penup()
                                        self.goto(450,randint(-140,140))
                                        self.shapesize(4,5,2)
                                        self.left(270)
                                        self.mov = 5
                                        self.move()

                    def move(self):
                                        while True:
                                                            self.goto(self.xcor() + self.mov,self.ycor())

far.py

from turtle import Turtle
class Far(Turtle):
                    def __init__(self,gt):
                                        super().__init__()
                                        self.shape("square")
                                        self.shapesize(0.5,0.5,2)
                                        self.penup()
                                        self.color("white")
                                        self.goto(gt)
                                        self.move()

                    def move(self):
                                        while True:
                                                            self.forward(10)

wall.py

from turtle import Turtle

class Wall(Turtle):
                    def __init__(self, goto):
                                        super().__init__()
                                        self.shape("square")
                                        self.shapesize(10,50)
                                        self.color("blue")
                                        self.penup()
                                        self.goto(goto)
                                        

هذا هو الكود

إعجابَين (2)