fromkandinskyimport*fromionimport*fromrandomimportrandintfromtimeimportsleepkd=keydownKE=KEY_EXEKO=KEY_OKdefinit():globalJeuJeu=[[9forminrange(7)]forninrange(6)]# nettoyage du haut de l'écran
fill_rect(0,0,320,39,'white')# nettoyage du plateau de jeu
foriinrange(7):forjinrange(6):jeton(i,j,'white')# Affichage du curseur
defcurseur(x,couleur):draw_string(["v",""][couleur=='white'],30+30*x,22,couleur)# Déplacement du curseur
defdeplacement():globalxdx=kd(KEY_RIGHT)-kd(KEY_LEFT)ifdx!=0:curseur(x,'white')x=(x+dx)%7curseur(x,couleur)whilekd(KEY_LEFT)orkd(KEY_RIGHT):Truedefdescente(x):globalJeul=0whilel<6andJeu[l][x]==9:# tant que la case est libre
sleep(0.1)ifl>0:jeton(x,l-1,'white')Jeu[l-1][x]=9jeton(x,l,couleur)Jeu[l][x]=joueurl+=1whilekd(KE)orkd(KO):Truereturnl-1defjeton(x,y,couleur):draw_string(["o",""][couleur=='white'],30+30*x,46+30*y,couleur)defremplir(x,y,couleur):fill_rect(33+30*x,54+30*y,4,4,couleur)defverif(lig,coeff1,col,coeff2,N):globalvoisinsforvarinrange(1,N+1):ifJeu[lig+coeff1*var][col+coeff2*var]==k:voisins+=1liste_gagnant.append([lig+coeff1*var,col+coeff2*var])else:breakdefcomparaison(a,b,c,d,e,f,g,h,i,j):globalvoisins,maxi_voisins,liste_gagnantvoisins=1liste_gagnant=[[y,x]]verif(a,b,c,d,e)verif(f,g,h,i,j)ifvoisins>=4:foreltinliste_gagnant:remplir(elt[1],elt[0],couleur)maxi_voisins=max(voisins,maxi_voisins)deffin():globalk,maxi_voisinsk=joueurmaxi_voisins=0comparaison(y,-1,x,0,y,y,1,x,0,5-y)#colonne
comparaison(y,0,x,-1,x,y,0,x,1,6-x)#ligne
comparaison(y,-1,x,-1,min(x,y),y,1,x,1,min(6-x,5-y))#diag1
comparaison(y,1,x,-1,min(x,5-y),y,-1,x,1,min(6-x,y))#diag2
ifmaxi_voisins>=4:draw_string("Joueur"+str(k+1)+" a gagné : Puissance"+str(maxi_voisins)+""+"!"*min((maxi_voisins-3),3),10-5*min((maxi_voisins-4),2),3,couleur)curseur(x,'white')draw_string("Appuyer sur EXE",85,21,(160,0,255))draw_string("Score : ",240,110,'purple')score[k]+=1draw_string("J"+str(k+1)+" : "+str(score[k]),240,128+18*k,couleur)ifscore[1-k]==0:draw_string("J"+str(2-k)+" : 0",240,110+18*(2-k),['red','blue'][k])returnTrueelifstr(Jeu).count('9')==0:draw_string("Personne n'a gagné",70,3)curseur(x,'white')draw_string("Appuyer sur EXE",85,21,(160,0,255))returnTruereturnFalsejoueur=0# vaudra 0 ou 1
x=3foriinrange(8):# tracé du plateau
fill_rect(20+30*i,40,1,181,'orange')fill_rect(20,40+min(30*i,30*6),211,1,'orange')score=[0,0]init()whileTrue:couleur=['blue','red'][joueur]curseur(x,couleur)whilenot(kd(KE)orkd(KO)):deplacement()ifJeu[0][x]==9:y=descente(x)iffin():whilenot(kd(KE)orkd(KO)):Trueinit()whilekd(KE)orkd(KO):Truejoueur=1-joueur
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.