Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Imports tkinter which is used to draw the canvas on which the images will be placed on.
- from tkinter import *
- import random
- #Main subroutine
- def main():
- global window
- global tkinter
- global canvas
- global cdtimer
- global scorecounter
- global pressed
- pressed = ''
- window = Tk()
- cdtimer = 61
- scorecounter = 0
- _timer = None
- window.title("JailBreak Bob") #Defines the name of the title of the window.
- #Generates the initial canvas.
- canvas = Canvas(width = 960, height = 540, bg = "white")
- mainscreen() #Loops the window until another action is taken otherwise it would end straight away after it runs once.
- #Main Screen
- def mainscreen():
- photo = PhotoImage(file="main.gif") #Allows the image to be assigned to a variable which in this case is 'photo'.
- canvas.bind("<Button-1>", buttonclick_mainscreen) #Allows the left click of the mouse to be used on the canvas.
- canvas.pack(expand = YES, fill = BOTH)
- canvas.create_image(1, 1, image = photo, anchor = NW) #Places the image on to the canvas at the desired coordinates.
- canvas.mainloop()
- #Help Screen
- #The function of this subroutine is the same as mainscreen() except to draw another image.
- def helpscreen():
- photo = PhotoImage(file="helpscreen.gif")
- canvas.bind("<Button-1>", buttonclick_helpscreen)
- canvas.pack(expand = YES, fill = BOTH)
- canvas.create_image(1, 1, image = photo, anchor = NW)
- canvas.mainloop()
- #Game Screen
- #Where the game is played.
- def gamescreen():
- imagelist = ["1.gif","2.gif","3.gif","4.gif","5.gif","6.gif","7.gif","8.gif","9.gif","10.gif","11.gif","12.gif","13.gif","14.gif","15.gif","16.gif","17.gif","18.gif","19.gif","20.gif","21.gif","22.gif","23.gif","24.gif","25.gif","26.gif","27.gif","28.gif","29.gif","30.gif","31.gif","32.gif","33.gif","34.gif","35.gif","36.gif","37.gif","38.gif","39.gif","40.gif","41.gif","42.gif","43.gif","44.gif","45.gif","46.gif","47.gif","48.gif","49.gif","50.gif"]
- answerlistx = [-1, -3, 3, 4, -7, 8, 9, 10, -10, 2, -7, 7, -1, -5, -6, -9, -7, 10, -4, 8, 1, -8, -10, -1, -3, -7, -3, 7, 3, -4, 1, -8, -4, 9, -5, -10, 10, 2, 2, -10, 4, 9, -3, 6, 10, -6, 4, 9, -10, -10]
- answerlisty = [3, -6, -5, 3, -2, 4, -4, -3, 4, -6, 1, 2, 2, 3, 2, -1, -5, 1, -3, 1, -2, -2, -5, -3, -2, -6, -3, 6, 2, 0, -5, 6, -4, 4, 1, -6, 0, -6, 5, 2, 4, -4, -2, 0, -3, -6, -4, 1, -3, 1]
- canvas.bind("<Button-1>", buttonclick_gamescreen)
- canvas.pack(expand = YES, fill = BOTH)
- photo = PhotoImage(file="gamescreen.gif")
- canvas.create_image(1, 1, image = photo, anchor = NW)
- e1 = Entry(canvas, width = 11)
- e2 = Entry(canvas, width = 11)
- canvas.create_window(390, 501, window=e1, anchor = NW)
- canvas.create_window(551, 501, window=e2, anchor = NW)
- canvas.after(1, countdowntimer)
- while cdtimer > 0:
- print("start of while loop")
- randomimage = random.randrange(0,49+1)
- game = PhotoImage(file=imagelist[randomimage])
- images = canvas.create_image(30, 65, image = game, anchor = NW)
- if pressed == 8 and e1 == answerlistx[randomimage] and e2 == answerlisty[randomimage]:
- print("correct")
- canvas.delete(images)
- randomimage = random.randrange(0,49+1)
- scorecounter = scorecounter + 1
- game = PhotoImage(file=imagelist[randomimage])
- images = canvas.create_image(30, 65, image = game, anchor = NW)
- e1.delete(0, END)
- e2.delete(0, END)
- elif pressed == 8 and e1 != answerlistx[randomimage] or pressed == 8 and e2 != answerlisty[randomimage]:
- print("incorrect")
- wronganswer = canvas.create_text(400, 200, text="Incorrect", font="Ubuntu 29 bold", fill='red', anchor=NW)
- e1.delete(0, END)
- e2.delete(0, END)
- canvas.after(1500,(canvas.delete(wronganswer)))
- canvas.mainloop()
- def countdowntimer():
- global cdtimer
- cdtimer -= 1
- cdtext = canvas.create_text(510, 6, text=cdtimer, font="Ubuntu 29 bold", anchor = NW)
- if cdtimer == 0:
- lambda: canvas.after_cancel(_timer)
- cdtimer += 61
- canvas.delete(ALL)
- scorescreen()
- else:
- _timer = canvas.after(1000, lambda: (canvas.delete(cdtext), countdowntimer()))
- #Score Screen
- #The function of this subroutine is the same as mainscreen() except to draw another image.
- def scorescreen():
- global scorecounter
- photo = PhotoImage(file="scorescreen.gif")
- canvas.create_image(1, 1, image = photo, anchor = NW)
- canvas.create_text(660,170, text=scorecounter, font="Ubuntu 36 bold", anchor = NW)
- canvas.bind("<Button-1>", buttonclick_scorescreen)
- scorecounter = scorecounter - scorecounter
- canvas.pack(expand = YES, fill = BOTH)
- canvas.mainloop()
- #Button Click
- def buttonclick_mainscreen(event):
- pressed = ""
- if event.x >18 and event.x <365 and event.y > 359 and event.y < 417 : pressed = 1 #Defines where the mouse can interact with the canvas.
- if event.x >18 and event.x <365 and event.y > 421 and event.y < 473 : pressed = 2 #Defines where the mouse can interact with the canvas.
- if event.x >18 and event.x <365 and event.y > 477 and event.y < 517 : pressed = 3 #Defines where the mouse can interact with the canvas.
- #Commands the program what to do if it was to click on a certain area.
- if pressed == 1 :
- canvas.delete(ALL)
- gamescreen()
- if pressed == 2 :
- canvas.delete(ALL)
- helpscreen()
- if pressed == 3 :
- window.destroy()
- def buttonclick_helpscreen(event):
- pressed = ""
- if event.x >18 and event.x <365 and event.y > 359 and event.y < 417 : pressed = 4 #Defines where the mouse can interact with the canvas.
- if event.x >18 and event.x <365 and event.y > 421 and event.y < 473 : pressed = 5 #Defines where the mouse can interact with the canvas.
- if event.x >18 and event.x <365 and event.y > 477 and event.y < 517 : pressed = 6 #Defines where the mouse can interact with the canvas.
- #Commands the program what to do if it was to click on a certain area.
- if pressed == 4 :
- canvas.delete(ALL)
- gamescreen()
- if pressed == 5 :
- canvas.delete(ALL)
- mainscreen()
- if pressed == 6 :
- window.destroy()
- def buttonclick_gamescreen(event):
- pressed = ""
- if event.x >853 and event.x <957 and event.y > 8 and event.y < 56 : pressed = 7 #Defines where the mouse can interact with the canvas.
- if event.x >666 and event.x <947 and event.y > 491 and event.y < 534 : pressed = 8 #Defines where the mouse can interact with the canvas.
- #Commands the program what to do if it was to click on a certain area.
- if pressed == 7 :
- window.destroy()
- if pressed == 8 :
- print("next")
- def buttonclick_scorescreen(event):
- pressed = ""
- if event.x >300 and event.x <645 and event.y > 361 and event.y < 418 : pressed = 9 #Defines where the mouse can interact with the canvas.
- if event.x >300 and event.x <645 and event.y > 423 and event.y < 474 : pressed = 10 #Defines where the mouse can interact with the canvas.
- if event.x >300 and event.x <645 and event.y > 478 and event.y < 522 : pressed = 11 #Defines where the mouse can interact with the canvas.
- #Commands the program what to do if it was to click on a certain area.
- if pressed == 9 :
- canvas.delete(ALL)
- gamescreen()
- if pressed == 10 :
- canvas.delete(ALL)
- helpscreen()
- if pressed == 11 :
- window.destroy()
- #Runs the main subroutine
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement