Snake game (achieve the goal) -levels mod & normal mod

السلام عليكم ورحمة الله وبركاته

لقد قمت بتطوير لعبة snake game التي تعلمنا كيف نصنعها مع الاستاذ ابراهيم جزاه الله خير الجزاء وانار الله بصيرته

اضفت للعبة شاشة بدء واشياء اخرى سا خبركم بها

لكن اولا لان عدد الاسطر كثيره نوعا ما سارفق كود main هناو الباقي في التعليقات

وصف سريع عن العبة:

1.لعبة منقسمه الى قسمين: وضع عادي ووضع المراحل
2.وضع المراحل (levels mod) يتكون من خمس مراحل متغيرة القوانين يعني في كل مرحله تجد شيء مختلف
3.الاسكور او انا اسميه في اللعبة(the target) لكل مرحله لها target خاص بها هذا خاص بال levels mod
4.الاسكور في الوضع العادي هو نفس الاسكور الموجود في اللعبة الاصل، يعني بيعد من صفر واحد… هكذا
5.big food وده اكل للثعبان لكن اكبر ويعطي نقاط اكثر
5. في وضع (levels mod) في 3 lives او حيوات في كل مرحله واذا خلصوا بتظهر رسالة لقد خسرت والسؤال هل تريد ان تلعب مجددا
6.في وضع ال(levelsmod) اذا اصدمت او خسرت حياه لا يعود ال(targe) الى صفر ويبدا من جديد بل يكون بنفس القيمه ما دام لم تنتهي كل الحيوات

  1. يوجد في الوضع العادي ميزه الجدران المفتوحه اي اذا اصتدمت باي جدار ترجع من الجهه المعاكسه وكذلك في بعض مراحل وضع levels mod

اما بخصوص الواجهه الخاصه باللعبة قبل بدء اللعب فيوجد التالي

1.start وهنا لبدء اللعبة
2.setting ويوجد به 4 خيارات
خيار لتغيير السرعه وخيار لتغيير الوضع الخاص باللعية وخيار الشكل الخاص بالثعبان والرجوع

ملحوظه: في المرحله رقم اربعه death ball بينتقل مكانها بعد ما تاكل 3 مرات.
هذا وصف سرع للعبة، مع اللعلم اللعبة ماذال ينقصها الكثير لهذا اريد منكم المشاركه وتعديل وان تشاركوني بابداعكم، كما ان هناك بعض الوظائف الموجوده باللعبة لم استخدمها بعد :joy:، مثل last food التي بملف food وهي عباره عن طعام خاص يظهر في اخر اللعبة، لم اعرف كيف استخدمها لكن فكره خطرت ببالي ولم اطبقها بعد:joy::joy::joy: اترك لكم الاضافه للتضيفوها بانفسكم وابدعوا…

هتلاقوا في الكود ده تركات جميله جدا ابرزها ازاي عملت فكرة target وازاي ميرجعش صفر بعد الخساره الا اذا الحيوات انتهت، وهتلاقو العقبات لها اشكال خطيره زي كرة الموت Death ball

وغيره وغيره وغيره هتلاقوه بي الكود، اتمني يعجبكم، وفي النهايه حابب اوجه كل امتنان واحترام للاستاذ ابراهيم صوفي المنشاء
ربنا يكرمك ويوفقك ويزيدك ثبات ونور ورضا وعز وشكرا.
ملف main.py

from turtle import Turtle, Screen
from snake import Snake
from food import Food
from lives import Lives
from big_food import Bigfood
from score import scoreboard
from score_normal import scoreboard_normal
from barrier import Barrier
from random import choice
import time

window = Screen()
window.tracer(0)
window.title('Snake Game By "MoHorus"')
window.setup(height=800,width=700)
pen = Turtle()
pen.hideturtle()
pen.penup()
pen.speed('fastest')

text_colors = ["gold", "limegreen", "deepskyblue", "hotpink", "orange", "yellow", "cyan"]
bg_colors = ["purple2", "black", "midnightblue", "darkslateblue", "darkorchid"]
special_nums=[4,7,11,15,19,20]
num = 0
level=1
snake_speed=0.1

snake_shape="square"
shape="Shape >Square"
speed= "Speed >Normal"
mood= "Mood >Levels"
def frame (bg,title):
	window.tracer(0)
	window.bgcolor(bg)
	pen.clear()
	pen.color("black")
	pen.penup()
	pen.goto(0, 250)
	pen.write(title, align="center", font=("arial", 45, "bold"))
	pen.goto(-351, 230)
	pen.pendown()
	pen.pensize(15)
	for _ in range(4):
		pen.fd(700)
		pen.lt(90)
		pen.fd(110)
		pen.lt(90)
	pen.penup()
