Adaptation du jeu du solitaire : les huit ennemis.
Le but est de faire passer les huit pions rouges à la place des huit pions bruns et réciproquement.
On peut déplacer les pions directement ou en sautant par-dessus un autre pion. Les pions ne se déplacent pas en diagonale.
Au départ, la case centrale du plateau est vide et il y a toujours une case vide au cours de la partie.
On joue avec les flèches pour sélectionner le pion à déplacer puis on le déplace avec la touche OK (il y a au maximum UN déplacement possible pour chaque pion sélectionné). Un appui sur la touche HOME permet de réinitialiser le plateau et de retrouver la disposition de départ.
Bon jeu et bonne chance !
from kandinsky import * from ion import * from time import * Plateau=[[0,0,2,2,2],[0,0,2,2,2],[1,1,0,2,2],[1,1,1,0,0],[1,1,1,0,0]] clr_fond=(225,170,0) def dessine_pion(colonne,ligne,clr="b"): #draw_string("o",120+20*colonne,30+20*ligne,"wkr"[Plateau[ligne][colonne]]) if clr=="b": clr=(clr_fond,"k","r")[Plateau[ligne][colonne]] dX=92+30*colonne dY=42+30*ligne fill_rect(dX+5,dY,6,1,clr) fill_rect(dX+3,dY+1,10,1,clr) fill_rect(dX+2,dY+2,12,1,clr) fill_rect(dX+1,dY+3,14,2,clr) fill_rect(dX,dY+5,16,6,clr) fill_rect(dX+1,dY+11,14,2,clr) fill_rect(dX+2,dY+13,12,1,clr) fill_rect(dX+3,dY+14,10,1,clr) fill_rect(dX+5,dY+15,6,1,clr) def dessine_contour(colonne,ligne): clr=(240,200,0) dX=92+30*colonne dY=42+30*ligne fill_rect(dX+4,dY-2,8,1,clr) fill_rect(dX+2,dY-1,12,1,clr) fill_rect(dX+1,dY,14,1,clr) fill_rect(dX,dY+1,16,1,clr) fill_rect(dX-1,dY+2,18,2,clr) fill_rect(dX-2,dY+4,20,8,clr) fill_rect(dX-1,dY+12,18,2,clr) fill_rect(dX,dY+14,16,1,clr) fill_rect(dX+1,dY+15,14,1,clr) fill_rect(dX+2,dY+16,12,1,clr) fill_rect(dX+4,dY+17,8,1,clr) def dessine_curseur(k,i,clr): for a in range(2): fill_rect(92-4+30*k,42-4+30*i+23*a,24,1,clr) fill_rect(92-4+30*k+23*a,42-4+30*i,1,24,clr) def dessine_plateau(x,y): # dessin du plateau #fill_rect(80,3,160,160,clr_fond) fill_rect(x+6,y,148,1,clr_fond) fill_rect(x+4,y+1,152,1,clr_fond) fill_rect(x+3,y+2,154,1,clr_fond) fill_rect(x+2,y+3,156,1,clr_fond) fill_rect(x+1,y+4,158,2,clr_fond) fill_rect(x,y+6,160,148,clr_fond) fill_rect(x+1,y+154,158,2,clr_fond) fill_rect(x+2,y+156,156,1,clr_fond) fill_rect(x+3,y+157,154,1,clr_fond) fill_rect(x+4,y+158,152,1,clr_fond) fill_rect(x+6,y+159,148,1,clr_fond) for ligne in range(5): for colonne in range(5): if not ((colonne<2 and ligne<2) or (colonne>2 and ligne>2)): dessine_contour(ligne,colonne) # dessin du contour dessine_pion(ligne,colonne) # dessin des pions draw_string("Jeu du solitaire",80,70,"purple") draw_string("Les huit ennemis",80,95,"purple") draw_string("Valider avec OK",85,135,"purple") for k in range(2): fill_rect(60,50+k*122,200,1,"g") for k in range(20): dessine_pion(-2+(k%10),-1+6*(k//10),"rkrkw"[k%5]) while not (keydown(KEY_OK) or keydown(KEY_EXE)):1 while keydown(KEY_OK) or keydown(KEY_EXE):1 fill_rect(0,0,320,222,"w") draw_string("Présentation",100,10,(80,150,50)) Regles=("Les pions rouges doivent","prendre la place des pions","bruns. Les pions se déplacent","directement ou en passant","par-dessus un autre pion.",""," Mode : ","","","Réinitialiser le jeu : Home") for k in range(len(Regles)): draw_string(Regles[k],20,33+18*k,"b") mode_facile=1 chg=1 draw_string("< >",160,141,"orange") while not (keydown(KEY_OK) or keydown(KEY_EXE)): if chg: draw_string(("Normal","Facile")[mode_facile],180,141,"w") mode_facile=1-mode_facile draw_string(("Normal","Facile")[mode_facile],180,141,"purple") draw_string("Les pions ne peuvent qu'avancer",5,160,"bw"[mode_facile]) sleep(0.2) chg=keydown(KEY_RIGHT)-keydown(KEY_LEFT) while keydown(KEY_OK) or keydown(KEY_EXE):1 fill_rect(0,0,320,222,"w") draw_string("Solitaire - Les huit ennemis",20,6,"b") dessine_plateau(80,30) #draw_string("Jeu du",60,20,"y") #draw_string("solitaire",60,40,"y") Nb_coups=0 T=monotonic() dessine_curseur(2,2,"y") x=2 y=2 chgX=0 chgY=0 while Plateau != [[0,0,1,1,1],[0,0,1,1,1],[2,2,0,1,1],[2,2,2,0,0],[2,2,2,0,0]]: if chgX or chgY: dessine_curseur(x,y,clr_fond) x=(x+chgX)%5 y=(y+chgY)%5 while (x<2 and y<2) or (x>2 and y>2): # hors plateau x=(x+chgX)%5 y=(y+chgY)%5 dessine_curseur(x,y,"y") sleep(0.2) chgX=keydown(KEY_RIGHT)-keydown(KEY_LEFT) chgY=keydown(KEY_DOWN)-keydown(KEY_UP) if keydown(KEY_HOME): Plateau=[[0,0,2,2,2],[0,0,2,2,2],[1,1,0,2,2],[1,1,1,0,0],[1,1,1,0,0]] dessine_plateau(80,30) x,y=2,2 dessine_curseur(x,y,"y") if keydown(KEY_OK) or keydown(KEY_EXE): # haut if ((y>0 and x>1) or y>2) and (Plateau[y][x]==1 or mode_facile): if Plateau[y-1][x]==0: # déplacement direct Plateau[y][x],Plateau[y-1][x]=Plateau[y-1][x],Plateau[y][x] Nb_coups+=1 dessine_pion(x,y) dessine_pion(x,y-1) elif ((y>1 and x>1) or y>3): # déplacement par saut if Plateau[y-2][x]==0: Plateau[y][x],Plateau[y-2][x]=Plateau[y-2][x],Plateau[y][x] Nb_coups+=1 dessine_pion(x,y) dessine_pion(x,y-2) # bas if ((y<4 and x<3) or y<2) and (Plateau[y][x]==2 or mode_facile): if Plateau[y+1][x]==0: # déplacement direct Plateau[y][x],Plateau[y+1][x]=Plateau[y+1][x],Plateau[y][x] Nb_coups+=1 dessine_pion(x,y) dessine_pion(x,y+1) elif ((y<3 and x<3) or y<1): # déplacement par saut if Plateau[y+2][x]==0: Plateau[y][x],Plateau[y+2][x]=Plateau[y+2][x],Plateau[y][x] Nb_coups+=1 dessine_pion(x,y) dessine_pion(x,y+2) # gauche if ((x>0 and y>1) or x>2) and (Plateau[y][x]==2 or mode_facile): if Plateau[y][x-1]==0: # déplacement direct Plateau[y][x],Plateau[y][x-1]=Plateau[y][x-1],Plateau[y][x] Nb_coups+=1 dessine_pion(x,y) dessine_pion(x-1,y) elif ((x>1 and y>1) or x>3): # déplacement par saut if Plateau[y][x-2]==0: Plateau[y][x],Plateau[y][x-2]=Plateau[y][x-2],Plateau[y][x] Nb_coups+=1 dessine_pion(x,y) dessine_pion(x-2,y) # droite if ((x<4 and y<3) or x<2) and (Plateau[y][x]==1 or mode_facile): if Plateau[y][x+1]==0: # déplacement direct Plateau[y][x],Plateau[y][x+1]=Plateau[y][x+1],Plateau[y][x] Nb_coups+=1 dessine_pion(x,y) dessine_pion(x+1,y) elif ((x<3 and y<3) or x<1): # déplacement par saut if Plateau[y][x+2]==0: Plateau[y][x],Plateau[y][x+2]=Plateau[y][x+2],Plateau[y][x] Nb_coups+=1 dessine_pion(x,y) dessine_pion(x+2,y) draw_string("Gagné en "+str(Nb_coups)+" coups et en "+str(int(monotonic()-T))+" sec.",5*(Nb_coups<100 and monotonic()-T<100),196,"b")