jeu_de_dames.py

Created by cent20

Created on June 20, 2022

3.58 KB

Dev en cours 20%


#created by Gabin P.
from kandinsky import *
from time import sleep
from ion import *
 

try:
    get_keys()
    color_pions = ((192, 53, 53), (255, 183, 52))
except:
    color_pions = ((255, 183, 52), (192, 53, 53))

fill_rect(0,203,320,19,color_pions[0])
   
draw_string ("Gameplay by nsi.xyz/dames",33,203,(255,255,255),color_pions[0])

fill_rect(215,1,100,39,(142,142,142))

draw_string ("IA Lvl",215,2+(19+1)*3,(42,42,42))   
fill_rect(285,2+(19+1)*3,30,19,color_pions[1])

draw_string ("Score",240,2+(19+1)*5,(42,42,42))   
fill_rect(225,2+(19+1)*6,30,19,color_pions[0])
fill_rect(275,2+(19+1)*6,30,19,color_pions[1])

draw_string ("IA playing",215,2+(19+1)*8,(42,42,42))   

plateau = 22222222222222222222000000000011111111111111111111

def pion(i, j, plat=plateau):
    position = i + j * 5
    return int(str(plat)[position])

def create_plateau():  # Crée un plateau en graphique 10x10 avec comme point de départ le point de coordonnées (10, 20) et avec chaque carré de taille 20x20
    return None
    for j in range(10, 211, 20):
        for x in range(20, 221, 1):
            set_pixel(x, j, (0, 0, 0))
        for i in range(20, 221, 20):
            for y in range(10, 211, 1):
                set_pixel(i, y, (0, 0, 0))

def decalage(ord_pion):
    return int(not ord_pion%2)


def init_pions():
    decal = 0
    for j in range(10):
        for i in range(5):
            if pion(i, j) != 0:
                decal = decalage(j)
                if pion(i, j) == 2:
                    color_temp_pion = color_pions[1]
                if pion(i, j) == 1:
                    color_temp_pion = color_pions[0]
                else:  # si c'est une dame
                    pass
                fill_rect(decal*20 + i * 40 + 5, j * 20 + 2, 19, 19, color_temp_pion)


def bouge_pion(coord_pion, new_coord):
    fill_rect(decalage(coord_pion[1])*20 + coord_pion[0] * 40 + 21, coord_pion[1] * 20 + 11, 19, 19, (255, 255, 255))
    fill_rect(decalage(new_coord[1])*20 + new_coord[0] * 40 + 21, new_coord[1] * 20 + 11, 19, 19, color_pions[0])


def allume_pion(coord_pion):
    fill_rect(decalage(coord_pion[1])*20 + coord_pion[0] * 40 + 21, coord_pion[1] * 20 + 11, 19, 19, (0, 0, 0))


def eteint_pion(coord_pion):
    fill_rect(decalage(coord_pion[1])*20 + coord_pion[0] * 40 + 21, coord_pion[1] * 20 + 11, 19, 19, color_pions[0])


def choix(liste_choix):
    id_choix = 0
    while not keydown(4):  # tant que ok n'est pas appuyé
        allume_pion(liste_choix[id_choix])
        if keydown(0):  # touche gauche
            sleep(0.25)
            eteint_pion(liste_choix[id_choix])
            if id_choix == 0:
                id_choix = len(liste_choix) - 1
            else:
                id_choix -= 1
        elif keydown(3):  # touche droite
            sleep(0.25)
            eteint_pion(liste_choix[id_choix])
            if id_choix == len(liste_choix) - 1:
                id_choix = 0
            else:
                id_choix += 1
    return liste_choix[id_choix]


def choix_pion():
    temp_pions_joueur = []
    for j in range(10):
        for i in range(5):
            if pion(i, j) == 1:
                temp_pions_joueur += [(i, j)]
    temp_pion = choix(temp_pions_joueur)         
    while not est_deplacable(temp_pion):
        init_pions() #refresh le plateau
        temp_pion = choix(temp_pions_joueur)
    return temp_pion


def choix_deplacement_pion(coord_pion):
    liste_move = move_possible_pion_blanc(coord_pion)  # liste_move est une liste de tuples ou chaque tuple est les coord d'un point possible où aller
    choix(liste_move)


create_plateau()
init_pions()
print(choix_pion())