Ajout de plusieur fonction mais en tout cas meintenant on peut placer les pion a leur place de base via le joueur

This commit is contained in:
2024-11-15 15:45:18 +01:00
parent f2880c2bbf
commit 9a446cfafa
8 changed files with 126 additions and 15 deletions

View File

@@ -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

View File

@@ -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++;
}
}

20
coordoner.c Normal file
View File

@@ -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;
}

9
coordoner.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef COORDONER_H
#define COORDONER_H
int coordonerX(int SourisX);
int coordonerY(int SourisY);
#endif

8
effacehaut.c Normal file
View File

@@ -0,0 +1,8 @@
#include <graph.h>
void Efface(void){
ChoisirCouleurDessin(CouleurParNom("white"));
RemplirRectangle(0, 0, 650, 50);
ChoisirCouleurDessin(CouleurParNom("black"));
}

7
effacehaut.h Normal file
View File

@@ -0,0 +1,7 @@
#ifndef EFFACEHAUT_H
#define EFFACEHAUT_H
void Efface();
#endif

View File

@@ -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;
}

View File

@@ -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