frommathimport*fromkandinskyimport*fromionimport*fromtimeimport*fromrandomimport*globallevellevel=1defgame(map):ifmap==0:map_seed0=[randint(5,11),randint(5,8),]map_seed=[map_seed0[0],map_seed0[1],randint(1,map_seed0[0]),randint(1,map_seed0[1]),[randint(2,map_seed0[0]-1),randint(2,map_seed0[1]-1)],[randint(2,map_seed0[0]-1),randint(2,map_seed0[1]-1)],[randint(2,map_seed0[0]-1),randint(2,map_seed0[1]-1)],[randint(1,map_seed0[0]),randint(1,map_seed0[1])],[randint(1,map_seed0[0]),randint(1,map_seed0[1])],[randint(1,map_seed0[0]),randint(1,map_seed0[1])]]else:map_seed=map#t = map_seed
#print("map = " + str(map_seed))
#print("type = " + str(type(map_seed)))
map=[map_seed[0],map_seed[1]]player=[map_seed[2],map_seed[3]]boxes=[map_seed[4],map_seed[5],map_seed[6]]objectives=[map_seed[7],map_seed[8],map_seed[9]]size=23start=monotonic()fill_rect(0,0,320,222,(200,240,240))draw_string("Loading...",0,0,(0,0,0),(200,240,240))fill_rect(size-2,size-2,map[0]*size+4,map[1]*size+4,(200,200,200))# le script massif de render sans aucun saut de ligne
defrender():forxinrange(map[0]):foryinrange(map[1]):if[x+1,y+1]==player:fill_rect((x+1)*size,(y+1)*size,size,size,(0,200,200))fill_rect((x+1)*size+2,(y+1)*size+2,size-4,size-4,(0,255,255))elif ([x+1,y+1]inobjectives)andnot([x+1,y+1]inboxes):fill_rect((x+1)*size,(y+1)*size,size,size,(200,0,200))fill_rect((x+1)*size+2,(y+1)*size+2,size-4,size-4,(255,0,255))draw_string(str((objectives.index([x+1,y+1]))+1),(x+1)*size+6,(y+1)*size+3,(200,0,200),(255,0,255))elif[x+1,y+1]inboxes:if[x+1,y+1]inobjectivesand(boxes.index([x+1,y+1])==objectives.index([x+1,y+1])):fill_rect((x+1)*size,(y+1)*size,size,size,(0,200,0))fill_rect((x+1)*size+2,(y+1)*size+2,size-4,size-4,(0,255,0))draw_string(str((boxes.index([x+1,y+1]))+1),(x+1)*size+6,(y+1)*size+3,(0,200,0),(0,255,0))elif[x+1,y+1]inobjectivesandnot(boxes.index([x+1,y+1])==objectives.index([x+1,y+1])):fill_rect((x+1)*size,(y+1)*size,size,size,(200,100,0))fill_rect((x+1)*size+2,(y+1)*size+2,size-4,size-4,(255,100,0))draw_string(str((boxes.index([x+1,y+1]))+1),(x+1)*size+6,(y+1)*size+3,(200,100,0),(255,100,0))else:fill_rect((x+1)*size,(y+1)*size,size,size,(200,0,0))fill_rect((x+1)*size+2,(y+1)*size+2,size-4,size-4,(255,0,0))draw_string(str((boxes.index([x+1,y+1]))+1),(x+1)*size+6,(y+1)*size+3,(200,0,0),(255,0,0))else:fill_rect((x+1)*size,(y+1)*size,size,size,(220,220,220))render()#print(boxes)
whileTrue:#print(map_seed)
ifkeydown(KEY_ZERO):draw_string("Prochain niveau...",160-(18*5),150,(0,0,0),(200,230,230))sleep(1)#level += 1
#print(boxes)
# commentaires anglais / francais, c'est pas propre ici
# TODO try to understand why map_seed changes itself
game(0)#game(map_seed)
#print(boxes)
#print(map_seed[4])
#print(map_seed)
breakt=round(monotonic()-start)#global level
#print(level)
level=1draw_string("Sokoban - Temps:"+str(t)+"s",0,0,(0,0,0),(200,240,240))ifkeydown(KEY_DOWN):ifnotplayer[1]==map[1]:if[player[0],player[1]+1]inboxes:if (notplayer[1]+1==map[1])and(not[player[0],player[1]+2]inboxes):boxes[boxes.index([player[0],player[1]+1])][1]+=1player[1]+=1else:player[1]+=1render()ifkeydown(KEY_UP):ifnotplayer[1]==1:if[player[0],player[1]-1]inboxes:if (notplayer[1]-1==1)and(not[player[0],player[1]-2]inboxes):boxes[boxes.index([player[0],player[1]-1])][1]-=1player[1]-=1else:player[1]-=1render()ifkeydown(KEY_LEFT):ifnotplayer[0]==1:if[player[0]-1,player[1]]inboxes:if (notplayer[0]-1==1)and(not[player[0]-2,player[1]]inboxes):boxes[boxes.index([player[0]-1,player[1]])][0]-=1player[0]-=1else:player[0]-=1render()ifkeydown(KEY_RIGHT):ifnotplayer[0]==map[0]:if[player[0]+1,player[1]]inboxes:if (notplayer[0]+1==map[0])and(not[player[0]+2,player[1]]inboxes):boxes[boxes.index([player[0]+1,player[1]])][0]+=1player[0]+=1else:player[0]+=1render()ifboxes==objectives:fill_rect(25,40,270,142,(2150,180,180))fill_rect(27,42,266,138,(200,230,230))# tentative de niveaux mais ca marche pas
iflevel==10:draw_string("Game done",160-(9*5),50,(0,0,0),(200,230,230))draw_string("Time : "+str(t)+"s",160-((8+len(str(t)))*5),100,(0,0,0),(200,230,230))foriinrange(7):draw_string("Menu in "+str(8-i),160-(15*5),150,(0,0,0),(200,230,230))sleep(1)menu()else:draw_string("Niveau terminé",160-(14*5),50,(0,0,0),(200,230,230))draw_string("Temps : "+str(t)+"s",160-((9+len(str(t)))*5),100,(0,0,0),(200,230,230))foriinrange(3):draw_string("Prochain niveau dans "+str(3-i),160-(21*5),150,(0,0,0),(200,230,230))sleep(1)level+=1game(0)sleep((map_seed[0]*map_seed[1])/500)defmenu():# bg
fill_rect(0,0,320,222,(2150,180,180))fill_rect(4,4,312,214,(200,230,230))# bt1
fill_rect(130,95,60,24,(2150,180,180))fill_rect(132,97,56,20,(2150,180,180))draw_string("Jouer",160-(5*5),98,(0,0,0),(2150,180,180))# bt2
fill_rect(94,134,135,24,(2150,180,180))fill_rect(96,136,131,20,(200,230,230))draw_string("Comment jouer",160-(13*5),137,(0,0,0),(200,230,230))#
# j'avait envie de mettre ca puis non en fait
#draw_string("by Escartem",200,195,(0,0,0),(200,230,230))
draw_string("Sobokan",160-(7*5),40,(0,0,0),(200,230,230))selected=1sleep(0.5)whileTrue:ifkeydown(KEY_DOWN):selected=2fill_rect(132,97,56,20,(200,230,230))draw_string("Jouer",160-(5*5),98,(0,0,0),(200,230,230))# bt2
fill_rect(96,136,131,20,(2150,200,200))draw_string("Comment jouer",160-(13*5),137,(0,0,0),(2150,200,200))ifkeydown(KEY_UP):selected=1fill_rect(132,97,56,20,(2150,180,180))draw_string("Jouer",160-(5*5),98,(0,0,0),(2150,180,180))# bt2
fill_rect(96,136,131,20,(200,230,230))draw_string("Comment jouer",160-(13*5),137,(0,0,0),(200,230,230))ifkeydown(KEY_OK):ifselected==1:#global level
#level = 1
game(0)else:#pass
htp()sleep(0.1)#game(0)
defhtp():fill_rect(0,0,320,222,(2150,180,180))fill_rect(4,4,312,214,(200,230,230))draw_string("\n\t- vous serez dans un\n\t monde, avec des boites \n\t(en rouge) et des objectifs\n\t(en violet)\n\n\t- Chaque boite et objectif \n\t a un nombre, les boites \n\t doivent etres placees\n\t sur l'objectif \n\t correspondant",0,0,(0,0,0),(200,230,230))sleep(0.5)whileTrue:ifkeydown(KEY_OK):menu()menu()
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.