from random import * from kandinsky import * from ion import * from time import * x,y=0,0 width=64 height=44 width_c=5 height_c=5 world=[False,]*height for i in range(height): world[i]=[False,]*width world2=[False,]*height for i in range(height): world2[i]=[False,]*width def draw_all(): for i in range(width): for j in range(height): fill_rect(i*width_c,j*height_c,width_c,height_c,[(255,255,255),(0,0,0)][world[j][i]]) def step_up(): global world for i in range(width): for j in range(height): t=0 t+=world[(j-1)%height][(i-1)%width] t+=world[(j-1)%height][(i)%width] t+=world[(j-1)%height][(i+1)%width] t+=world[(j)%height][(i-1)%width] t+=world[(j)%height][(i+1)%width] t+=world[(j+1)%height][(i-1)%width] t+=world[(j+1)%height][(i)%width] t+=world[(j+1)%height][(i+1)%width] world2[j][i]=[False,False,world[j][i],True,False,False,False,False,False][t] for i in range(0,height): world[i]=world2[i][:] plans=( ((0,0),(2,0),(2,1),(1,1),(1,2)), ((0,1),(0,2),(1,1),(1,2),(1,3),(2,3),(2,2),(3,2),(3,1),(4,1),(3,0),(2,0)), ((0,4),(0,5),(1,4),(1,5),(10,4),(10,5),(10,6),(11,3),(11,7),(12,2),(12,8),(13,8),(13,2),(14,5),(15,3),(15,7),(16,4),(16,5),(16,6),(17,5),(20,2),(20,3),(20,4),(21,2),(21,3),(21,4),(22,1),(22,5),(24,0),(24,1),(24,5),(24,6),(34,2),(34,3),(35,2),(35,3)), ((1,0),(2,0),(3,0),(4,0),(0,1),(4,1),(4,2),(0,3),(3,3),(1,6),(2,7),(2,8),(1,9),(2,9),(0,10),(1,14),(2,14),(3,14),(4,14),(0,15),(4,15),(4,16),(3,17),(0,17)), ((0,0),(1,0),(2,0),(3,0),(0,1),(4,1),(14,1),(0,2),(12,2),(13,2),(1,3),(4,3),(7,3),(8,3),(14,3),(15,3),(16,3),(6,4),(7,4),(8,4),(15,4),(16,4),(17,4),(1,5),(4,5),(7,5),(8,5),(14,5),(15,5),(16,5),(0,6),(12,6),(13,6),(0,7),(4,7),(14,7),(0,8),(1,8),(2,8),(3,8)), ((12,0),(13,0),(11,1),(15,1),(1,2),(0,2),(10,2),(16,2),(20,2),(21,2),(0,3),(1,3),(10,3),(14,3),(16,3),(17,3),(20,3),(21,3),(10,4),(16,4),(11,5),(15,5),(12,6),(13,6)), ((2,0),(3,0),(4,0),(6,0),(1,1),(2,1),(3,1),(4,1),(6,1),(0,2),(1,2),(1,3),(3,3),(2,4),(3,4),(4,4),(5,4),(7,4),(3,5),(4,5),(5,5),(6,8),(7,8),(8,8),(9,8),(10,8),(6,9),(11,9),(6,10),(7,11),(11,11),(9,12)) ) def apply_plan(x=0,y=0,n_plan=0): global world plan=plans[n_plan] for i in plan: world[(y+i[1])%height][(x+i[0])%width]=1 draw_string("LE JEU DE LA VIE",50,50) draw_string("(de John Conway)",70,70) draw_string("Appuies sur OK pour editer",30,90) draw_string("=> Quand vous editer appuies sur\n pour mettre une cellule",0,110) draw_string("ONE",10,130,(255,255,255),(0,0,0)) draw_string("=> Quand vous editer appuies sur\n pour enlever la cellule",0,150) draw_string("ZERO",10,170,(255,255,255),(255,185,50)) sleep(1) while not keydown(KEY_OK): sleep(0.1) draw_all() while True: step_up() draw_all() if keydown(KEY_OK): while keydown(KEY_OK): fill_rect(width_c*x,height_c*y,width_c,height_c,[(100,100,100),(200,200,200)][world[y][x]]) pass while not keydown(KEY_OK): fill_rect(x*width_c,y*height_c,width_c,height_c,[(255,255,255),(0,0,0)][world[y][x]]) for i in range(5): if keydown(i): x=(x+(-1,0,0,1)[i])%width y=(y+(0,-1,1,0)[i])%height fill_rect(width_c*x,height_c*y,width_c,height_c,[(100,100,100),(200,200,200)][world[y][x]]) for i in range(7): if keydown(i+12): apply_plan(x,y,i) draw_all() if keydown(KEY_ONE): world[y][x]=1 if keydown(KEY_ZERO): world[y][x]=0 sleep(0.1)