اذهب إلى المحتوى
  • 1

أرجو المساعدة في إنشاء لعبة بلغة بايثون

صفيه الـ

السؤال

السلام عليكم .. لو سمحتوا ابي اسوي هذي اللعبة لها واجهه بالبايثون  ادري انه عن طريق استدعاء مكتبة tkinter  بس ماعرفت الطريقة ممكن احد يساعدني ):

#ghost Game

from random import randint

print ("===================> Ghost Game <===================")
brave = True
score = 0

while brave :
    ghost_door = randint(1,3)
    print ("Three doors ahead..===> Ghost is behind one of them")
    print ("[+] Choose which door to open [+]")
    door = input ("choose one door from 1 to 3:  ")
    door_num = int(door)
    if door_num > 3 or door_num < 1 :
        print (" {This Number Does't Exist}")
    if door_num < 3 and door_num >= 1 :
        if door_num == ghost_door :
            print ("GHOOOOOOOOOOST")
            brave = False
        else :
            print ("No Ghost, Gooood")
            print ("You enter the next rooom")
            score = score + 1

if brave == False :
    print ("Run Away Ghoooost behind you")
    print ("Game Over , Your Score : %s" % score)

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0

وعليكم السلام @صفيه الـ

لإنشاء الألعاب في البايثون بالطريقة الأمثل هي بإستخدام مكتبة pygame, لكن مثل هذه اللعبة tkinter ربما يكفي لبساطتها.

هذا هو الكود الكامل للعبة بإستخدام tkinter.


from tkinter import *
from random import randint


score = 0
ghost_door = randint(1,3)
door_num = 0

home = Tk()
home.title("Ghoost game")

title_font = ("Times New Roman",16,"bold","underline")
buttons_font = ("Times New Roman",14,"bold")

home_width = 600
home_height = 500

home.resizable(False,False)

screen_width = home.winfo_screenwidth()
screen_height = home.winfo_screenheight()

home_x = (screen_width // 2) - (home_width // 2)
home_y = ((screen_height // 2)- (home_height // 2))- 100

home.geometry(f"{home_width}x{home_height}+{home_x}+{home_y}")


def check_Ghost(doorNo):
    global score
    if doorNo == ghost_door:
        lower_label['text'] = f"GHOOOOOOST,Run away!\nGame Over , Your Score : {score}"
        lower_label.place(x=30,y=400)
    else:
        lower_label['text'] = f"No Ghost, Gooood,You enter the next rooom"
        lower_label.place(x=30,y=400)
        score += 1


game_title = Label(home,font = title_font,text = "Three doors ahead..===> Ghost is behind one of them\nChoose a door" )
game_title.place(x=70,y=30)

door_one = Button(home,font = buttons_font,text = "Door one",width = 12,height = 9,bg = "purple",command = lambda door=1 : check_Ghost(door))
door_one.place(x=30,y=140)


door_two = Button(home,font = buttons_font,text = "Door two",width = 12,height = 9,bg = "purple",command = lambda door=2 : check_Ghost(door))
door_two.place(x=200,y=140)

door_three = Button(home,font = buttons_font,text = "Door three",width = 12,height = 9,bg = "purple",command = lambda door=3 : check_Ghost(door))
door_three.place(x=370,y=140)


lower_label = Label(home,font = title_font,text = "" )


home.mainloop()

أطيب تحياتي.

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...