def start_window():
	frame(bg="gold",title="Snake Game")
	pen.goto(0, -250)
	pen.write("1.Start\n\n2.Sitting\n\n3.Exit", align="center", font=("times new roman",60, "normal"))
	window.update()
def Settings_window():
	frame(bg="purple2",title="SETTINGS")
	pen.goto(0, -330)
	pen.write(f"1-{speed}\n\n2-{mood}\n\n3-{shape}\n\n4-BACK", align="center", font=("Courier", 50, "bold"))
	window.update()
def shape_window():
	frame(bg="purple2",title="SHAPE")
	pen.goto(0, -200)
	pen.write(f"1-square \n\n2-circle\n\n3-BACK", align="center", font=("Courier", 50, "bold"))
	window.update()
def mood_window():
	frame(bg="purple2",title="MOOD")
	pen.goto(0, -250)
	pen.write("1-Normal\n\n2-Levels\n\n3-Exit", align="center", font=("Courier",50, "bold"))
	window.update()
def speed_window():
	frame(bg="purple2",title="SPEED")
	pen.goto(0, -330)
	pen.write("1.Slow\n\n2.Normal\n\n3.Fast\n\n4.Vere Fast", align="center", font=("Courier", 50, "bold"))
	window.update()
def winner():
	window.clear()
	window.tracer(0)
	for i in range(10):  # عدد المرات اللي هيتغير فيها الألوان
		window.bgcolor(choice(bg_colors))  # تغيير خلفية الشاشة
		pen.clear()
		pen.color(choice(text_colors))
		pen.goto(0, 200)
		pen.write("You win", align="center", font=("times new roman", 70, "italic"))
		if i >= 5:
			pen.goto(0, 100)  # تحديد موقع الكلمة تحت
			pen.color(choice(text_colors))
			pen.write("Congratulations!!!", align="center", font=("times new roman", 60, "italic"))
		window.update()  # تحديث الشاشة
		time.sleep(0.7)  # تأخير بسيط لتأثير 
def next_level_window():
	next_level=window.textinput("You Win....", "Now there is only one level left in this game \n\nAt this level the snake's speed will be normal\n\nDid you want to go next level? \n1.yes\n2.no" if level == 4 else 'did you want to go next level?\n1.yes\n2.no')
	while True:
		if next_level:
			if next_level.lower()=="y" or next_level.lower()=="yes" or next_level.lower()=="1":
				return True
			elif next_level.lower()=='n' or next_level.lower() == "no" or next_level.lower()=="2" :
				window.clear()
				return False				
			else:
				next_level=window.textinput("Type Error...",'Please write (y or n)\n\nDid you want to go next level?\n1.yes\n2.no')
		else:
			next_level=window.textinput("No Value",'Please Type your choice...\n\nDid you want to go next level?\n1.yes\n2.no')
def reset_all(target_score):
	global num
	global target
	num=0
	window.clear()
	window.tracer(0)
	the_snake.Reset()
	food2.Reset()
	food.Reset()
	food2.apper()
	live_snake.loss_of_live()
	if level >= 2:
		barrier1.Reset()
		barrier2.Reset()
		barrier1.square()
		barrier2.square()
		if level >= 4:
			barrier3.Reset()
			barrier3.death_ball()
			if level == 5:
				barrier2.x=barrier1.x
				barrier2.y=barrier1.y
				barrier2.death_ball()
	score.Reset()
	if live_snake.num_lives <= 0:
		score.target = 0
	if live_snake.num_lives > 0 :
		score.target = target_score
	score.real_target = target
	score.update_score()
def show_lose_window():
	global num
	global target
	the_snake.snake_died()
	reset_all(target - (target - score.target))
	num = 0	
	if live_snake.num_lives == 0:
		score.lose()
		window.update()
		playagain = window.textinput("You Lose", 'Did you want to try again?\n1.yes\n2.no')
		while True:
			if playagain:
				if playagain.lower() in ['y','n','yes','no','1','2']:
					if playagain.lower()== 'n' or playagain.lower()== 'no' or playagain== '2':
						window.clear()
						window.update()
						return False
					else:
						reset_all(target)
						live_snake.Reset()
						return True
				else:
					playagain = window.textinput("wait....", f'>{playagain}< this is not in choices\nPlease Write (y or n)\n\nDid you want to try again?\n1.yes\n2.no')
			else:
				playagain = window.textinput("wait....", "Please Type your choice...... \n\nDid you want to try again?\n1.yes\n2.no)")
	return True
