from time import * from kandinsky import * from random import * from ion import * def go(v = 1): score = 0 dx,dy = 0,1 vert,rouge = (0,255,0),(255,0,0) s = [[160,110]] food = True pt = monotonic() while True: ct = monotonic() dt = ct-pt if food: fx = 10 * randint(0,31) fy = 10 * randint(0,21) food = False fill_rect(fx,fy,10,10,rouge) if keydown(KEY_UP): dx,dy = 0,-1 if keydown(KEY_DOWN) : dx,dy = 0,1 if keydown(KEY_LEFT): dx,dy = -1,0 if keydown(KEY_RIGHT): dx,dy = 1,0 if dt>.2-.02*v: pt = monotonic() x = s[0][0] + 10*dx y = s[0][1] + 10*dy if x<0 or x>310 or y<0 or y>210 or get_pixel(x,y)==vert: draw_string("oups !!",5,10) fill_rect(x,y,10,10,rouge) return score s.insert(0,[x,y]) if get_pixel(x,y)!=rouge: q = s.pop() fill_rect(q[0],q[1],10,10,(248,255,248)) else: score += 1 draw_string(str(score),5,10) food=True fill_rect(s[0][0],s[0][1],10,10,vert) go()