Séparation des modes de jeu en plusieurs fichiers, plus facile à manipuler
This commit is contained in:
58
jeu_humain.c
Normal file
58
jeu_humain.c
Normal file
@@ -0,0 +1,58 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <graph.h>
|
||||
#include <unistd.h>
|
||||
#include "jeu_humain.h"
|
||||
|
||||
void jouerModeHumain(struct EtatJeu *etatJeu) {
|
||||
while (1) {
|
||||
if (SourisCliquee()) {
|
||||
printf("Clic détecté sur la grille à : (%d, %d)\n", _X, _Y);
|
||||
gererClicHumain(etatJeu);
|
||||
|
||||
int gagnant = verifierVictoire(*etatJeu);
|
||||
if (gagnant != 0) {
|
||||
afficherVictoire(gagnant);
|
||||
printf("En attente d'un clic pour retourner au menu...\n");
|
||||
while (!SourisCliquee()) {
|
||||
usleep(100000);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
usleep(20000);
|
||||
}
|
||||
}
|
||||
|
||||
void gererClicHumain(struct EtatJeu *etatJeu) {
|
||||
int x = _X;
|
||||
int y = _Y;
|
||||
int largeurFenetre = 800;
|
||||
int hauteurFenetre = 600;
|
||||
int marge = 50;
|
||||
|
||||
int tailleCase = (largeurFenetre - 2 * marge) / etatJeu->tailleGrille;
|
||||
if (tailleCase * etatJeu->tailleGrille > (hauteurFenetre - 2 * marge)) {
|
||||
tailleCase = (hauteurFenetre - 2 * marge) / etatJeu->tailleGrille;
|
||||
}
|
||||
|
||||
int startX = (largeurFenetre - (tailleCase * etatJeu->tailleGrille)) / 2;
|
||||
int startY = (hauteurFenetre - (tailleCase * etatJeu->tailleGrille)) / 2;
|
||||
|
||||
x -= startX;
|
||||
y -= startY;
|
||||
|
||||
int i = y / tailleCase;
|
||||
int j = x / tailleCase;
|
||||
|
||||
if (i >= 0 && i < etatJeu->tailleGrille &&
|
||||
j >= 0 && j < etatJeu->tailleGrille &&
|
||||
etatJeu->grille[i][j] == 0) {
|
||||
|
||||
etatJeu->grille[i][j] = etatJeu->tourJoueur;
|
||||
etatJeu->tourJoueur = (etatJeu->tourJoueur == 1) ? 2 : 1;
|
||||
|
||||
EffacerEcran(CouleurParNom("white"));
|
||||
dessinerGrille(*etatJeu);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user