class Dessin: def __init__(self): self.haut = 10 self.larg = 3 self.vue = Vue(self.haut, self.larg, max_dim=6) self.m = ['R'] * self.haut + ['G'] * self.haut + ['B'] * self.haut shuffle(self.m) self.matrice = [[self.m[self.larg * j + i] for i in range(self.larg)] for j in range(self.haut)] self.afficher_matrices() def afficher_matrices(self): dico_chemins = { 'R': './pions/pion_rouge.png', 'G': './pions/pion_vert.png', 'B': './pions/pion_bleu.png' } for y in range(self.haut): for x in range(self.larg): self.vue.modifier_grille('image', y, x, cf=dico_chemins[self.matrice[y][x]], visible=True) def echanger_couleurs(self, col, lig_a, lig_b): assert col in range(self.larg) and lig_a in range( self.haut) and lig_b in range(self.haut) self.matrice[lig_a][col], self.matrice[lig_b][col] = self.matrice[ lig_b][col], self.matrice[lig_a][col] self.afficher_matrices()
class Dessin: def __init__(self): self.n = 17 self.plateau = [choice(('R', 'B')) for i in range(self.n)] self.vue = Vue(1, self.n) self.redessiner_plateau() def echanger(self, i, j): self.plateau[i], self.plateau[j] = self.plateau[j], self.plateau[i] self.redessiner_plateau() def redessiner_plateau(self): dico = {'R': './pions/pion_rouge.png', 'B': './pions/pion_blanc.png'} lig = 0 for col in range(self.n): self.vue.modifier_grille('fond', lig, col, c=(220, 220, 220), visible=True) self.vue.modifier_grille('image', lig, col, cf=dico[self.plateau[col]], visible=True)
class Dessin: def __init__(self): self.dim = 23 self.vue = Vue(self.dim, self.dim, max_dim=5) self.matrice = self.fournir_matrice() self.afficher_matrice() def fournir_matrice(self): ligne = list('ENGAGELEJEUQUEJELEGAGNE') matrice = [0] * self.dim for i in range(self.dim // 2): space = [''] * (self.dim // 2 - i) ligne_en_cours = space + ligne[:i + 1] + (ligne[-i:] if i != 0 else []) + space matrice[i] = ligne_en_cours.copy() matrice[-1 - i] = ligne_en_cours.copy() matrice[self.dim // 2] = ligne return matrice def afficher_matrice(self): for y in range(self.dim): for x in range(self.dim): self.vue.modifier_grille('texte', y, x, t=self.matrice[y][x], tp=13, visible=True)
def __init__(self): self.haut = 10 self.larg = 13 self.vue = Vue(self.haut, self.larg, max_dim=6) self.matrice_fraises = self.matrice_depart() self.matrice_chemin = [[False for j in range(self.larg)] for i in range(self.haut)] self.afficher_matrices()
def __init__(self, nb_crepes=7): #la matrice stocke aussi les couleurs d'affichage self.haut = nb_crepes self.larg = 2 * self.haut + 2 self.vue = Vue(self.haut, self.larg, max_dim=6) self.matrice = self.generer_matrice() self.afficher_matrice()
def __init__(self): self.haut = 9 self.larg = 9 self.vue = Vue(self.haut, self.larg, max_dim=5) self.c_1 = (200, 230, 250) self.c_2 = (200, 250, 230) self.c_3 = (250, 250, 250) self.matrice = self.fournir_matrice_croix() self.afficher_matrice()
def __init__(self): self.haut = 8 self.larg = 8 self.vue = Vue(self.haut, self.larg, max_dim=5) self.xcoq = 7 self.ycoq = 0 self.xf = 0 self.yf = 7 self.fond = self.generer_matrice() self.redessiner_matrice()
def __init__(self): self.haut = 10 self.larg = 3 self.vue = Vue(self.haut, self.larg, max_dim=6) self.m = ['R'] * self.haut + ['G'] * self.haut + ['B'] * self.haut shuffle(self.m) self.matrice = [[self.m[self.larg * j + i] for i in range(self.larg)] for j in range(self.haut)] self.afficher_matrices()
def __init__(self, dim=10): self.dim = dim self.vue = Vue(self.dim, self.dim, max_dim=5) self.vue.lier_evenement('selection_objet', self.gestionnaire_selection, True) self.matrice = self.generer_matrice() self.visibles = [[False for col in range(self.dim)] for lig in range(self.dim)] self.redessiner_matrice() self.message_nombre_a_trouver()
def __init__(self): self.haut = 4 self.larg = 4 self.vue = Vue(self.haut, self.larg * 3 + 4, max_dim=5) self.m_depart = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]] self.m_arrivee = [[12, 10, 11, 9], [16, 14, 5, 13], [8, 6, 7, 15], [4, 2, 3, 1]] self.m = deepcopy(self.m_depart) self.afficher_matrices()
class Dessin: def __init__(self, dim=10): self.dim = dim self.vue = Vue(self.dim, self.dim, max_dim=5) self.vue.lier_evenement('selection_objet', self.gestionnaire_selection, True) self.matrice = self.generer_matrice() self.visibles = [[False for col in range(self.dim)] for lig in range(self.dim)] self.redessiner_matrice() self.message_nombre_a_trouver() def generer_matrice(self): m = [[0 for x in range(self.dim)] for y in range(self.dim)] m[0][0] = randint(1, 99) for idx in range(1, self.dim): m[idx][0] = m[idx - 1][0] + randint(1, 46) m[0][idx] = m[0][idx - 1] + randint(1, 46) for lig in range(1, self.dim): for col in range(1, self.dim): m[lig][col] = max(m[lig - 1][col], m[lig][col - 1]) + randint( 1, 46) return m def redessiner_matrice(self): for lig in range(self.dim): for col in range(self.dim): vis = self.visibles[lig][col] self.vue.modifier_grille('texte', lig, col, t=self.matrice[lig][col], tp=15, visible=vis) self.vue.modifier_grille('fond', lig, col, ce=(0, 140, 140), ci=(150, 240, 240), visible=True) def message_nombre_a_trouver(self): lig, col = randint(1, self.dim - 1), randint(1, self.dim - 1) nat = self.matrice[lig][col] nat = nat + randint(0, 1) self.vue.mzt(t='En cliquant sur les cases, déterminez si le nombre ' + str(nat) + ' est présent parmi les cartes.', tp=10, ct=(255, 0, 0)) def gestionnaire_selection(self, event): lig = event['lig'] col = event['col'] self.visibles[lig][col] = True self.redessiner_matrice()
class Dessin: def __init__(self, nb_crepes=7): #la matrice stocke aussi les couleurs d'affichage self.haut = nb_crepes self.larg = 2 * self.haut + 2 self.vue = Vue(self.haut, self.larg, max_dim=6) self.matrice = self.generer_matrice() self.afficher_matrice() def generer_ligne(self, larg): #larg varie de 1 à self.haut (pas de 2 à self.larg) ligne = [(255, 255, 255)] * self.larg curseur = int((255 * (larg - 1)) / (self.haut - 1)) for i in range(larg): ligne[self.larg // 2 + i] = (255 - curseur, curseur, 255) ligne[self.larg // 2 - i - 1] = (255 - curseur, curseur, 255) return ligne def generer_matrice(self): matrice = [] largeurs = list(range(1, self.haut + 1)) shuffle(largeurs) for larg in largeurs: matrice.append(self.generer_ligne(larg)) return matrice def afficher_matrice(self): for y in range(self.haut): for x in range(self.larg): self.vue.modifier_grille('fond', y, x, c=self.matrice[y][x], visible=True) def retourner_x_crepes(self, x): for i in range((x) // 2): self.matrice[x - i - 1], self.matrice[i] = self.matrice[i], self.matrice[ x - i - 1] self.afficher_matrice()
class Dessin: def __init__(self): self.haut = 9 self.larg = 9 self.vue = Vue(self.haut, self.larg, max_dim=5) self.c_1 = (200, 230, 250) self.c_2 = (200, 250, 230) self.c_3 = (250, 250, 250) self.matrice = self.fournir_matrice_croix() self.afficher_matrice() def fournir_matrice_croix(self): ligne_a = [0, 0, 0, 1, 1, 1, 0, 0, 0] ligne_b = [1 for i in range(9)] matrice = [ ligne_a.copy() if i not in (3, 4, 5) else ligne_b.copy() for i in range(9) ] return matrice def afficher_matrice(self): for y in range(self.haut): for x in range(self.larg): if self.matrice[y][x] == 1: self.vue.modifier_grille('fond', y, x, c=self.c_1 if (y + x) % 2 == 0 else self.c_2, visible=True) else: self.vue.modifier_grille('fond', y, x, c=self.c_3, visible=True)
class Dessin: def __init__(self): self.haut, self.larg = 4, 5 self.vue = Vue(self.haut, self.larg, max_dim=5) self.nouveau() def generer_matrices(self): fonds = [[True for x in range(self.larg)] for y in range(self.haut)] aretes_v = [[True for x in range(self.larg + 1)] for y in range(self.haut)] aretes_h = [[True for x in range(self.larg)] for y in range(self.haut + 1)] trous = [(x, randint(1, self.haut - 1)) for x in range(1, self.larg, 3)] for (x, y) in trous: for dy in (0, 1): for dx in (0, 1): fonds[y - dy][x - dx] = False for dy in (0, 1): aretes_v[y - dy][x] = False for dx in (0, 1): aretes_h[y][x - dx] = False return fonds, aretes_v, aretes_h def redessiner_matrices(self, f, av, ah): for y in range(self.haut): for x in range(self.larg): self.vue.modifier_grille('fond', y, x, c=(180, 255, 180) if f[y][x] else (255, 180, 180), visible=True) for y in range(self.haut): for x in range(self.larg + 1): self.vue.modifier_grille('mur_v', y, x, ci=(255, 255, 180), visible=True if av[y][x] else False) for y in range(self.haut + 1): for x in range(self.larg): self.vue.modifier_grille('mur_h', y, x, ci=(255, 255, 180), visible=True if ah[y][x] else False) def nouveau(self): f, av, ah = self.generer_matrices() self.redessiner_matrices(f, av, ah)
class Dessin: def __init__(self): self.haut = 4 self.larg = 4 self.vue = Vue(self.haut, self.larg * 3 + 4, max_dim=5) self.m_depart = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]] self.m_arrivee = [[12, 10, 11, 9], [16, 14, 5, 13], [8, 6, 7, 15], [4, 2, 3, 1]] self.m = deepcopy(self.m_depart) self.afficher_matrices() def afficher_matrices(self): for y in range(self.haut): for x in range(self.larg): self.vue.modifier_grille('texte', y, x, t=self.m_depart[y][x], tp=13, visible=True) self.vue.modifier_grille('texte', y, x + 6, t=self.m[y][x], tp=13, visible=True, c=(0, 0, 255)), self.vue.modifier_grille('texte', y, x + 12, t=self.m_arrivee[y][x], tp=13, visible=True) def echanger_lignes(self, i, j): self.m[i], self.m[j] = self.m[j], self.m[i] self.afficher_matrices() def echanger_colonnes(self, i, j): for lig in range(self.haut): self.m[lig][j], self.m[lig][i] = self.m[lig][i], self.m[lig][j] self.afficher_matrices()
class Dessin: def __init__(self): self.haut = 8 self.larg = 8 self.vue = Vue(self.haut, self.larg, max_dim=5) self.xcoq = 7 self.ycoq = 0 self.xf = 0 self.yf = 7 self.fond = self.generer_matrice() self.redessiner_matrice() def generer_matrice(self): fond = [['B' if (x + y) % 2 == 0 else 'N' for x in range(self.larg)] for y in range(self.haut)] return fond def redessiner_matrice(self): dico = {'N': (225, 225, 225), 'B': (245, 245, 245)} for lig in range(self.haut): for col in range(self.larg): self.vue.modifier_grille('fond', lig, col, c=dico[self.fond[lig][col]], visible=True) if lig == self.ycoq and col == self.xcoq: self.vue.modifier_grille('image', lig, col, cf='./persos/coq.png', visible=True) if lig == self.yf and col == self.xf: self.vue.modifier_grille('image', lig, col, cf='./persos/Fermiere.png', visible=True)
def __init__(self): self.haut = 8 self.larg = 8 self.vue = Vue(self.haut, self.larg, max_dim = 5) self.plateau = Plateau(self)
def __init__(self): self.dim = 23 self.vue = Vue(self.dim, self.dim, max_dim=5) self.matrice = self.fournir_matrice() self.afficher_matrice()
def __init__(self): self.haut, self.larg = 4, 5 self.vue = Vue(self.haut, self.larg, max_dim=5) self.nouveau()
def __init__(self): self.n = 17 self.plateau = [choice(('R', 'B')) for i in range(self.n)] self.vue = Vue(1, self.n) self.redessiner_plateau()
class Dessin: def __init__(self): self.haut = 10 self.larg = 13 self.vue = Vue(self.haut, self.larg, max_dim=6) self.matrice_fraises = self.matrice_depart() self.matrice_chemin = [[False for j in range(self.larg)] for i in range(self.haut)] self.afficher_matrices() def matrice_depart(self): nb_cells = self.haut * self.larg nb_fraises = randint(max(nb_cells / 5, 1), min(2 * nb_cells / 5, nb_cells)) matrice_en_long = [True] * nb_fraises + [False ] * (nb_cells - nb_fraises) shuffle(matrice_en_long) matrice = [[ matrice_en_long[self.larg * j + i] for i in range(self.larg) ] for j in range(self.haut)] matrice[0][0] = False matrice[self.haut - 1][self.larg - 1] = False return matrice def afficher_matrices(self): chemin_img = './nourriture/fraise.png' for y in range(self.haut): for x in range(self.larg): self.vue.modifier_grille( 'fond', y, x, ci=(230, 250, 230) if self.matrice_chemin[y][x] else (255, 255, 255), ce=(0, 128, 0), visible=True) if self.matrice_fraises[y][x]: self.vue.modifier_grille('image', y, x, cf=chemin_img, visible=True) self.vue.modifier_grille('texte', 0, 0, t='DEPART', visible=True) self.vue.modifier_grille('texte', self.haut - 1, self.larg - 1, t='ARRIVEE', visible=True) def chemin_robot_au_hasard(self): chemin_en_long = [True] * (self.larg - 1) + [False] * (self.haut - 1) shuffle(chemin_en_long) matrice_chemin = [[False for j in range(self.larg)] for i in range(self.haut)] lig, col = 0, 0 matrice_chemin[lig][col] = True for dep in chemin_en_long: if dep: col = col + 1 else: lig = lig + 1 matrice_chemin[lig][col] = True self.matrice_chemin = matrice_chemin self.afficher_matrices()