Peer Working : Ajout de nouveaux modes de jeux
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <graph.h>
|
||||
#include "../include/serpent.h"
|
||||
#include "../include/main.h"
|
||||
#define TAILLE_CASE 20
|
||||
#define LARGEUR_GRILLE 60
|
||||
#define HAUTEUR_GRILLE 40
|
||||
@@ -8,9 +9,12 @@
|
||||
|
||||
void initialiserSerpent(Segment serpent[], int *longueur) {
|
||||
int i;
|
||||
int centreX = LARGEUR_GRILLE / 2;
|
||||
int centreY = HAUTEUR_GRILLE / 2;
|
||||
|
||||
for (i = 0; i < 10; ++i) {
|
||||
serpent[i].x = 10 - i;
|
||||
serpent[i].y = 10;
|
||||
serpent[i].x = centreX - i;
|
||||
serpent[i].y = centreY;
|
||||
}
|
||||
|
||||
*longueur = 10;
|
||||
@@ -32,7 +36,10 @@ void gestionDeplacements(Segment serpent[], int *direction_x, int *direction_y)
|
||||
} else if (touche == XK_Right && *direction_x == 0) {
|
||||
*direction_x = 1;
|
||||
*direction_y = 0;
|
||||
}
|
||||
} else if (touche == XK_Escape) {
|
||||
FermerGraphique();
|
||||
main();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,20 +66,28 @@ void mettreAJourSerpent(Segment serpent[], int *longueur, int *direction_x, int
|
||||
int i;
|
||||
int ancienX = serpent[*longueur - 1].x;
|
||||
int ancienY = serpent[*longueur - 1].y;
|
||||
|
||||
/* Déterminer la couleur de fond en fonction de la position de la case dans la grille */
|
||||
couleur couleurFond = (ancienX + ancienY) % 2 == 0 ? CouleurParComposante(170, 215, 82) : CouleurParComposante(180, 220, 90);
|
||||
|
||||
/* Remplir la case avec la couleur de fond appropriée */
|
||||
ChoisirCouleurDessin(couleurFond);
|
||||
RemplirRectangle(ancienX * TAILLE_CASE, ancienY * TAILLE_CASE, TAILLE_CASE, TAILLE_CASE);
|
||||
|
||||
/* Remplir la case avec la couleur de la grille à cet endroit précis */
|
||||
ChoisirCouleurDessin(CouleurParComposante(170, 215, 82));
|
||||
RemplirRectangle(0, 0, TAILLE_CASE, TAILLE_CASE);
|
||||
|
||||
for (i = *longueur - 1; i > 0; --i) {
|
||||
serpent[i] = serpent[i - 1];
|
||||
}
|
||||
serpent[0].x += *direction_x;
|
||||
serpent[0].y += *direction_y;
|
||||
|
||||
tuerSerpent(serpent,*longueur); /*Appeler la fonction pour vérifier si le serpent est mort*/
|
||||
tuerSerpent(serpent, *longueur); /*Appeler la fonction pour vérifier si le serpent est mort*/
|
||||
}
|
||||
|
||||
|
||||
void dessinerSerpent(Segment serpent[], int *longueur) {
|
||||
int i;
|
||||
for (i = 0; i < *longueur; ++i) {
|
||||
@@ -80,3 +95,10 @@ void dessinerSerpent(Segment serpent[], int *longueur) {
|
||||
RemplirRectangle(serpent[i].x * TAILLE_CASE, serpent[i].y * TAILLE_CASE, TAILLE_CASE, TAILLE_CASE);
|
||||
}
|
||||
}
|
||||
|
||||
void attendreSerpent(unsigned long int microseconds) {
|
||||
unsigned long int attente_jusqu_a = Microsecondes() + microseconds;
|
||||
while (Microsecondes() < attente_jusqu_a) {
|
||||
/*Attendre jusqu'au temps données en paramètre de la fonction*/
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user