def the_game():
	global num
	global change_pos
	global target
	n=0
	timer=0
	game = True
	while game:
		the_snake.move()
		window.update()
		for i in range(len(the_snake.turtles)-1):
			if the_snake.head.distance(the_snake.turtles[i])<19:
					game = show_lose_window()
					break
		if the_snake.head.distance(food2) < 19:
			if level == 4:
				food2.apper_normalmood()
				timer +=1
			else:
				food2.apper()
			score.increase_score()
			the_snake.new_segment()
			num+=1
			if num in special_nums:
				food.apper()
		if the_snake.head.distance(food) <24:
			food.hide_food()
			score.great_increase_score()
		if score.target >= target:
			live_snake.num_lives = 0
			food2.hideturtle()
			the_snake.hidesnake()
			score.win()
			window.update()
			return True
		if level ==1 or level==2:
			if the_snake.head.xcor() < -330 or the_snake.head.xcor() > 330 or the_snake.head.ycor() < -340 or the_snake.head.ycor() > 300:
					game = show_lose_window()
			if level == 2:
				if the_snake.head.distance(barrier1)<170 and (-180 <= the_snake.head.xcor() <= 210 and -100 <= the_snake.head.ycor() <= -90 ):
					game = show_lose_window()
				if the_snake.head.distance(barrier2)<170  and (-180 <= the_snake.head.xcor() <= 210 and  80 <= the_snake.head.ycor() <= 120) :
					game = show_lose_window()
				if (-180 <= food2.xcor() <= 210) and (-100 <= food2.ycor() <= -90 or 80 <= food2.ycor() <= 120):
					food2.apper()
		elif level ==3:
			if the_snake.head.xcor() <=-350 or the_snake.head.xcor() >= 350:
				the_snake.head.goto(the_snake.head.xcor()*-1,the_snake.head.ycor())
				n+=1
				if n>=3:
					the_snake.head.goto(-330,the_snake.head.ycor())
					n=0
			if the_snake.head.ycor() < -330 or the_snake.head.ycor() > 280:
				game = show_lose_window()
			if the_snake.head.distance(barrier1) <150 and (230 <=the_snake.head.xcor() <=250 and -200 <= the_snake.head.ycor()<= 100)  :
				game = show_lose_window()
			if the_snake.head.distance(barrier2) <150 and (-260 <=the_snake.head.xcor() <=-240 and -200 <= the_snake.head.ycor()<= 100) :
				game = show_lose_window()
			if (-255 <=food2.xcor() <=-230 or 230 <= food2.xcor()<= 255) and -200 <= food2.ycor() <= 100 :
				food2.apper()
		elif level ==4:
			barrier3.lt(15)
			if the_snake.head.ycor() <= -280 or the_snake.head.ycor() >= 280:
				the_snake.head.goto(the_snake.head.xcor(),(the_snake.head.ycor()*-1))
				n+=1
				timer +=1
				if n>=5:
					if the_snake.head.xcor() >= 280:
						the_snake.head.goto((the_snake.head.xcor()*-1)-40,the_snake.head.ycor()-40)
					if the_snake.head.xcor() <= -280:
						the_snake.head.goto((the_snake.head.xcor()*-1)-40,the_snake.head.ycor()+40)
					n=0
			if the_snake.head.xcor() < -330 or the_snake.head.xcor() > 330:
					game = show_lose_window()
			if the_snake.head.distance(barrier1) <150 and (-90 <=the_snake.head.xcor() <=220 and -280 <= the_snake.head.ycor()<= -230)  :
				game = show_lose_window()
			if the_snake.head.distance(barrier2) <150 and (-90 <=the_snake.head.xcor() <=220 and 230 <= the_snake.head.ycor()<= 280) :
				game = show_lose_window()
			if  the_snake.head.distance(barrier3)<70 and ((-300<=the_snake.head.xcor()<=-200 or 200<=the_snake.head.xcor()<=300) and -50<=the_snake.head.ycor()<=50):
					game = show_lose_window()
			if (-90 <=food2.xcor() <=-220 or -300 <= food2.xcor()<= -200 or 200 <= food2.xcor() <= 300) and (-280 <= food2.ycor() <= -230 or 230 <= food2.ycor() <= 280 or -50 <= food2.ycor() <= 50) :
				food2.apper_normalmood()
			if timer >= 3:
				change_pos *= -1
				barrier3.change(change_pos,0,5,5)
				timer=0
		else:
			timer += 1
			barrier1.monster()
			barrier2.x += 40
			barrier2.goto(barrier2.x,barrier2.y)
			barrier2.death_ball()
			barrier3.lt(20)
			if barrier2.x >= 300:
				barrier2.hideturtle()
				barrier2.Circle.hideturtle()
				barrier2.x= barrier1.x - 20
				barrier2.y = barrier1.y
			if timer == 5:
				barrier3.y *= -1
				barrier3.death_ball()
			if timer >=20:
				barrier1.y -=80
				if barrier1.y <-300:
					barrier1.y = 270
				timer=0
			if the_snake.head.xcor() < -330 or the_snake.head.xcor() > 330 or the_snake.head.ycor() < -340 or the_snake.head.ycor() > 280:
				game = show_lose_window()
			if the_snake.head.distance(barrier2)<50 or the_snake.head.distance(barrier2.Circle) <50:
				game = show_lose_window()
			if the_snake.head.distance(barrier3) <= 50 or the_snake.head.distance(barrier3.Circle) <= 50: 
				game = show_lose_window()
			if food2.distance(barrier3) <= 50 or food2.distance(barrier3.Circle) <= 50: 
				food2.apper()
			window.update()
		time.sleep(snake_speed)
	return False
