From 34d72b58837a7877901af005c2e2608dbdbdb89a Mon Sep 17 00:00:00 2001 From: neox Date: Wed, 27 Dec 2023 14:45:15 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20des=20changements=20du=2026=20d=C3=A9ce?= =?UTF-8?q?mbre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.py | 23 +++-- piege.py | 153 ++++++++++++++++++++++++------ sprites/{bille.png => bille1.png} | Bin sprites/{bois.png => bois1.png} | Bin 4 files changed, 135 insertions(+), 41 deletions(-) rename sprites/{bille.png => bille1.png} (100%) rename sprites/{bois.png => bois1.png} (100%) diff --git a/game.py b/game.py index 4204201..d2a00df 100644 --- a/game.py +++ b/game.py @@ -67,14 +67,14 @@ class Plateau: """ self.trous = [ [False] * DIM * DIM ] * 2 # Espace 7 × 7, deux fois pour # vertical et horizontal - self.billes = [] # liste de tuples (x,y) + self.billes = [] # liste de tuples (x,y,joueur) - self.tirettes = [ [None] * DIM ] * 2 # Espace 7 , deux fois pour - # vertical et horizontal + self.tirettes = [ [None] * DIM ] * 2 + # Espace 7 , deux fois pour + # vertical et horizontal + self.générer_tirettes() - return self - - def générer_tirettes(): + def générer_tirettes(self): """ genere les tirettes @params void @@ -83,7 +83,7 @@ class Plateau: """ for orientation in range(2): # vertical et horizontal for i in range(DIM): - self.tirettes[orientation][i] = + self.tirettes[orientation][i] = \ Tirette(i+(orientation*DIM), self) def est_ce_un_trou(self,x,y): @@ -92,7 +92,8 @@ class Plateau: @params x l'abscisse et y l'ordonnée @return boolean """ - return self.trous[calcul_coord(x,y)] + return self.trous[0][calcul_coord(x,y)] \ + and self.trous[0][calcul_coord(x,y)] def mise_à_jour(self): @@ -133,7 +134,6 @@ class Tirette: # position initiale à 0 self.position = 0 - return self def calcul_pos(self, offset): """ @@ -177,7 +177,6 @@ class Joueur: constructor """ self.plateau = plateau - return self def placer_bille(self, x, y): """ @@ -187,7 +186,7 @@ class Joueur: """ if not self.plateau.est_ce_un_trou(x,y): - if not (x,y) in self.plateau.billes: - self.plateau.billes.append((x,y)) + if not (x,y,self) in self.plateau.billes: + self.plateau.billes.append((x,y,self)) return True return False diff --git a/piege.py b/piege.py index eb5db51..653de88 100755 --- a/piege.py +++ b/piege.py @@ -13,17 +13,18 @@ import random, fltk, time, os, importlib import game ## VARIABLES DE CONFIGURATION -LARGEUR_FENETRE = 800 -HAUTEUR_FENETRE = 800 +LARGEUR_FENETRE = 900 +HAUTEUR_FENETRE = 1000 DIM = 7 VERTICAL = 0 HORIZONTAL = 1 -def run_game(): +def run_game(joueur1, joueur2, plateau): """ Running game - @params void + @params joueur1, joueur2, players (class Joueur) + plateau, game board (class Plateau) @return void """ @@ -44,36 +45,126 @@ def run_game(): "tirette_horiz":"sprites/tirette.png", "barre_horiz":"sprites/barre.png", "tirette_vert":"sprites/tirette2.png", - "barre_horiz":"sprites/barre2.png", - "bille":"", + "barre_vert":"sprites/barre2.png", + "bille1":"sprites/bille1.png", + "bille2":"sprites/bille2.png", "tour_de_plateau":"sprites/bois3.png", "case1":"sprites/bois1.png", - "case2":"sprites/bois2.png" + "case2":"sprites/bois2.png", + "trou": "sprites/trou.png" } + OFFSET_X = 230 + OFFSET_Y = 230 + + # Boucle principale while True: fltk.mise_a_jour() + plateau.mise_à_jour() + + # Affichage plateau - for i in range(DIM+2): - for j in range(DIM+2): + # Tirettes verticales + for i in range(DIM): + #XXX récupérer la position de la tirette -> n + # boucler x fois pour afficher des barres + + n = plateau.tirettes[0][i].position + + fltk.image( OFFSET_X + (i+1)*62, + OFFSET_Y + (DIM+1)*62 + n*30, + modeles["tirette_vert"], + ancrage = "center", + largeur=50, + hauteur=50, + tag="{}".format(i)) + + for x in range(n): + fltk.image( OFFSET_X + (i+1)*62, + OFFSET_Y + (DIM+1)*62 + x*30, + modeles["barre_vert"], + ancrage = "center", + largeur=50, + hauteur=50, + tag="{}".format(i)) + + # Tirettes horizontales + for j in range(DIM): + #XXX récupérer la position de la tirette -> n + # boucler x fois pour afficher des barres + n = plateau.tirettes[1][j].position + + fltk.image( OFFSET_X + 20 + (0)*62 - n*30, + OFFSET_Y + 20 + (j+1)*62, + modeles["tirette_horiz"], + ancrage = "center", + largeur=55, + hauteur=55, + tag="{}".format(i)) + + for x in range(n): + fltk.image( OFFSET_X + 20 + (0)*62 - x*30, + OFFSET_Y + 20 + (j+1)*62, + modeles["barre_horiz"], + ancrage = "center", + largeur=50, + hauteur=50, + tag="{}".format(i)) + + # Plateau + for i in range(0,DIM): + for j in range(0,DIM): # Choix du type de sprite selon position - if (i < 0 or j < 0 or i > DIM or j > DIM): - type_modele = "tour_de_plateau" + if (i+j) % 2 == 0: + type_modele = "case1" + #elif trou: + # type_modele = trou else: - if (i+j) % 2 == 0: - type_modele = "case1" - else: - type_modele = "case2" + type_modele = "case2" - fltk.image( 100+i*100, - 150+j*100, - modeles[type_modele], #XXX déterminer type - ancrage = "nw", - largeur=100, - hauteur=100, + fltk.image( OFFSET_X + 2 + (i+1)*62, + OFFSET_Y + 20 + (j+1)*62, + modeles[type_modele], + ancrage = "center", + largeur=60, + hauteur=60, tag="{},{}".format(i,j)) + #XXX TROUS + if plateau.est_ce_un_trou(i,j): + fltk.image( OFFSET_X + 2 + (i+1)*62, + OFFSET_Y + 20 + (j+1)*62, + modeles["trou"], + ancrage = "center", + largeur=60, + hauteur=60, + tag="{},{}".format(i,j)) + + # Billes + for bille in plateau.billes: + if bille[2] is joueur1: + fltk.image( OFFSET_X + 2 + (i+1)*62, + OFFSET_Y + 20 + (j+1)*62, + modeles["bille1"], + ancrage = "center", + largeur=30, + hauteur=30, + tag="{},{}".format(i,j)) + + if bille[2] is joueur2: + fltk.image( OFFSET_X + 2 + (i+1)*62, + OFFSET_Y + 20 + (j+1)*62, + modeles["bille2"], + ancrage = "center", + largeur=30, + hauteur=30, + tag="{},{}".format(i,j)) + + + #XXX Affichage instructions liées au mode de jeu + + fltk.mise_a_jour() event = fltk.attend_ev() if "Quitte" in fltk.type_ev(event): @@ -96,13 +187,14 @@ def run_game(): x = fltk.abscisse(event) y = fltk.ordonnee(event) - print("Clic sur coords ({},{})".format(x,y)) + i = int( (x - OFFSET_X - 2 + 62/2)/62 - 1) + j = int( (y - OFFSET_Y - 20 + 62/2)/62 - 1) - # if x > 100 and y > 150 and x < 700 and y < 750: - # x_n = int((x - 100) / 100) - # y_n = int((y - 150) / 100) - # print("Rotation de salle ({},{}) demandée".format(x_n, y_n)) - # réaliser_action()) #XXX + print("Clic sur coords ({},{})".format(x,y)) + print(" case {},{}".format(i,j)) + + #clic_sur_case(i, j) + ## XXX Gérer évènement de clic ## Fonction principale @@ -110,9 +202,12 @@ def main(): while True: importlib.reload(fltk) # corrige un bug sérieux de fltk avec les images - #XXX créer joueurs + plateau = game.Plateau() + + joueur1 = game.Joueur(plateau) + joueur2 = game.Joueur(plateau) - run_game() + run_game(joueur1, joueur2, plateau) #XXX vérifier condition de sortie diff --git a/sprites/bille.png b/sprites/bille1.png similarity index 100% rename from sprites/bille.png rename to sprites/bille1.png diff --git a/sprites/bois.png b/sprites/bois1.png similarity index 100% rename from sprites/bois.png rename to sprites/bois1.png