2023-11-21 12:20:06 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <graph.h>
|
2023-12-07 14:32:42 +01:00
|
|
|
#include "../fichier.h/time.h"
|
|
|
|
#include "../fichier.h/terrain.h"
|
|
|
|
#include "../fichier.h/serpent.h"
|
2023-11-21 12:20:06 +01:00
|
|
|
|
2023-11-21 14:36:58 +01:00
|
|
|
|
2023-12-07 14:32:42 +01:00
|
|
|
#define LARGEUR_FENETRE 1250
|
|
|
|
#define HAUTEUR_FENETRE 750
|
|
|
|
#define TAILLE_CELLULE 25
|
|
|
|
#define DELAI_MILLISECONDES 100
|
|
|
|
#define ESPACE_NOIR 100
|
2023-12-01 13:32:18 +01:00
|
|
|
|
2023-12-07 14:32:42 +01:00
|
|
|
void jeu(void) {
|
2023-11-21 12:20:06 +01:00
|
|
|
InitialiserGraphique();
|
2023-12-07 14:32:42 +01:00
|
|
|
CreerFenetre(10, 10, LARGEUR_FENETRE, HAUTEUR_FENETRE + ESPACE_NOIR);
|
|
|
|
ChoisirCouleurDessin(CouleurParComposante(0, 0, 0));
|
|
|
|
EffacerEcran(CouleurParComposante(0, 0, 0));
|
|
|
|
initialiserSerpent();
|
|
|
|
genererPomme();
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
dessinerDamier(); /* Dessiner le damier en fond*/
|
|
|
|
deplacerSerpent();
|
|
|
|
gestionCollision();
|
|
|
|
dessinerSerpent();
|
|
|
|
dessinerPomme();
|
|
|
|
attente(DELAI_MILLISECONDES); /* Attente pour ralentir le serpent*/
|
|
|
|
|
|
|
|
if (SourisCliquee()) {
|
|
|
|
FermerGraphique();
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ToucheEnAttente()) {
|
|
|
|
int touche = Touche();
|
|
|
|
switch (touche) {
|
|
|
|
case XK_Right:
|
|
|
|
direction = 0;
|
|
|
|
break;
|
|
|
|
case XK_Down:
|
|
|
|
direction = 1;
|
|
|
|
break;
|
|
|
|
case XK_Left:
|
|
|
|
direction = 2;
|
|
|
|
break;
|
|
|
|
case XK_Up:
|
|
|
|
direction = 3;
|
|
|
|
break;
|
|
|
|
case XK_Escape:
|
|
|
|
FermerGraphique();
|
2023-11-27 17:19:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-23 10:11:35 +01:00
|
|
|
|