fromkandinskyimport*fromrandomimportrandint,choicefromtimeimportsleepfrommathimportsqrtfromionimportkeydowncarte=[[666]*32ifiin{0,19}else[666]+[0for_inrange(30)]+[666]foriinrange(20)]# https://coolors.co/ffb531-9471de-2ac5f2-00a676-ee7674
# (255, 181, 49) (148, 113, 222) (42, 197, 242) (0, 166, 118) (163, 22, 33)
# Orange violet bleu vert rouge
col={"ui":(148,113,222),"p":(42,142,242),"h":(163,22,33),"w":(0,166,118),"l":(142,142,142)}player={"x":1,"y":5,"vie":3,"level":False}game={"L":1,"R":6,"E":1}defwait(keys=(0,1,2,3,4)):# input keyboard
whileTrue:forkinkeys:ifkeydown(k):whilekeydown(k):True# Fonction anti-rebond
returnkdefminer():foryinrange(2,19,1):forxinrange(2,31,1):carte[y][x]=0n=21*game["L"]"""Place n bombes sur la carte, win condition, start"""whilen>0:y,x=randint(1,18),randint(2,29)ifcarte[y][x]!=666:carte[y][x]=666n-=1y,x=randint(1,18),1player["x"],player["y"],=1,ycarte[y][x]=0x,y=randint(10,28),choice((0,19))ifx==31:y=randint(3,17)carte[y][x]=42print(x,y)draw_string(str(x)+""+str(y),0,0,(242,)*3,(148,113,222))draw_string(str(x)+""+str(y),180,0,(242,)*3,(148,113,222))defcount(y,x):"""Nombre de bombe dans le voisinage"""b=0foriinrange(-1,2,1):forjinrange(-1,2,1):ifx+i<0orx+i>31ory+j<0ory+j>19:b+=1if0<=x+i<=31and0<=y+j<=19andcarte[y+j][x+i]==666:b+=1returnbdefcolor(y,x):ifyin{0,19}:fill_rect(x*10,y*10,10,10,(0,0,0))elifxin{0,31}:fill_rect(x*10,y*10,10,10,(255,255,255))ifyin{1,18}:fill_rect(x*10,y*10,10,10,(192,192,192))else:fill_rect(x*10,y*10,10,10,(240-48*count(y,x),240-48*count(y,x),240-48*count(y,x)))defgrille():"""debugage only"""foryinrange(20):forxinrange(32):color(y,x)defui():fill_rect(0,200,320,22,(148,113,222))draw_string("nsi.xyz/labyrinth",0,202,(242,)*3,(148,113,222))txt=""forkingame.keys():txt+=k+str(game[k])+""draw_string(txt,270-10*len(txt),202,(242,)*3,(148,113,222))heart("h")draw_string(str(player["vie"]),320-10*len(str(player["vie"])),202,(242,)*3,(148,113,222))defheart(h="h",n=1):x,y=0,0fori,jinenumerate((1,3,2,3,1,4,2,24,1,8,3,6,5,4,7,2,4)):#heart
whilej>0:c=col["ui"]ifi%2==0elsecol[h]fill_rect(295-10*len(str(player["vie"]))+(x%10)*2,203+y*2,2,2,c)x,y,j=x+1,(x+1)//10,j-1defgo(y,x):"""Augmente la couleur de chaque case et deplace le joueur"""print(player["x"],player["y"],x,y,carte[y][x])player["x"],player["y"]=x,yifx<0orx>31ory<0ory>19orcarte[y][x]==666:returnloose()ifcarte[y][x]==42:returnwin()radar()forx0inrange(32):fory0inrange(20):c=max(0,get_pixel(10*x0,10*y0)[0]-24)fill_rect(x0*10,y0*10,10,10,(c,c,c))defradar(p=1):forxinrange(-p,p+1,1):foryinrange(-p,p+1,1):ifx==0andy==0:fill_rect(player["x"]*10,player["y"]*10,10,10,col["p"])elifsqrt(abs(x)**2+abs(y)**2)<=pandplayer["y"]+y<20:c=216-24*count(player["y"]+y,player["x"]+x)fill_rect((player["x"]+x)*10,(player["y"]+y)*10,10,10,(c,c,c))defloose():player["vie"]-=1print("Boom",player,carte[player["y"]][player["x"]])player["level"]=Truedefwin():print("WIN",player,carte[player["y"]][player["x"]])player["vie"]+=1player["level"]=Truegame["L"]+=1game["E"]+=1defplay():passdefemp(p=1):forxinrange(-p,p+1,1):foryinrange(-p,p+1,1):xe=player["x"]+xye=player["y"]+yifxe>0andye>0andxe<31andye<19andcarte[ye][xe]!=42:carte[ye][xe]=0radar(game["R"]+2)definit():fill_rect(0,0,320,200,(0,0,0))n=game["L"]game["R"]=max(2,5-n//2)# Radar range
#game["B"] = 21*game["L"] # Bomb nb
#game["B"] = 15
game["E"]=min(1+n,game["E"]+1)# EMP nb
miner()ui()radar(game["R"])whileplayer["vie"]:player["level"]=Falseinit()whilenotplayer["level"]:k=wait()ifk==4:emp(2)else:player["x"],player["y"]=player["x"]-1*(k==0)+1*(k==3),player["y"]-1*(k==1)+1*(k==2)go(player["y"],player["x"])radar(game["R"])
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.