def the_game_normal():
	global num
	n = 0
	game_on=True
	while game_on:
		the_snake.move()
		window.update()
		time.sleep(snake_speed)
		for i in range(len(the_snake.turtles)-1):
			if the_snake.head.distance(the_snake.turtles[i])<19:
				score2.lose()
				window.update()
				time.sleep(5)
				game_on=False
				break
		if the_snake.head.distance(food2) < 19:
			food2.apper_normalmood()
			score2.increase_score()
			the_snake.new_segment()
			num+=1
			if num in special_nums:
				food.apper()
		if the_snake.head.distance(food) < 22:
			food.hide_food()
			the_snake.new_segment()
			score2.great_increase_score()
		if the_snake.head.xcor() <= -340 or the_snake.head.xcor() >= 340 :
			the_snake.head.goto(the_snake.head.xcor()*-1,the_snake.head.ycor())
			num=0
			n+=1
			if n>=3:
				if the_snake.head.xcor() >= 340:
					the_snake.head.goto((the_snake.head.xcor()*-1)-40,the_snake.head.ycor()-40)
				if the_snake.head.xcor() <= -340:
					the_snake.head.goto((the_snake.head.xcor()*-1)-40,the_snake.head.ycor()+40)
				n=0
		if the_snake.head.ycor() <= -280 or the_snake.head.ycor() >= 280:
			the_snake.head.goto((the_snake.head.xcor()),(the_snake.head.ycor()*-1))
			n+=1
			if n>=3:
				the_snake.head.goto((the_snake.head.xcor(),270))
				n=0
def exit_masseage():  
	window.clear()
	window.bgcolor('black')
	pen.goto(0,100)
	pen.color("white")
	pen.write("This Game Created \n     By MoHorus",align="center",font=("times new roman",50,"italic"))
	pen.goto(0,-200)
	pen.write("Click To Exit...",align="center",font=("arial",20,"bold"))
