Files
SAE11_2024/comportementJCJ.c

228 lines
7.7 KiB
C
Raw Normal View History

#include <graph.h>
2024-11-14 14:50:14 +01:00
#include <stdio.h>
2024-11-15 09:50:42 +01:00
#include "definirMaxXY.h"
#include "initialisation.h"
#include "coordoner.h"
#include "effacehaut.h"
#include "verificationblock.h"
2024-11-15 09:50:42 +01:00
void compJCJ(int taille){
2024-11-15 09:50:42 +01:00
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, placer = 1;
int emplacementcooX1 = 0, emplacementcooX2 = 0, emplacementcooY1 = 0, emplacementcooY2 = 0;
2024-11-14 14:50:14 +01:00
int grille[taille+2][taille+2];
int empblock[4] = {0, 0, 0, 0}, empperso[4] = {0, 0, 0, 0};
2024-11-15 09:50:42 +01:00
maxX = DefMaxX(taille);
maxY = DefMaxY(taille);
2024-11-14 14:50:14 +01:00
for(tabx = 0; tabx < taille + 2; tabx++){
for(taby = 0; taby < taille + 2; taby++){
grille[tabx][taby] = 0;
if(taby == 0 || taby == taille + 1 || tabx == 0 || tabx == taille + 1){
grille[tabx][taby] = 9;
}
}
}
EcrireTexte(30, 40, "Joueur 1 choisissez l'emplacement de base du pion 1", 1);
2024-11-15 09:50:42 +01:00
while(initi == 0){
2024-11-14 14:50:14 +01:00
if(SourisCliquee()){
SourisX = _X;
SourisY = _Y;
}
2024-11-15 09:50:42 +01:00
if(initialiser == 0){
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;
2024-11-18 13:32:53 +01:00
for(tabx = 0; tabx < taille + 2; tabx++){
for(taby = 0; taby < taille + 2; taby++){
printf("%d", grille[tabx][taby]);
}
printf("\n");
}
Efface();
EcrireTexte(30, 40, "Joueur 2 choisissez l'emplacement de base du pion 2", 1);
2024-11-14 14:50:14 +01:00
}
2024-11-15 09:50:42 +01:00
}else if (initialiser == 1){
if(SourisX >= 50 && SourisX <= maxX && SourisY >= 100 && SourisY <= maxY){
ChargerSprite("pion2.png");
joueurx2 = initialisationX(SourisX, maxX, taille);
joueury2 = initialisationY(SourisY, maxY, 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;
2024-11-18 13:32:53 +01:00
for(tabx = 0; tabx < taille + 2; tabx++){
for(taby = 0; taby < taille + 2; taby++){
printf("%d", grille[tabx][taby]);
}
printf("\n");
}
}
2024-11-14 14:50:14 +01:00
}
}
ChargerSprite("croix1.png");
ChargerSprite("croix2.png");
2024-11-13 23:25:07 +01:00
while(fin == 0){
2024-11-14 14:50:14 +01:00
if(tour == 0){
Efface();
2024-11-14 14:50:14 +01:00
EcrireTexte(30, 40, "Tour du joueur 1", 2);
SourisX = 0;
SourisY = 0;
while(placer == 1){
if(SourisCliquee()){
SourisX = _X;
SourisY = _Y;
}
VerifBlock1(SourisX, SourisY, maxX, maxY, taille, empperso);
if(empperso[0] != 0){
if(grille[empperso[1]][empperso[0]] == 0){
2024-11-18 13:32:53 +01:00
grille[joueury1][joueurx1] = 0;
ChoisirCouleurDessin(CouleurParNom("white"));
2024-11-18 13:32:53 +01:00
RemplirRectangle(emplacementcooX1, emplacementcooY1, 40, 40);
ChoisirCouleurDessin(CouleurParNom("black"));
joueurx1 = empperso[0];
joueury1 = empperso[1];
empperso[2] = coordonerX(SourisX);
empperso[3] = coordonerY(SourisY);
2024-11-18 13:32:53 +01:00
grille[empperso[1]][empperso[0]] = 1;
AfficherSprite(1, empperso[2], empperso[3]);
2024-11-18 13:32:53 +01:00
emplacementcooX1 = empperso[2];
emplacementcooY1 = empperso[3];
placer = 0;
2024-11-18 13:32:53 +01:00
for(tabx = 0; tabx < taille + 2; tabx++){
for(taby = 0; taby < taille + 2; taby++){
printf("%d", grille[tabx][taby]);
}
printf("\n");
}
}
}
}
empperso[0] = 0;
placer = 1;
tour++;
}else if(tour == 1){
Efface();
EcrireTexte(30, 40, "Joueur 1 place le bloc", 2);
SourisX = 0;
SourisY = 0;
while(placer == 1){
if(SourisCliquee()){
SourisX = _X;
SourisY = _Y;
}
VerifBlock1(SourisX, SourisY, maxX, maxY, taille, empblock);
if(empblock[0] != 0){
if(grille[empblock[1]][empblock[0]] == 0){
empblock[2] = coordonerX(SourisX);
empblock[3] = coordonerY(SourisY);
2024-11-18 13:32:53 +01:00
grille[empblock[1]][empblock[0]] = 3;
AfficherSprite(3, empblock[2], empblock[3]);
placer = 0;
2024-11-18 13:32:53 +01:00
for(tabx = 0; tabx < taille + 2; tabx++){
for(taby = 0; taby < taille + 2; taby++){
printf("%d", grille[tabx][taby]);
}
printf("\n");
}
}
}
2024-11-15 15:57:03 +01:00
}
empblock[0] = 0;
placer = 1;
tour++;
}else if(tour == 2){
Efface();
2024-11-18 13:32:53 +01:00
EcrireTexte(30, 40, "Tour du joueur 2", 2);
SourisX = 0;
SourisY = 0;
while(placer == 1){
if(SourisCliquee()){
SourisX = _X;
SourisY = _Y;
}
VerifBlock1(SourisX, SourisY, maxX, maxY, taille, empperso);
if(empperso[0] != 0){
if(grille[empperso[1]][empperso[0]] == 0){
grille[joueury2][joueurx2] = 0;
ChoisirCouleurDessin(CouleurParNom("white"));
RemplirRectangle(emplacementcooX2, emplacementcooY2, 40, 40);
ChoisirCouleurDessin(CouleurParNom("black"));
joueurx2 = empperso[0];
joueury2 = empperso[1];
empperso[2] = coordonerX(SourisX);
empperso[3] = coordonerY(SourisY);
grille[empperso[1]][empperso[0]] = 2;
AfficherSprite(2, empperso[2], empperso[3]);
emplacementcooX2 = empperso[2];
emplacementcooY2 = empperso[3];
placer = 0;
for(tabx = 0; tabx < taille + 2; tabx++){
for(taby = 0; taby < taille + 2; taby++){
printf("%d", grille[tabx][taby]);
}
printf("\n");
}
}
}
}
empperso[0] = 0;
placer = 1;
tour++;
}else if(tour == 3){
Efface();
EcrireTexte(30, 40, "Joueur 2 place le bloc", 2);
SourisX = 0;
SourisY = 0;
while(placer == 1){
if(SourisCliquee()){
SourisX = _X;
SourisY = _Y;
}
VerifBlock1(SourisX, SourisY, maxX, maxY, taille, empblock);
if(empblock[0] != 0){
if(grille[empblock[1]][empblock[0]] == 0){
empblock[2] = coordonerX(SourisX);
empblock[3] = coordonerY(SourisY);
2024-11-18 13:32:53 +01:00
grille[empblock[1]][empblock[0]] = 4;
AfficherSprite(4, empblock[2], empblock[3]);
placer = 0;
2024-11-18 13:32:53 +01:00
for(tabx = 0; tabx < taille + 2; tabx++){
for(taby = 0; taby < taille + 2; taby++){
printf("%d", grille[tabx][taby]);
}
printf("\n");
}
}
}
}
empblock[0] = 0;
placer = 1;
tour = 0;
2024-11-14 14:50:14 +01:00
}
2024-11-13 23:25:07 +01:00
}
}