jeu_de_dames.py

Created by lorem-ipsum-42

Created on June 20, 2022

4.03 KB


from time import sleep
from ion import *
from kandinsky import *

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

color_pions = ((148, 113, 222), (192, 53, 53), (255, 183, 52), (242, 242, 242))

plateau = int("2" * 20 + "3" * 10 + "1" * 20)

fill_rect(0, 200, 320, 22, (148, 113, 222))

lettres = (32032318, 33095217, 18732593, 33061407, 33061951)


def affiche_lettres(x_start, y_start, l=lettres):
    temp_y = y_start
    for lettre in lettres:
        pos = 0
        for pixel in str(bin(lettre))[2:]:
            if pos == 20:
                pos = 0
                y_start += 4

            if pixel == '1':
                fill_rect(x_start + pos, y_start, 4, 4, (128, 206, 225))

            pos += 4
        x_start += 25
        y_start = temp_y


draw_string("Gameplay by nsi.xyz/dames", 33, 202, (255, 255, 255), color_pions[0])
affiche_lettres(202, 0)


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
    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 rempli_pion(coord_pion, couleur):
    fill_rect(decalage(coord_pion[1]) * 20 + coord_pion[0] * 40, coord_pion[1] * 20, 20, 20, couleur)


def init_pions():
    color_temp_pion = (0, 0, 0)
    for j in range(10):
        for i in range(5):
            if pion(i, j) == 3:
                color_temp_pion = color_pions[3]
            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
            rempli_pion((i, j), color_temp_pion)


def bouge_pion(coord_pion, new_coord):
    rempli_pion(coord_pion, color_pions[3])
    rempli_pion(new_coord, color_pions[0])


def allume_pion(coord_pion):
    rempli_pion(coord_pion, color_pions[2])


def eteint_pion(coord_pion):
    rempli_pion(coord_pion, 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 est_deplacable(coord_pion: tuple):
    print(coord_pion)
    pass
    """couleur_pion = int(plateau[coord_pion[0]][coord_pion[1]])
    if couleur_pion == 1:
        return plateau[coord_pion[0]+1][coord_pion[1]-1] == '0' and plateau[coord_pion[0]+1][coord_pion[1]+1] == '0'
    elif couleur_pion == 2:
        return plateau[coord_pion[0]-1][coord_pion[1]-1] == '0' and plateau[coord_pion[0]-1][coord_pion[1]+1] == '0'"""


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 move_possible_pion_blanc(coord_pion):
    print(coord_pion)
    pass


def choix_deplacement_pion(coord_pion):
    # noinspection PyTypeChecker
    choix(move_possible_pion_blanc(coord_pion))
    return True


init_pions()
print(choix_pion())