game_on=True
content_for_menu_message=("snake game","choice 1-3")
while game_on :
	window.clear()
	start_window()
	menu = window.textinput(content_for_menu_message[0], content_for_menu_message[1])
	if menu:
		if menu.isdigit():
			if menu == "1":
				start_play= True
				while start_play:
					pen.clear()					
					food2=Food()
					food=Bigfood()
					if level == 0:
						score2= scoreboard_normal()
						food2.apper_normalmood()
						the_snake=Snake("white",level,snake_shape)
						the_game_normal()
						start_play=False
					else:
						target = 13
						score=scoreboard(target= target)
						level=1
						snake_color="green2"
						the_snake=Snake(snake_color,level,snake_shape)
						live_snake=Lives(snake_color)
						if the_game():
							if next_level_window():
								target = 17
								snake_color="blue2"
								level = 2
								the_snake = Snake(snake_color,level,snake_shape)
								barrier1=Barrier(50,-100,16,1)
								barrier2=Barrier(50,100,16,1)
								reset_all(target)
								live_snake.clear()
								live_snake=Lives(snake_color)
								if the_game():
									if next_level_window():
										target = 23
										snake_color="white"
										level =3
										the_snake = Snake(snake_color,level,snake_shape)
										barrier1.change(250,-50,1,16)
										barrier2.change(-250,-50,1,16)
										reset_all(target)
										live_snake.clear()
										live_snake=Lives(snake_color)
										if the_game():
											if next_level_window():
												target = 25
												snake_color="orange2"
												level =4
												the_snake = Snake(snake_color,level,snake_shape)
												change_pos=250
												barrier3=Barrier(change_pos,0,5,5)
												barrier3.death_ball()
												barrier1.change(50,-250,16,2)
												barrier2.change(50,250,16,2)
												reset_all(target)
												live_snake.clear()
												live_snake=Lives(snake_color)
												if the_game():
													if next_level_window():
														target = 20 #لان بصراحة المرحلة دي صعبه جدا ، كنت عايز 30 بس كده هتكون صعبه جدا والهدف اصلا ان اللعبة تكون ممتعة (^_^)
														snake_speed= 0.1
														snake_color="blue2"
														level =5
														the_snake = Snake(snake_color,level,snake_shape)
														barrier1.change(-300,250,1,10)
														barrier2.change(-250,250,5,3)
														barrier3.change(250,200,5,5)
														reset_all(target)
														live_snake.clear()
														live_snake=Lives(snake_color)
														if the_game():
															winner()
															time.sleep(5)
						start_play=False
			elif menu == "2":
				content_for_settings_message=("Settings", "Choice 1-4")
				while True:
					Settings_window()
					settings_choice = window.textinput(content_for_settings_message[0],content_for_settings_message[1])
					if settings_choice:
						if settings_choice.isdigit():
							if settings_choice == "1":
								content_for_speed_message = ("Speed", "Choice 1-4\n\nor write * to go back")
								while True :
									speed_window()
									speed_choice = window.textinput(content_for_speed_message[0],content_for_speed_message[1])
									if speed_choice:
										if speed_choice=="*" or speed_choice.isdigit():
											if speed_choice in ["1","2","3","4","*"]:
												if speed_choice == "1":
													speed= "Speed >Slow"
													snake_speed=0.2
												if speed_choice == "2":
													speed= "Speed >Normal"
													snake_speed=0.1
												if speed_choice == "3":
													speed= "Speed >Fast"
													snake_speed=0.06
												if speed_choice=='4':
													speed= "Speed >Very Fast"
													snake_speed=0.03
												break
											else:
												content_for_speed_message = ("Choice out","Your choice is out the list\n\nchoice 1-4 \n\nor write * to go back")
										else:
											content_for_speed_message = ("Choice error",f"Wrong entry: {speed_choice}\nPlease enter a number only \nchoice 1-4 \n\nor write * to go back")
									else:
										content_for_speed_message = ("no value","Please enter your choice \n\nchoice 1-4 \n\nor write * to go back")
							elif settings_choice == "2":
								content_for_mood_message = ("mood","choice 1-3")
								while True:
									mood_window()
									mood_choice = window.textinput(content_for_mood_message[0],content_for_mood_message[1])
									if mood_choice:
										if mood_choice.isdigit():
											if mood_choice in ["1","2","3"]:
												if mood_choice =="1":
													level=0
													mood= "Mood >Normal"
												if mood_choice == "2":
													level=1
													mood= "Mood >Levels"
												break
											else:
												content_for_mood_message =  ("Choice out","Your choice is out the list\n\nchoice 1-3 ")
										else:
											content_for_mood_message = ("Choice error",f"Wrong entry: {mood_choice}\nPlease enter a number only \nchoice 1-3 ")
									else:
										content_for_mood_message = ("no value","Please enter your choice \n\nchoice 1-3 ")
							elif settings_choice =="3":
								content_for_shape_message = ("shape","choice 1-3")
								while True:
									shape_window()
									shape_choice = window.textinput(content_for_shape_message[0],content_for_shape_message[1])
									if shape_choice:
										if shape_choice.isdigit():
											if shape_choice in ["1","2","3"]:
												if shape_choice =="1":
													snake_shape="square"
													shape= "Shape >Square"
												if shape_choice == "2":
													snake_shape="circle"
													shape= "Shape >Circle"
												break
											else:
												content_for_shape_message = ("Choice error","Your choice is out the list\n\nchoice 1-3 ")
										else:
											content_for_shape_message = ("Choice error",f"Wrong entry: {shape_choice}\nPlease enter a number only \nchoice 1-3 ")
									else:
										content_for_shape_message = ("no value","Please enter your choice \n\nchoice 1-3 ")
							elif settings_choice == "4":
								pen.clear()
								break
							else:
								content_for_settings_message =("Choice out","Your choice is out the list\n\nchoice 1-3 ")
						else:
							content_for_settings_message = ("Choice error",f"Wrong entry: {settings_choice}\nPlease enter a number only \nchoice 1-3 ")
					else:
						content_for_settings_message = ("no value","Please enter your choice \n\nchoice 1-3 ")
			elif menu == "3":
				game_on=False
			else:
				content_for_menu_message=("Choice out","Your choice is out the list\n\nchoice 1-3 ")
		else:
			content_for_menu_message=("Choice error",f"Wrong entry: {menu}\nPlease enter a number only \nchoice 1-3 ")
	else:
		content_for_menu_message=("no value","Please enter your choice \n\nchoice 1-3 ")
	window.update()
