Jeu du morpion jouable à 2 joueurs. Appuyez simplement sur les touches de 1 à 9 de la calculatrice pour placer vos symboles. Il est aussi possible de modifier la couleur du tracé, des croix, des ronds, et la taille du morpion :).
from ion import * from kandinsky import * from turtle import * keys=[KEY_ONE,KEY_TWO,KEY_THREE,KEY_FOUR,KEY_FIVE,KEY_SIX,KEY_SEVEN,KEY_EIGHT,KEY_NINE] numberLap=0 def newCircle(x0,y0,r,c1,c2): xd=x0-int((r-1)/sqrt(2)) xf=x0+int((r-1)/sqrt(2)) for x in range(xd,xf+1): x1=x y1=y0+int(sqrt((r-1)**2-(x-x0)**2)) set_pixel(x,y1,c1) for j in range(3): x2=x0+y1-y0 y2=y0+x0-x1 set_pixel(x2,y2,c1) x1,y1=x2,y2 def cross(x, y, w, l, color): draw_line(int(x-l*0.35), int(y-w*0.35), int(x+l*0.35), int(y+w*0.35),color) draw_line(int(x-l*0.35), int(y+w*0.35), int(x+l*0.35), int(y-w*0.35),color) def draw(x, y, w, l, colorLines): draw_line(int(x-l/2), int(y-w-w/2), int(x-l/2), int(y+w+w/2), colorLines) draw_line(int(x+l/2), int(y-w-w/2), int(x+l/2), int(y+w+w/2), colorLines) draw_line(int(x+l+l/2), int(y+w/2), int(x-l-l/2), int(y+w/2), colorLines) draw_line(int(x+l+l/2), int(y-w/2), int(x-l-l/2), int(y-w/2), colorLines) def morpion(x, y, w, l, colorLines='black', colorCross='black', colorRound='black'): draw(x, y, w, l, colorLines) numberLap=0 hideturtle() placement=[] xModif=[x-l, x, x+l, x-l, x, x+l, x-l, x, x+l] yModif=[y+w, y+w, y+w, y, y, y, y-w, y-w, y-w] while True: for i in keys: if keydown(i): while keydown(i): pass placement.append(keys.index(i)+1) numberLap+=1 draw(x, y, w, l, colorLines) for i in placement: xLap=xModif[i-1] yLap=yModif[i-1] if placement.index(i) % 2 == 0: cross(xLap, yLap, w, l, colorCross) else: newCircle(xLap,yLap,l*0.4, colorRound, colorRound) sizeW=sizeL=60 morpion(160, 111, sizeW, sizeL, 'pink', 'blue', 'red')