puissance44.py

Created by antarctus

Created on September 24, 2023

7.48 KB


'''
Cree par Gengisclan le 08/09/2023
'''


# Modules
from kandinsky import *
from random import randint
from time import sleep
from ion import *

KEY_OK=KEY_EXE
def Ch_page():
  global suiv
  suiv=False
  sleep(.1)  

def Dessin_boutons(bouton,coul=(0,)*3):
  fill_rect(bouton[3],bouton[4],bouton[1],bouton[2],(255,)*3)
  fill_rect(bouton[3]+1,bouton[4]+1,bouton[1]-2,bouton[2]-2,coul)
  draw_string(bouton[0],bouton[3]+10,bouton[4]+10,(255,)*3,coul)

def Dessin_plateau():
  for i in range(8):
    fill_rect(40+(33*i),10,3,201,(255,)*3)
  for j in range(7):
    fill_rect(40,10+(33*j),234,3,(255,)*3)

def Deplac_curs(pos_curs):
  fill_rect(40,0,240,10,(0,)*3)
  fill_rect(40+(33*pos_curs),0,36,10,(255,255,0))

def Pose_pion(pos_curs):
  global case
  for i in range(5,-1,-1):
    if get_pixel(43+(33*pos_curs),14+(33*i))==(0,)*3:
      case=i
      break
  if get_pixel(43+(33*pos_curs),14)==(0,)*3:
    return [pos_curs,case]  
  else:
    return [-1,-1]  

def Victoire(Pose,compteur=0,couleur=(0,0,0)):
    couleur=get_pixel(43+(33*Pose[0]),13+(33*Pose[1]))

    for i in range(4):
      if get_pixel(43+(33*(Pose[0]+i)),13+(33*Pose[1]))==couleur:compteur+=1
      else:break
      if compteur==4:return True
    compteur-=1
  
    for j in range(4):
      if get_pixel(43+(33*(Pose[0]-j)),13+(33*Pose[1]))==couleur:compteur+=1
      else:break
      if compteur==4:return True
    compteur=0
    
    for k in range(4):
      if get_pixel(43+(33*Pose[0]),13+(33*(Pose[1]+k)))==couleur:compteur+=1
      else:break
      if compteur==4:return True
    compteur-=1

    for l in range(4):
      if get_pixel(43+(33*Pose[0]),13+(33*(Pose[1]-l)))==couleur:compteur+=1
      else:break
      if compteur==4:return True
    compteur=0

    for o in range(4):
      if get_pixel(43+(33*(Pose[0]+o)),13+(33*(Pose[1]+o)))==couleur:compteur+=1
      else:break
      if compteur==4:return True
    compteur-=1

    for m in range(4):
      if get_pixel(43+(33*(Pose[0]-m)),13+(33*(Pose[1]-m)))==couleur:compteur+=1
      else:break
      if compteur==4:return True
    compteur=0

    for p in range(4):
      if get_pixel(43+(33*(Pose[0]-p)),13+(33*(Pose[1]+p)))==couleur:compteur+=1
      else:break
      if compteur==4:return True
    compteur-=1

    for n in range(4):
      if get_pixel(43+(33*(Pose[0]+n)),13+(33*(Pose[1]-n)))==couleur:compteur+=1
      else:break
      if compteur==4:return True
    compteur=0

def Egalitee(compteur=0):
  for i in range(7):
    if get_pixel(43+(33*i),13)!=(0,)*3:
      compteur+=1
  if compteur==7:return True           


def Logo():
  fill_rect(0,0,320,240,(0,)*3)
  fill_rect(100,80,120,60,(255,)*3)
  fill_rect(101,81,118,58,(0,)*3)
  draw_string("Cree par",120,90,(255,)*3,(0,)*3)
  draw_string("Gengisclan",110,110,(255,)*3,(0,)*3)
  sleep(2)

def Page1():
  Dessin_boutons(Boutons[0])
  Dessin_boutons(Boutons[1])

def Page2():
  Dessin_plateau() 
  fill_rect(30,0,3,55,(255,)*3)   
  fill_rect(0,55,33,3,(255,)*3)   

def Afichage_Vic(win=(0,0,0)):
  win=get_pixel(43+(33*Pose[0]),13+(33*Pose[1]))          
  draw_string("V",290,10,win,(0,)*3)
  draw_string("I",290,30,win,(0,)*3)
  draw_string("C",290,50,win,(0,)*3)
  draw_string("T",290,70,win,(0,)*3)
  draw_string("O",290,90,win,(0,)*3)
  draw_string("I",290,110,win,(0,)*3)
  draw_string("R",290,130,win,(0,)*3)
  draw_string("E",290,150,win,(0,)*3)

def Afichage_Ega(win=(255,0,255)):
  draw_string("E",290,10,win,(0,)*3)
  draw_string("G",290,30,win,(0,)*3)
  draw_string("A",290,50,win,(0,)*3)
  draw_string("L",290,70,win,(0,)*3)
  draw_string("I",290,90,win,(0,)*3)
  draw_string("T",290,110,win,(0,)*3)
  draw_string("E",290,130,win,(0,)*3)
  draw_string("E",290,150,win,(0,)*3)