exit_masseage()
window.exitonclick()
إعجابَين (2)

يرجى تسمية الملفات بنفس الاسم المخصص لكل ملف لكي لا يحدث خطاء

إعجابَين (2)

هنا بقية الملفات

score.py

from turtle import Turtle
class scoreboard:
	'''يجب ادخال رقم محدد ليكون هدف '''
	def __init__(self, target):
		super().__init__()
		self.target=0
		self.real_target=target
		self.t=Turtle()
		self.t.penup()
		self.t.hideturtle()
		self.t.color("black")
		self.t.goto(-30,310)
		self.pen=Turtle()
		self.pen.hideturtle()
		self.pen.penup()
		self.update_score()
	def update_score(self):
		self.t.clear()
		self.t.write(f"Target:{self.target}/{self.real_target}", align="center", font=("arial", 35, "bold"))
	def increase_score(self):
		self.target+=1
		self.t.clear()
		self.update_score()
	def great_increase_score(self):
		self.target+=5
		self.t.clear()
		self.update_score()
	def lose(self):
		self.pen.clear()
		self.pen.goto(0,50)
		self.pen.screen.bgcolor('darkred')
		self.pen.color('black')
		self.pen.write("You\nLose",align='center',font=("arial",50,'normal'))
	def win(self):
		self.pen.clear()
		self.pen.goto(0,50)
		self.pen.screen.bgcolor('green2')
		self.pen.color('blue')
		self.pen.write("You \nWin",align='center',font=("arial",50,'normal'))
	def Reset(self):
		self.__init__(self.real_target)

score_normal.py

from turtle import Turtle
class scoreboard_normal(Turtle):
	def __init__(self):
		super().__init__()
		self.score=0
		self.penup()
		self.hideturtle()
		self.color("gold")
		self.goto(0,-330)
		self.update_score()
	def update_score(self):
		self.clear()
		self.write(f"score:{self.score}", align="center", font=("arial", 35, "bold"))
	def increase_score(self):
		self.score+=1
		self.clear()
		self.update_score()
	def great_increase_score(self):
		self.score+=5
		self.clear()
		self.update_score()
	def lose(self):
		self.clear()
		self.goto(0,150)
		self.screen.bgcolor('darkred')
		self.color('white')
		self.write(f"Game\n Over",align='center',font=("arial",50,'bold'))
		self.goto(0,0)
		self.color("green2")
		self.write(f"You got {self.score} Score",align='center',font=("arial",50,'bold'))

food.py

from turtle import Turtle
from random import randrange
class Food(Turtle):
	def __init__(self):
		super().__init__()
		self.penup()
		self.apper()
	def apper(self):
		self.goto(randrange(-320,320,20),randrange(-320,280,20))
		self.color("red")
		self.shapesize(0.7,0.7)
		self.shape('circle')
	def apper_normalmood(self):
		self.goto(randrange(-320,320,20),randrange(-260,280,20))
		self.color("red")
		self.shapesize(0.7,0.7)
		self.shape('circle')
	def last_food(self):
		self.shape("square")
		self.color('white')
		self.goto(randrange(-320,320,20),randrange(-320,280,20))
		self.shapesize(1.3,1.3)
	def Reset(self):
		self.__init__()

big_food.py

from turtle import Turtle
from random import randrange
class Bigfood(Turtle):
	def __init__(self):
		super().__init__()
		self.penup()
		self.color("red")
		self.shape('circle')
		self.shapesize(2.5,2.5)
		self.hide_food()
	def apper(self):
		self.showturtle()
		self.goto(randrange(-240,240,20),randrange(-240,240,20))
		self.color("red")
		self.shape('circle')
	def hide_food(self):
		self.hideturtle()
		self.goto(0,700)
	def Reset(self):
		self.__init__()

barrier.py

