test_dames_map.py

Created by lorem-ipsum-42

Created on May 23, 2022

2.77 KB


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)]
    
plateau = ['0202020202',
           '2020202020',
           '0202020202',
           '2020202020',
           '0000000000',
           '0000000000',
           '0101010101',
           '1010101010',
           '0101010101',
           '1010101010']


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 dessin_pion(coord_pion, color):
      fill_rect(coord_pion[1] * 20 + 21, coord_pion[0] * 20 + 11, 19, 19, color)
  
  
def init_pions():
    for i in range(len(plateau)):
        for j in range(len(plateau[0])):
            if plateau[j][i] != '0':
                if plateau[j][i] == '2':
                    color_temp_pion = color_pions[1]
                elif plateau[j][i] == '1':
                    color_temp_pion = color_pions[0]
                else:  # si c'est une dame
                    pass
                dessin_pion((j, i), color_temp_pion)


def bouge_pion(coord_pion, new_coord):
    dessin_pion(coord_pion, (255, 255, 255))
    dessin_pion(new_coord, color_pions[0])


def allume_pion(coord_pion):
    dessin_pion(coord_pion, (0, 0, 0))


def eteint_pion(coord_pion):
    dessin_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 choix_pion():
    temp_pions_joueur = []
    for i in range(10):
        for j in range(10):
            if plateau[i][j] == "1":
                temp_pions_joueur += [(i, j)]
    choix(temp_pions_joueur)


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())

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.