from Tkinter import *
import random
from time import *
import thread
import sys
sys.setrecursionlimit(sys.maxint)
def callback1(): # difficulty
global diff
diff = difficulty(0)
def callback11(): # difficulty
global diff
diff = difficulty(1)
def callback12(): # difficulty
global diff
diff = difficulty(2)
def callback2(): # start
start()
def callback3(): # exit
root.destroy()
def callback4(event): # up
m.append(0)
def callback5(event): # down
m.append(1)
def callback6(event): # left
m.append(2)
def callback7(event): # right
m.append(3)
def difficulty(x=2):
if x == 0:
return 0.5
if x == 1:
return 0.3
if x == 2:
return 0.1
def createfood():
x = random.randint(0, 39)
y = random.randint(0, 29)
return (x, y)
def pan(now):
for i in range(len(l)):
if lx[i] == now[0] * 20 and ly[i] == now[1] * 20:
return False
def food():
now = createfood()
while pan(now):
now = createfood()
r = f.create_rectangle(now[0] * 20, now[1] * 20, now[0] * 20 + 20, now[1] * 20 + 20, fill='red')
f.update()
z.append(r)
lxf.append(now[0] * 20)
lyf.append(now[1] * 20)
def gameover():
if lx[-1] > 780 or lx[-1] < 0 or ly[-1] > 580 or ly[-1] < 0:
try:
f.create_text(400, 250, text='Game Over', font=('Fixdsys', 40), fill='red', justify=CENTER)
f.create_text(400, 330, text='Ur Score : ' + str(len(l) - 3), font=('Fixdsys', 40), fill='blue', justify=CENTER)
f.create_text(400, 400, text='please click exit', fill='black',font=('Fixdsys', 20))
except:
print 'Game Over'
f.create_text(400,400,text='please click exit',fill='black',font=('Fixdsys', 20))
sleep(100)
for i in range(len(l) - 1):
if lx[i] ==