from turtle import Turtle, Screen
class Barrier(Turtle):
    """يجب ادخال قيمة الموقع و الطول والعرض\nملحوظة:الحاجز الافتراضي هو مربع واذا غيرته فسوف تحتاج الى النداء على دالة المربع مجددا"""
    def __init__(self, x, y, length, width):
        super().__init__()
        self.x = x
        self.y = y
        self.length = length
        self.width = width
        self.penup()
        self.color("dark red")
        self.showturtle()
        self.Circle = Turtle("circle")
        self.e1 = Turtle('circle')
        self.e2 = Turtle('circle')
        self.eyebrow1 = Turtle('square')
        self.eyebrow2 = Turtle('square')
        self.eyebrow1.setheading(220)
        self.eyebrow2.setheading(-30)
        self.eyebrow1.penup()
        self.eyebrow2.penup()
        self.e1.penup()
        self.e2.penup()
        self.e1.shapesize(0.8,0.8)
        self.e2.shapesize(0.8,0.8)
        self.Circle.penup()
        self.Circle.hideturtle()
        self.Circle.color("dark red")
        self.Circle.shapesize(stretch_wid=self.width, stretch_len=self.length)
        self.square()
    def square(self):
        self.e1.hideturtle()
        self.e2.hideturtle()
        self.eyebrow1.hideturtle()
        self.eyebrow2.hideturtle()
        self.Circle.hideturtle()
        self.shape("square")
        self.goto(self.x, self.y)
        self.shapesize(stretch_wid=self.width, stretch_len=self.length)
    def change(self, x, y, length, width):
        self.x = x
        self.y = y
        self.length = length
        self.width = width
        self.shapesize(stretch_wid=width+1, stretch_len=length+1)
        self.goto(self.x, self.y)
        self.Circle.shapesize(stretch_wid=self.width,stretch_len=self.length)
        self.Circle.goto(self.x, self.y)
    def death_ball(self):
        self.e1.hideturtle()
        self.e2.hideturtle()
        self.eyebrow1.hideturtle()
        self.eyebrow2.hideturtle()
        self.Circle.showturtle()
        self.showturtle()
        self.color("black")
        self.shape("triangle")
        self.goto(self.x, self.y)
        self.shapesize(stretch_wid=self.width+1, stretch_len=self.length+1)
        self.Circle.shapesize(stretch_wid=self.width,stretch_len=self.length)
        self.goto(self.x, self.y)
        self.Circle.goto(self.x, self.y)
    def monster(self):
        self.e1.showturtle()
        self.e2.showturtle()
        self.eyebrow1.showturtle()
        self.eyebrow2.showturtle()
        self.length = 3
        self.width = 10
        self.shapesize(self.width,self.length)
        self.eyebrow1.shapesize(0.3,1)
        self.eyebrow2.shapesize(0.3,1)
        self.shape('square')
        self.goto(self.x, self.y)
        self.e1.goto(self.x-10,self.y+70)
        self.e2.goto(self.x+10,self.y+70)
        self.eyebrow1.goto(self.x +10,self.y+85)
        self.eyebrow2.goto(self.x -10 ,self.y + 85)
    def Reset(self):
    	self.__init__(self.x, self.y, self.length, self.width)

lives.py

from turtle import Turtle
class Lives(Turtle):
	'''يجب ادخال اسم لون '''
	def __init__(self,color):
		super().__init__()
		self.num_lives=3
		self.penup()
		self.hideturtle()
		self.snake_color=color
		self.lives()
	def lives(self):
		self.clear()
		self.color(self.snake_color)
		self.goto(-250, 310)
		self.write(f"Lives:{self.num_lives}", align="center", font=("arial", 35, "bold"))
	def loss_of_live(self):
		self.clear()
		self.num_lives-=1
		self.lives()
	def Reset(self,):
		self.clear()
		self.__init__(self.snake_color)	

snake.py

from turtle import Turtle,Screen
import time
class Snake():
	"""يجب إدخال اللون ورقم المرحلة وشكل الثعبان"""
	def __init__(self,color,num,shape):
		self.w=Screen()
		self.pen=Turtle()
		self.pen.hideturtle()
		self.pen.penup()
		self.pen.color('black')
		self.pen.speed('fastest')
		self.color=color
		self.shape=shape
		self.positions=[(-20,20),(0,20),(20,20)]
		self.turtles=[]
		self.num=num
		self.create_snake()
		self.head=self.turtles[-1]
		self.levels(self.num)
	#إنشاء جسم الثعبان
	def create_snake(self):
			for i in range(len(self.positions)):
				t=Turtle(self.shape)
				t.color(self.color)
				t.penup()
				t.goto(self.positions[i])
				self.turtles.append(t)

		#حركة الثعبان		
	def move(self):
			for i in range(len(self.turtles)-1):
				self.turtles[i].goto(self.turtles[i+1].pos())
			self.head.fd(20)
			self.drive()	
		#زيادة طول الثعبان	
	def new_segment(self):
		turtle=Turtle(self.shape)
		turtle.penup()
		turtle.lt(self.head.heading())
		turtle.goto(self.turtles[0].pos())
		turtle.color(self.head.pencolor())
		self.turtles.insert(0,turtle)
		
		#اخفاء الثعبان والاتجاه الي نقطة البداية
	def hidesnake(self):
		for i in range(len(self.turtles)):
			self.turtles[i].hideturtle()
		#اظهار الثعبان والاتجاه الي نقطة البداية
	def showsnake(self):
		for i in range(len(self.turtles)):
			self.turtles[i].showturtle()
		self.head.goto(20,20)
		#اتجاهات حركة الثعبان
	def up(self):
		if self.head.heading()!=270:
			self.head.setheading(90)
	def down(self):
		if self.head.heading()!=90:
			self.head.setheading(270)
	def left(self):
		if self.head.heading()!=0:
			self.head.setheading(180)
	def right(self):
		if self.head.heading()!=180:
			self.head.setheading(0)
		#توجيه الثعبان عن طريق الازرار
	def drive(self):
		self.w.listen()
		self.w.onkey(self.up,'Up')
		self.w.onkey(self.down,'Down')
		self.w.onkey(self.left,'Left')
		self.w.onkey(self.right,'Right')
	
	def levels(self,num):
		if num==0:
			self.w.bgcolor("black")
			self.pen.goto(-350,-280)
			self.pen.pendown()
			self.pen.color("white")
			self.pen.pensize(5)
			self.pen.fd(700)
		if num==1:
			self.w.bgcolor("cyan4")
			self.pen.clear()
			self.pen.goto(200,310)
			self.pen.color("white")
			self.pen.write("Level 1",align="center",font=("arial",33,"normal"))
			self.pen.color("black")
			self.pen.goto(-340, -340)
			self.pen.pendown()
			self.pen.pensize(15)
			for _ in range(2):
				self.pen.fd(680)
				self.pen.lt(90)
				self.pen.fd(650)
				self.pen.lt(90)
		if num==2:
			self.w.bgcolor("pink2")
			self.pen.clear()
			self.pen.goto(200,310)
			self.pen.color("white")
			self.pen.write("Level 2",align="center",font=("arial",33,"normal"))
			self.pen.color("black")
			self.pen.goto(-340, -340)
			self.pen.pendown()
			self.pen.pensize(15)
			for _ in range(2):
				self.pen.fd(680)
				self.pen.lt(90)
				self.pen.fd(650)
				self.pen.lt(90)		
		if num==3:
			self.w.bgcolor("orange2")
			self.pen.clear()
			self.pen.goto(200,310)
			self.pen.color("white")
			self.pen.write("Level 3",align="center",font=("arial",33,"normal"))
			self.pen.color("black")
			self.pen.goto(-340, -340)
			self.pen.pendown()
			self.pen.pensize(15)
			for _ in range(2):
				self.pen.fd(680)
				self.pen.lt(90)
				self.pen.penup()
				self.pen.fd(640)
				self.pen.lt(90)
				self.pen.pendown()
		if num==4:
			self.w.bgcolor("green")
			self.pen.clear()
			self.pen.goto(200,310)
			self.pen.color("white")
			self.pen.write("Level 4",align="center",font=("arial",33,"normal"))
			self.pen.color("black")
			self.pen.goto(-340, -340)
			self.pen.pendown()
			self.pen.pensize(15)
			for _ in range(2):
				self.pen.penup()
				self.pen.fd(680)
				self.pen.lt(90)
				self.pen.pendown()
				self.pen.fd(640)
				self.pen.lt(90)
		if num==5:
			self.w.bgcolor("cyan4")
			self.pen.clear()
			self.pen.goto(220,310)
			self.pen.color("white")
			self.pen.write("Evil Level (•_•)",align="center",font=("arial",28,"normal"))
			self.pen.color("black")
			self.pen.goto(-340, -350)
			self.pen.pendown()
			self.pen.pensize(15)
			for _ in range(2):
				self.pen.fd(680)
				self.pen.lt(90)
				self.pen.fd(650)
				self.pen.lt(90)
	def update(self):
		self.turtles=[]
		self.positions=[(-20,20),(0,20),(20,20)]
	#عند خسار الثعبان
	def Reset(self):
		self.hidesnake()
		self.__init__(self.color,self.num,self.shape)
	def snake_died(self):
		self.head.color("red")
		self.w.update()
		time.sleep(1)
		self.hidesnake()
إعجابَين (2)

تعديل بسيط يا شباب

في السطر رقم 245: غير قيمة 300 في كل مره ظهرت في الشرط سواء كانت موجب ام سالب الى 270

لضمان ظهور الطعام في مكان ظاهر، وايضا هناك جزء متعلق بالمرحله رقم اربعه لم اوضحها هو ان الطعام ربما لا يظهر، وهذا لان الطعام يمكن ان يظهر اسفل death ball فلاجل تحركها عليك ان تختفي وتظهر ثلاث مرات عن طريق الذهاب الى الفتحات الموجوده لكي تظهر في الجهه المعاكسه