morpion.py

Created by marius-layan

Created on February 05, 2024

3.54 KB

Voici une reconstitution du jeu nommé le Morpion, le but est simple: 2 joueur s’affronte (joueur bleu et joueur rouge), une grille de 9 cases est a leur disposition, il peuvent chacun leur tour désirer d’occuper une case et le premier à aligner 3 case occupées à gagné.

les cases peuvent être occupées grâce aux touches allant de 1 à 9.

BON JEU !


from random import *
from kandinsky import *
from ion import *
from time import *
def swap():
  global player
  if player==1:
    player=2
    for i in range(30): fill_rect(xy[0]+i,xy[1]+i,5,5,'red')
    for i in range(30): fill_rect(xy[0]+29-i,xy[1]+i,5,5,'red')
  else:player=1;fill_rect(xy[0],xy[1],34,34,'blue');fill_rect(xy[0]+4,xy[1]+4,26,26,'black')
while True:
  tab0,tab1,tab2,player=[0,0,0],[0,0,0],[0,0,0],randint(1,2);fill_rect(0,0,320,222,'black')
  for i in range(1,3):fill_rect(i*50+83,36,4,150,'white')
  for i in range(1,3):fill_rect(85,i*50+34,150,4,'white')
  while True:
    if player==1:draw_string("Player  Rouge",95,5,'red','black')
    else:draw_string("Player   Blue",95,5,'blue','black')
    if keydown(KEY_ONE) and tab2[0]==0:
      xy,tab2[0]=[93,144],player;swap()
      while keydown(KEY_ONE):continue
    if keydown(KEY_TWO) and tab2[1]==0:
      xy,tab2[1]=[143,144],player;swap()
      while keydown(KEY_TWO):continue
    if keydown(KEY_THREE) and tab2[2]==0:
      xy,tab2[2]=[193,144],player;swap()
      while keydown(KEY_THREE):continue
    if keydown(KEY_FOUR) and tab1[0]==0:
      xy,tab1[0]=[93,94],player;swap()
      while keydown(KEY_FOUR):continue
    if keydown(KEY_FIVE) and tab1[1]==0:
      xy,tab1[1]=[143,94],player;swap()
      while keydown(KEY_FIVE):continue
    if keydown(KEY_SIX) and tab1[2]==0:
      xy,tab1[2]=[193,94],player;swap()
      while keydown(KEY_SIX):continue
    if keydown(KEY_SEVEN) and tab0[0]==0:
      xy,tab0[0]=[93,44],player;swap()
      while keydown(KEY_SEVEN):continue
    if keydown(KEY_EIGHT) and tab0[1]==0:
      xy,tab0[1]=[143,44],player;swap()
      while keydown(KEY_EIGHT):continue
    if keydown(KEY_NINE) and tab0[2]==0:
      xy,tab0[2]=[193,44],player;swap()
      while keydown(KEY_NINE):continue
    if (tab0[0]==1 and tab0[1]==1 and tab0[2]==1) or (tab1[0]==1 and tab1[1]==1 and tab1[2]==1) or (tab2[0]==1 and tab2[1]==1 and tab2[2]==1) or (tab0[0]==1 and tab1[0]==1 and tab2[0]==1) or (tab0[1]==1 and tab1[1]==1 and tab2[1]==1) or (tab0[2]==1 and tab1[2]==1 and tab2[2]==1) or (tab0[0]==1 and tab1[1]==1 and tab2[2]==1) or (tab0[2]==1 and tab1[1]==1 and tab2[0]==1):win=1;break
    if sum(tab0)==6 or sum(tab1)==6 or sum(tab2)==6 or (tab0[0]==2 and tab1[0]==2 and tab2[0]==2) or (tab0[1]==2 and tab1[1]==2 and tab2[1]==2) or (tab0[2]==2 and tab1[2]==2 and tab2[2]==2) or (tab0[0]==2 and tab1[1]==2 and tab2[2]==2) or (tab0[2]==2 and tab1[1]==2 and tab2[0]==2):win=2;break
    if tab0[0]!=0 and tab0[1]!=0 and tab0[2]!=0 and tab1[0]!=0 and tab1[1]!=0 and tab1[2]!=0 and tab2[0]!=0 and tab2[1]!=0 and tab2[2]!=0:win=0;break
  sleep(0.7)
  a,b=0,0;fill_rect(0,0,320,222,'black');draw_string("REJOUER",125,100,'yellow','black');draw_string(" oui ",135,150,'black','green');draw_string(" non ",135,180,'white','black')
  while keydown(KEY_OK)==False:
    if b==0:c=0
    if b==254:c=1
    if c==0:b+=2
    else:b-=2
    if win==1:draw_string("Winner :    Red",86,10,(255,b,b),'black')
    elif win==2:draw_string("Winner :   Blue",86,10,(b,b,255),'black')
    else:draw_string("Egalite",125,10,(b,b,b),'black')
    if keydown(KEY_UP) and a==1:draw_string(" oui ",135,150,'black','green');draw_string(" non ",135,180,'white','black');a=0
    if keydown(KEY_DOWN) and a==0:draw_string(" oui ",135,150,'white','black');draw_string(" non ",135,180,'black','green');a=1
  while keydown(KEY_OK):
    if a==0:draw_string(" oui ",135,150,'gray',(50,130,0));draw_string(" non ",135,180,'white','black')
    if a==1:draw_string(" oui ",135,150,'white','black');draw_string(" non ",135,180,'gray',(50,130,0))
  if a==1:break

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

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.