From d11b5b8b51b001de1cf51c96dbacf9da17408d6e Mon Sep 17 00:00:00 2001 From: abraham Date: Fri, 15 Nov 2024 17:22:14 +0100 Subject: [PATCH] ajout des block mais pas fini car plus de temps de semaine donc travaille a la maison requis --- Makefile | 5 ++++- comportementJCJ.c | 27 ++++++++++++++++++--------- initialisation.c | 31 +++++++++++++++++++++++++++++++ initialisation.h | 5 ++++- verificationblock.c | 19 +++++++++++++++++++ verificationblock.h | 7 +++++++ 6 files changed, 83 insertions(+), 11 deletions(-) create mode 100644 verificationblock.c create mode 100644 verificationblock.h diff --git a/Makefile b/Makefile index ed639ec..f50e866 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ OFILES = taille.o \ initialisation.o \ coordoner.o \ effacehaut.o \ + verificationblock.o \ main.o @@ -34,11 +35,13 @@ effacehaut.o : effacehaut.h coordoner.o : coordoner.h +verificationblock.o : verificationblock.h + initialisation.o : initialisation.h nbjoueur.o : nbjoueur.h -comportementJCJ.o : comportementJCJ.h definirMaxXY.h initialisation.h coordoner.h effacehaut.h +comportementJCJ.o : comportementJCJ.h definirMaxXY.h initialisation.h coordoner.h effacehaut.h verificationblock.h comportementJCIA.o : comportementJCIA.h diff --git a/comportementJCJ.c b/comportementJCJ.c index c70dda2..7a4e6e1 100644 --- a/comportementJCJ.c +++ b/comportementJCJ.c @@ -7,13 +7,15 @@ #include "initialisation.h" #include "coordoner.h" #include "effacehaut.h" +#include "verificationblock.h" void compJCJ(int taille){ int fin = 0, tabx = 0, taby = 0, tour = 0, initi = 0, SourisX = 0, SourisY = 0, x = 50, y = 100, initialiser = 0; - int maxX = 0, maxY = 0, joueurx1 = 0, joueury1 = 0, joueurx2 = 0, joueury2 = 0; + int maxX = 0, maxY = 0, joueurx1 = 0, joueury1 = 0, joueurx2 = 0, joueury2 = 0, placer = 1; int emplacementcooX1 = 0, emplacementcooX2 = 0, emplacementcooY1 = 0, emplacementcooY2 = 0; int grille[taille+2][taille+2]; + int empblock[4] = {0, 0, 0, 0}; maxX = DefMaxX(taille); maxY = DefMaxY(taille); for(tabx = 0; tabx < taille + 2; tabx++){ @@ -51,7 +53,7 @@ void compJCJ(int taille){ if(SourisX >= 50 && SourisX <= maxX && SourisY >= 100 && SourisY <= maxY){ ChargerSprite("pion2.png"); joueurx2 = initialisationX(SourisX, maxX, taille); - joueury2 = initialisationY(SourisY, maxX, taille); + joueury2 = initialisationY(SourisY, maxY, taille); if(grille[joueury2][joueurx2] != 1){ emplacementcooX2 = coordonerX(SourisX); emplacementcooY2 = coordonerY(SourisY); @@ -70,20 +72,27 @@ void compJCJ(int taille){ Efface(); EcrireTexte(30, 40, "Tour du joueur 1", 2); tour++; - }else if(tour == 2){ + }else if(tour == 1){ Efface(); EcrireTexte(30, 40, "Joueur 1 place le bloc", 2); - while(1){ + while(placer == 1){ + VerifBlock1(maxX, maxY, taille, empblock); + if(empblock[2] == 6){ + printf("%d, %d", empblock[0], empblock[1]); + } } + placer = 1; + tour++; + }else if(tour == 2){ + Efface(); + EcrireTexte(30, 40, "Tour du joueur 2", 2); + while(1){} tour++; }else if(tour == 3){ - Efface(); - EcrireTexte(30, 40, "Tour du joueur 2", 2); - tour++; - }else if(tour == 4){ Efface(); EcrireTexte(30, 40, "Joueur 2 place le bloc", 2); - tour++; + while(1){} + tour = 0; } } } diff --git a/initialisation.c b/initialisation.c index e42330c..ec6ce13 100644 --- a/initialisation.c +++ b/initialisation.c @@ -25,3 +25,34 @@ int initialisationY(int SourisY, int maxY, int taille){ } return casejoueur; } + + + +int initialisationXbox(int SourisX, int maxX, int taille){ + int caseblock = 0, x = 0, y = 50, verou = 0; + for(x = 0; x <= taille; x++){ + if(SourisX >= 50 && SourisX <= maxX){ + if(SourisX <= y && verou == 0){ + caseblock = x; + verou++; + } + y += 50; + } + } + return caseblock; +} + + +int initialisationYbox(int SourisY, int maxY, int taille){ + int caseblock = 0, x = 0, y = 100, verou = 0; + for(x = 0; x <= taille; x++){ + if(SourisY >= 100 && SourisY <= maxY){ + if(SourisY <= y && verou == 0){ + caseblock = x; + verou++; + } + y += 50; + } + } + return caseblock; +} diff --git a/initialisation.h b/initialisation.h index ab2fe3e..64d1d9c 100644 --- a/initialisation.h +++ b/initialisation.h @@ -3,7 +3,10 @@ int initialisationX(int SourisX, int maxX, int taille); - int initialisationY(int SourisY, int maxY, int taille); +int initialisationXbox(int SourisX, int maxX, int taille); + +int initialisationYbox(int SourisY, int maxY, int taille); + #endif diff --git a/verificationblock.c b/verificationblock.c new file mode 100644 index 0000000..3f8eeb8 --- /dev/null +++ b/verificationblock.c @@ -0,0 +1,19 @@ +#include + +#include "initialisation.h" + + +int VerifBlock1(int maxX, int maxY, int taille, int* coordoner){ + int SourisX = 0, SourisY = 0, placement = 1, placementX = 0, placementY = 0; + if(SourisCliquee()){ + SourisX = _X; + SourisY = _Y; + } + if(SourisX >= 50 && SourisX <= maxX && SourisY >= 100 && SourisY <= maxY){ + placementX = initialisationXbox(SourisX, maxX, taille); + placementY = initialisationYbox(SourisY, maxY, taille); + } + coordoner[0] = placementX; + coordoner[1] = placementY; + coordoner[2] = 6; +} diff --git a/verificationblock.h b/verificationblock.h new file mode 100644 index 0000000..c6d542f --- /dev/null +++ b/verificationblock.h @@ -0,0 +1,7 @@ +#ifndef VERIFICATIONBLOCK_H +#define VERIFICATIONBLOCK_H + +int VerifBlock1(int maxX, int maxY, int taille, int* coordoner); + + +#endif