Demo entry 6786628

ergdfg

   

Submitted by anonymous on Apr 01, 2019 at 12:53
Language: Python. Code size: 17.0 kB.

from tkinter import *
import random
master = Tk()


def callback():
    print("welcome to: celebrity dogs The game")
    master.destroy()


    root1 = Tk()
       

    w1 = Label(root1, text="Enter the number of cards you want to play with", fg="red", font=("Arahoni", 16), bd=10)
    w1.pack()


    e = Entry(root1)
    e.pack()
    e.focus_set()

    def call():
            print("you are playing with", int(e.get()), "cards")
            pnumcards = int(e.get())/2
            cnumcards = int(e.get())/2
            global cnumcards
            global pnumcards 
            totalnumofcards = (int(e.get())/2)
            allcards = (int(e.get()))
            print(totalnumofcards)
            if 4 > int(e.get()) or int(e.get()) > 30:
                
                print("This is an incorrect value")
            
            elif int(e.get())/2 == float:
                print("This is an incorrect value")
                
            else:
                root1.destroy()




                dognames = open("dogs.txt", "r")
                contents = dognames.read().split(",")


                n = 0

                playerocards = 0
                computerocards = 1
                elist = []
                ilist = []
                flist = []
                dlist = []
                plist = []
                clist = []




                for i in range(0, int(totalnumofcards)):
    

                    print(contents[n])
                    n = n + 1
                    plist.append(playerocards)
                    clist.append(computerocards)
                    playerocards = playerocards + 2
                    computerocards = computerocards + 2

                for i in range(0, int(allcards)):
                    elist.append(random.randint(1, 5))
                    ilist.append(random.randint(1, 100))
                    flist.append(random.randint(1, 10))
                    dlist.append(random.randint(1, 10))


                def endgamecwon():
                    mastercwon = Tk()
                    title1 = Label(mastercwon, text = "Computer wins!!!", fg = "red", font=("Arahoni", 16), bg = "gold")
                    title1.pack()

                    losingtxt = Label(mastercwon, text = "the computer collected all the cards", fg = "red", font=("Arahoni", 12))
                    losingtxt.pack()

                    return1 = Button(mastercwon, text = "Return to menu", fg = "red", font=("Arahoni", 10))
                    return1.pack()
                   

                def endgamepwon():
    
                    masterpwon = Tk()
                    title1 = Label(masterpwon, text = "You are the winner!!!", fg = "red", font=("Arahoni", 16), bg = "gold")
                    title1.pack()

                    losingtxt = Label(masterpwon, text = "You collected all the cards", fg = "red", font=("Arahoni", 12))
                    losingtxt.pack()

                    return1 = Button(masterpwon, text = "Return to menu", fg = "red", font=("Arahoni", 10))
                    return1.pack()








                def generatecardc():
                    master1 = Tk()
                    n1 = Label(master1, text=contents[clist[0]], fg="red", font=("Arahoni", 16), bd=10, bg = "light blue")
                    n1.pack()

                    e1 = Label(master1, text="Exercise", fg="blue", font=("Arahoni", 10), bd=4)
                    e1.pack()
                    eb1 = Label(master1, text=elist[clist[0]], width=2)
                    eb1.pack()
                    i1 = Label(master1, text="Inteligence", fg="blue", font=("Arahoni", 10), bd=4)
                    i1.pack()
                    ib1 = Label(master1, text=ilist[clist[0]], width=2)
                    ib1.pack()    

                    f1 = Label(master1, text="Friendliness", fg="blue", font=("Arahoni", 10), bd=4)
                    f1.pack()
                    fb1 = Label(master1, text=flist[clist[0]], width=2)
                    fb1.pack()    

                    d1 = Label(master1, text="Drool", fg="blue", font=("Arahoni", 10), bd=4)
                    d1.pack()
                    db1 = Label(master1, text=dlist[clist[0]], width=2)
                    db1.pack()

                    close1 = Button(master1, text="close", fg="red", font=("Arahoni", 10), bd=4, command=master1.destroy)
                    close1.pack()
    


                def comparescoreforex():
                    generatecardc()
                    global cnumcards
                    global pnumcards
    
                    if elist[plist[0]] >= elist[clist[0]]:
                        rootwin= Tk()
                        winm = Label(rootwin, text="You won that round, woof woof", fg="red", font=("Arahoni", 16), bd=4)
                        winm.pack()
                        dogbone = Label(rootwin, text=('''

      .-.               .-.
     (   `-._________.-'   )
      >=     _______     =<
     (   ,-'`       `'-,   )
      `-'               `-'

'''), font = 'TkFixedFont')
                        dogbone.pack()
                        okb = Button(rootwin, text="woop", width=10, command = lambda:[generatecardp(), rootwin.destroy()])
                        okb.pack()
                        plist.append(plist.pop(0))
                        plist.append(clist.pop(0))
                        cnumcards = cnumcards - 1
                        pnumcards = pnumcards + 1

        
        
        
        

        
                    else:
                        rootlos= Tk()
                        losm = Label(rootlos, text="You lost that round, woof, woof", fg="red", font=("Arahoni", 16), bd=4)
                        losm.pack()
                        ohb = Button(rootlos, text="oh", width=10, command  = lambda:[computerwon(),  rootlos.destroy()])
                        ohb.pack()
                        clist.append(clist.pop(0))
                        clist.append(plist.pop(0))        
                        cnumcards = cnumcards + 1
                        pnumcards = pnumcards - 1

        
        







                def comparescoreforint():
                    generatecardc()
                    global cnumcards
                    global pnumcards  
    
                    if ilist[plist[0]] >= ilist[clist[0]]:
                        rootwin= Tk()
                        winm = Label(rootwin, text="You won that round, woof woof", fg="red", font=("Arahoni", 16), bd=4)
                        winm.pack()
                        dogbone = Label(rootwin, text=('''

      .-.               .-.
     (   `-._________.-'   )
      >=     _______     =<
     (   ,-'`       `'-,   )
      `-'               `-'

'''), font = 'TkFixedFont')
                        dogbone.pack()
                        okb = Button(rootwin, text="woop", width=10, command = lambda:[generatecardp(), rootwin.destroy()])
                        okb.pack()
                        plist.append(plist.pop(0))
                        plist.append(clist.pop(0))
                        cnumcards = cnumcards - 1
                        pnumcards = pnumcards + 1

                
        

        
                    else:
                        rootlos= Tk()
                        losm = Label(rootlos, text="You lost that round, woof, woof", fg="red", font=("Arahoni", 16), bd=4)
                        losm.pack()
                        ohb = Button(rootlos, text="oh", width=10, command  = lambda:[computerwon(), rootlos.destroy()])
                        ohb.pack()
                        clist.append(clist.pop(0))
                        clist.append(plist.pop(0))
                        cnumcards = cnumcards + 1
                        pnumcards = pnumcards - 1

        


            

                def comparescoreforfr():
                    generatecardc()
                    global cnumcards
                    global pnumcards    
    
                    if flist[plist[0]] >= flist[clist[0]]:
                        rootwin= Tk()
                        winm = Label(rootwin, text="You won that round, woof woof", fg="red", font=("Arahoni", 16), bd=4)
                        winm.pack()
                        dogbone = Label(rootwin, text=('''

      .-.               .-.
     (   `-._________.-'   )
      >=     _______     =<
     (   ,-'`       `'-,   )
      `-'               `-'

'''), font = 'TkFixedFont')
                        dogbone.pack()
                        okb = Button(rootwin, text="woop", width=10, command = lambda:[generatecardp(), rootwin.destroy()])
                        okb.pack()
                        plist.append(plist.pop(0))
                        plist.append(clist.pop(0))
                        cnumcards = cnumcards - 1
                        pnumcards = pnumcards + 1

        

        
                    else:
                        rootlos= Tk()
                        losm = Label(rootlos, text="You lost that round, woof, woof", fg="red", font=("Arahoni", 16), bd=4)
                        losm.pack()
                        ohb = Button(rootlos, text="oh", width=10, command  = lambda:[computerwon(), rootlos.destroy()])
                        ohb.pack()
                        clist.append(clist.pop(0))
                        clist.append(plist.pop(0))        
                        cnumcards = cnumcards + 1
                        pnumcards = pnumcards - 1


        


                def comparescorefordrool():


                    generatecardc()
                    global cnumcards
                    global pnumcards    
    
                    if dlist[plist[0]] <= dlist[clist[0]]:
                        rootwin= Tk()
                        winm = Label(rootwin, text="You won that round, woof woof", fg="red", font=("Arahoni", 16), bd=4)
                        winm.pack()
                        dogbone = Label(rootwin, text=('''

      .-.               .-.
     (   `-._________.-'   )
      >=     _______     =<
     (   ,-'`       `'-,   )
      `-'               `-'

'''), font = 'TkFixedFont')
                        dogbone.pack()
                        okb = Button(rootwin, text="woop", width=10, command = lambda:[generatecardp(),rootwin.destroy()])
                        okb.pack()
                        plist.append(plist.pop(0))
                        plist.append(clist.pop(0))
                        cnumcards = cnumcards - 1
                        pnumcards = pnumcards + 1

        

        
                    else:
                        rootlos = Tk()
                        losm = Label(rootlos, text="You lost that round, woof, woof", fg="red", font=("Arahoni", 16), bd=4)
                        losm.pack()
                        ohb = Button(rootlos, text="oh", width=10, command  =  lambda:[computerwon(), rootlos.destroy()])
                        ohb.pack()
                        clist.append(clist.pop(0))
                        clist.append(plist.pop(0))        
                        cnumcards = cnumcards + 1
                        pnumcards = pnumcards - 1

                
        

                def generatecardp():
                    if int(pnumcards) == 2*(totalnumofcards):
                        endgamepwon()
                    else:
                        master2 = Tk()
                        n1 = Label(master2, text=contents[plist[0]], fg="red", font=("Arahoni", 16), bd=10, bg = "light green")
                        n1.pack()

                        e1 = Label(master2, text="Exercise", fg="blue", font=("Arahoni", 10), bd=4)
                        e1.pack()
                        eb1 = Button(master2, text=elist[plist[0]], width=2, command = lambda:[comparescoreforex(), master2.destroy()])
                        eb1.pack()

                        i1 = Label(master2, text="Inteligence", fg="blue", font=("Arahoni", 10), bd=4)
                        i1.pack()
                        ib1 = Button(master2, text=ilist[plist[0]], width=2, command = lambda:[comparescoreforint(), master2.destroy()])
                        ib1.pack()    

                        f1 = Label(master2, text="Friendliness", fg="blue", font=("Arahoni", 10), bd=4)
                        f1.pack()
                        fb1 = Button(master2, text=flist[plist[0]], width=2, command = lambda:[comparescoreforfr(), master2.destroy()])
                        fb1.pack()    

                        d1 = Label(master2, text="Drool", fg="blue", font=("Arahoni", 10), bd=4)
                        d1.pack()
                        db1 = Button(master2, text=dlist[plist[0]], width=2, command = lambda:[comparescorefordrool(), master2.destroy()])
                        db1.pack()
    
                def generatecardc2():
    
                    master4 = Tk()
                    n1 = Label(master4, text=contents[clist[0]], fg="red", font=("Arahoni", 16), bd=10)
                    n1.pack()

                    e1 = Label(master4, text="Exercise", fg="blue", font=("Arahoni", 10), bd=4)
                    e1.pack()
                    eb1 = Label(master4, text=elist[clist[0]], width=2)
                    eb1.pack()
                    i1 = Label(master4, text="Inteligence", fg="blue", font=("Arahoni", 10), bd=4)
                    i1.pack()
                    ib1 = Label(master4, text=ilist[clist[0]], width=2)
                    ib1.pack()    

                    f1 = Label(master4, text="Friendliness", fg="blue", font=("Arahoni", 10), bd=4)
                    f1.pack()
                    fb1 = Label(master4, text=flist[clist[0]], width=2)
                    fb1.pack()    

                    d1 = Label(master4, text="Drool", fg="blue", font=("Arahoni", 10), bd=4)
                    d1.pack()
                    db1 = Label(master4, text=dlist[clist[0]], width=2)
                    db1.pack()

                    close1 = Button(master4, text="close", fg="red", font=("Arahoni", 10), bd=4, command= master4.destroy)
                    close1.pack()



                def computerwon():
                    if int(cnumcards) == 2*(totalnumofcards):
                        endgamecwon()
                    else:
                        a = random.randint(1, 4)
                        if a == 1:
                            comparescoreforex()
                        elif a == 2:
                            comparescoreforint()
                        elif a == 3:
                            comparescoreforfr()
                        else:
                            comparescorefordrool()
        
                        master3 = Tk()
                        n1 = Label(master3, text=contents[plist[0]], fg="red", font=("Arahoni", 16), bd=10, bg = "light green")
                        n1.pack()

                        e1 = Label(master3, text="Exercise", fg="blue", font=("Arahoni", 10), bd=4)
                        e1.pack()
                        eb1 = Label(master3, text=elist[plist[0]], width=2, font=("Arahoni", 10), bd=4 )
                        eb1.pack()

                        i1 = Label(master3, text="Inteligence", fg="blue", font=("Arahoni", 10), bd=4)
                        i1.pack()
                        ib1 = Label(master3, text=ilist[plist[0]], width=2,font=("Arahoni", 10), bd=4 )
                        ib1.pack()    

                        f1 = Label(master3, text="Friendliness", fg="blue", font=("Arahoni", 10), bd=4)
                        f1.pack()
                        fb1 = Label(master3, text=flist[plist[0]], width=2, font=("Arahoni", 10), bd=4 )
                        fb1.pack()    

                        d1 = Label(master3, text="Drool", fg="blue", font=("Arahoni", 10), bd=4)
                        d1.pack()
                        db1 = Label(master3, text=dlist[plist[0]], width=2,font=("Arahoni", 10), bd=4 )
                        db1.pack()    
    
                        close4 = Button(master3, text="close", fg="red", font=("Arahoni", 10), bd=4, command =  master3.destroy)
                        close4.pack()
            

                generatecardp()
    


    b = Button(root1, text="Play", width=10, command=call)
    b.pack()


       
       








def callback2():
    print("you Quit")
    master.destroy()



w = Label(master, text="Welcome to the celebrity dog game", fg="red", font=("Arahoni", 16), bd=10)
w.pack()


b = Button(master, text="Play game", bd=(5), command=callback)
b.pack()

b1 = Button(master, text="Quit", bd=(5), command=callback2)
b1.pack()


mainloop()

This snippet took 0.03 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).