From 9a446cfafab09cf615e9bf231509c3648531fbd8 Mon Sep 17 00:00:00 2001 From: abraham Date: Fri, 15 Nov 2024 15:45:18 +0100 Subject: [PATCH] Ajout de plusieur fonction mais en tout cas meintenant on peut placer les pion a leur place de base via le joueur --- Makefile | 8 ++++++- comportementJCJ.c | 55 +++++++++++++++++++++++++++++++++++++++-------- coordoner.c | 20 +++++++++++++++++ coordoner.h | 9 ++++++++ effacehaut.c | 8 +++++++ effacehaut.h | 7 ++++++ initialisation.c | 30 ++++++++++++++++++++++---- initialisation.h | 4 +++- 8 files changed, 126 insertions(+), 15 deletions(-) create mode 100644 coordoner.c create mode 100644 coordoner.h create mode 100644 effacehaut.c create mode 100644 effacehaut.h diff --git a/Makefile b/Makefile index 27aaf0e..ed639ec 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,8 @@ OFILES = taille.o \ comportementJCIA.o \ definirMaxXY.o \ initialisation.o \ + coordoner.o \ + effacehaut.o \ main.o @@ -28,11 +30,15 @@ menu.o : taille.h menu.h nbjoueur.h nbjoueur2.h boutonJVJ.h grille.h taille.o : taille.h jeu.h +effacehaut.o : effacehaut.h + +coordoner.o : coordoner.h + initialisation.o : initialisation.h nbjoueur.o : nbjoueur.h -comportementJCJ.o : comportementJCJ.h definirMaxXY.h initialisation.h +comportementJCJ.o : comportementJCJ.h definirMaxXY.h initialisation.h coordoner.h effacehaut.h comportementJCIA.o : comportementJCIA.h diff --git a/comportementJCJ.c b/comportementJCJ.c index 2fb45eb..b6bc873 100644 --- a/comportementJCJ.c +++ b/comportementJCJ.c @@ -5,11 +5,14 @@ #include "definirMaxXY.h" #include "initialisation.h" +#include "coordoner.h" +#include "effacehaut.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; + int maxX = 0, maxY = 0, joueurx1 = 0, joueury1 = 0, joueurx2 = 0, joueury2 = 0; + int emplacementcooX1 = 0, emplacementcooX2 = 0, emplacementcooY1 = 0, emplacementcooY2 = 0; int grille[taille+2][taille+2]; maxX = DefMaxX(taille); maxY = DefMaxY(taille); @@ -28,23 +31,57 @@ void compJCJ(int taille){ if(SourisCliquee()){ SourisX = _X; SourisY = _Y; - printf("%d, %d\n", SourisX, SourisY); - printf("max X Y : %d, %d\n", maxX, maxY); } if(initialiser == 0){ - if(SourisX >= 200 && SourisX <= maxX && SourisY >= 250 && SourisY <= maxY){ - printf("entre max\n"); - initialisation(SourisX, SourisY, maxX, maxY); + if(SourisX >= 50 && SourisX <= maxX && SourisY >= 100 && SourisY <= maxY){ + ChargerSprite("pion1.png"); + joueurx1 = initialisationX(SourisX, maxX, taille); + joueury1 = initialisationY(SourisY, maxY, taille); + emplacementcooX1 = coordonerX(SourisX); + emplacementcooY1 = coordonerY(SourisY); + AfficherSprite(1, emplacementcooX1, emplacementcooY1); + grille[joueury1][joueurx1] = 1; + initialiser++; + SourisX = 0; + SourisY = 0; + Efface(); + EcrireTexte(30, 40, "Joueur 2 choisissez l'emplacement de base du pion 2", 1); } }else if (initialiser == 1){ + if(SourisX >= 50 && SourisX <= maxX && SourisY >= 100 && SourisY <= maxY){ + ChargerSprite("pion2.png"); + joueurx2 = initialisationX(SourisX, maxX, taille); + joueury2 = initialisationY(SourisY, maxX, taille); + if(grille[joueury2][joueurx2] != 1){ + emplacementcooX2 = coordonerX(SourisX); + emplacementcooY2 = coordonerY(SourisY); + AfficherSprite(2, emplacementcooX2, emplacementcooY2); + grille[joueury2][joueurx2] = 2; + initialiser++; + initi++; + } + SourisX = 0; + SourisY = 0; + } } } while(fin == 0){ if(tour == 0){ - ChoisirCouleurDessin(CouleurParNom("white")); - RemplirRectangle(0, 0, 300, 50); - ChoisirCouleurDessin(CouleurParNom("black")); + Efface(); EcrireTexte(30, 40, "Tour du joueur 1", 2); + while(1){} + tour++; + }else if(tour == 2){ + Efface(); + EcrireTexte(30, 40, "Joueur 1 place le bloc", 2); + 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++; } } diff --git a/coordoner.c b/coordoner.c new file mode 100644 index 0000000..56c7702 --- /dev/null +++ b/coordoner.c @@ -0,0 +1,20 @@ +int coordonerX(int SourisX){ + int x = 0, z = 0; + for(z = 50; z <= 500; z += 50){ + if(SourisX > z){ + x = z + 5; + } + } + return x; +} + + +int coordonerY(int SourisY){ + int x = 0, z = 0; + for(z = 100; z <= 550; z += 50){ + if(SourisY > z){ + x = z + 5; + } + } + return x; +} diff --git a/coordoner.h b/coordoner.h new file mode 100644 index 0000000..f4b556f --- /dev/null +++ b/coordoner.h @@ -0,0 +1,9 @@ +#ifndef COORDONER_H +#define COORDONER_H + + +int coordonerX(int SourisX); + +int coordonerY(int SourisY); + +#endif diff --git a/effacehaut.c b/effacehaut.c new file mode 100644 index 0000000..aa9c1eb --- /dev/null +++ b/effacehaut.c @@ -0,0 +1,8 @@ +#include + + +void Efface(void){ + ChoisirCouleurDessin(CouleurParNom("white")); + RemplirRectangle(0, 0, 650, 50); + ChoisirCouleurDessin(CouleurParNom("black")); +} diff --git a/effacehaut.h b/effacehaut.h new file mode 100644 index 0000000..6f9730d --- /dev/null +++ b/effacehaut.h @@ -0,0 +1,7 @@ +#ifndef EFFACEHAUT_H +#define EFFACEHAUT_H + + +void Efface(); + +#endif diff --git a/initialisation.c b/initialisation.c index 0dde763..e42330c 100644 --- a/initialisation.c +++ b/initialisation.c @@ -1,5 +1,27 @@ - - - -int initialisation(int SourisX, int SourisY, int maxX, int maxY){ +int initialisationX(int SourisX, int maxX, int taille){ + int casejoueur = 0, x = 0, y = 50, verou = 0; + for(x = 0; x <= taille; x++){ + if(SourisX >= 50 && SourisX <= maxX){ + if(SourisX <= y && verou == 0){ + casejoueur = x; + verou++; + } + y += 50; + } + } + return casejoueur; +} + +int initialisationY(int SourisY, int maxY, int taille){ + int casejoueur = 0, x = 0, y = 100, verou = 0; + for(x = 0; x <= taille; x++){ + if(SourisY >= 100 && SourisY <= maxY){ + if(SourisY <= y && verou == 0){ + casejoueur = x; + verou++; + } + y += 50; + } + } + return casejoueur; } diff --git a/initialisation.h b/initialisation.h index 06a69e4..ab2fe3e 100644 --- a/initialisation.h +++ b/initialisation.h @@ -1,7 +1,9 @@ #ifndef INITIALISATION_H #define INITIALISATION_H -int initialisation(int SourisX, int SourisY, int maxX, int maxY); +int initialisationX(int SourisX, int maxX, int taille); +int initialisationY(int SourisY, int maxY, int taille); + #endif