Boutons=[
# [Texte,Longueur,Largeur,x,y]
["Solo",60,40,130,60],
["Multi",70,40,125,140],
]

page=1
suiv=False
n_souris=0
run=True
mode=""
pos_curs=0
case=0
Pose=[]
tour=1
Vic_R=False



Logo()
fill_rect(0,0,320,240,(0,)*3)
while run:
  Ch_page()
  if page==1:
    fill_rect(0,0,320,240,(0,)*3)
    Page1()
    sleep(.1)
    n_souris=0
    Dessin_boutons(Boutons[n_souris],(112,114,110))
    while not suiv:
      sleep(.1)
      # Mouvements de sourie
      if keydown(KEY_DOWN):
        n_souris=1
        Page1()
        Dessin_boutons(Boutons[n_souris],(112,114,110))
      if keydown(KEY_UP):
        n_souris=0
        Page1()
        Dessin_boutons(Boutons[n_souris],(112,114,110))
      if keydown(KEY_OK):
        if n_souris==0:mode="Solo"
        if n_souris==1:mode="Multi"
        page=2
        suiv=True  
  
  if page==2:      
    draw_string(str(tour),5,5,(255,)*3,(0,)*3)
    fill_rect(0,0,320,240,(0,)*3)
    sleep(.1)
    Page2()  
    
    draw_string(str(tour),5,5,(255,)*3,(0,)*3)
    draw_string("R",5,35,(255,0,0),(0,)*3)

    if mode=="Solo":
      fill_rect(30,55,3,90,(255,)*3)
      fill_rect(0,145,33,3,(255,)*3)
      draw_string("S",5,65,(110,25,225),(0,)*3)  
      draw_string("O",5,85,(110,25,225),(0,)*3)  
      draw_string("L",5,105,(110,25,225),(0,)*3)  
      draw_string("O",5,125,(110,25,225),(0,)*3)

    if mode=="Multi":
      fill_rect(30,55,3,110,(255,)*3)
      fill_rect(0,165,33,3,(255,)*3)
      draw_string("M",5,65,(110,25,225),(0,)*3)  
      draw_string("U",5,85,(110,25,225),(0,)*3)  
      draw_string("L",5,105,(110,25,225),(0,)*3)  
      draw_string("T",5,125,(110,25,225),(0,)*3)
      draw_string("I",5,145,(110,25,225),(0,)*3)
    
    while not suiv:
      sleep(.1)
      if keydown(KEY_LEFT) and pos_curs!=0:
        pos_curs-=1
        while keydown(KEY_LEFT):pass
      if keydown(KEY_RIGHT) and pos_curs!=6:
        pos_curs+=1
        while keydown(KEY_RIGHT):pass

      if mode=="Multi":
        if keydown(KEY_OK):
          Pose=Pose_pion(pos_curs)
          if Pose!=[-1,-1]:
            if tour%2==0:
                fill_rect(43+(33*Pose[0]),13+(33*Pose[1]),30,30,(0,0,255))
                draw_string("R",5,35,(255,0,0),(0,)*3)
            if tour%2==1:
              fill_rect(43+(33*Pose[0]),13+(33*Pose[1]),30,30,(255,0,0))
              draw_string("B",5,35,(0,0,255),(0,)*3)
       
            if Victoire(Pose)==True:
              Afichage_Vic()
              suiv=True
              run=False
      
            if Egalitee()==True:
                Afichage_Ega()
                suiv=True
                run=False
      
            tour+=1
            draw_string(str(tour),5,5,(255,)*3,(0,)*3)
       
          while keydown(KEY_OK):pass
      
      if mode=="Solo":
        if keydown(KEY_OK):
          Pose=Pose_pion(pos_curs)
          if Pose!=[-1,-1]:
            if tour%2==1:
              fill_rect(43+(33*Pose[0]),13+(33*Pose[1]),30,30,(255,0,0))
              draw_string("B",5,35,(0,0,255),(0,)*3)
              
              if Victoire(Pose)==True:
                Afichage_Vic()
                Vic_R=True
                suiv=True
                run=False

              if Egalitee()==True:
                Afichage_Ega()
                suiv=True
                run=False

              if Vic_R==False:
                sleep(.3)
                Pose=Pose_pion(randint(0,6))
                while Pose==[-1,-1]:
                  Pose=Pose_pion(randint(0,6))
                fill_rect(43+(33*Pose[0]),13+(33*Pose[1]),30,30,(0,0,255))
                draw_string("R",5,35,(255,0,0),(0,)*3)
              
                if Victoire(Pose)==True:
                  Afichage_Vic()
                  suiv=True
                  run=False
                
                if Egalitee()==True:
                  Afichage_Ega()
                  suiv=True
                  run=False

      Dessin_plateau()
      Deplac_curs(pos_curs)

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.