2023-11-24 17:00:28 +01:00
|
|
|
#include <stdio.h>
|
2023-12-07 09:13:31 +01:00
|
|
|
#include <stdlib.h>
|
2023-11-24 17:00:28 +01:00
|
|
|
#include <graph.h>
|
2023-12-05 21:26:41 +01:00
|
|
|
#include "../include/grille.h"
|
|
|
|
#include "../include/serpent.h"
|
|
|
|
#include "../include/pomme.h"
|
2023-11-24 17:00:28 +01:00
|
|
|
#include "../include/jeu.h"
|
2023-12-07 09:13:31 +01:00
|
|
|
#include "../include/menu.h"
|
2023-12-09 21:43:13 +01:00
|
|
|
#include "../include/timer.h"
|
2023-12-07 09:13:31 +01:00
|
|
|
|
2023-12-12 20:11:39 +01:00
|
|
|
void jouer(int nbPommes, unsigned long int vitesse) {
|
2023-12-05 21:26:41 +01:00
|
|
|
int i;
|
2023-12-12 17:21:32 +01:00
|
|
|
Segment serpent[2400];
|
2023-12-07 09:13:31 +01:00
|
|
|
int longueur = 10;
|
|
|
|
int direction_x = 1;
|
|
|
|
int direction_y = 0;
|
|
|
|
int score = 0;
|
|
|
|
char scoreStr[20];
|
2023-12-12 20:11:39 +01:00
|
|
|
Pomme pommes[25];
|
2023-12-10 18:14:02 +01:00
|
|
|
int min, sec;
|
2023-12-11 18:40:04 +01:00
|
|
|
int id_pomme;
|
2023-12-12 20:11:39 +01:00
|
|
|
int esc = 0;
|
2023-12-05 21:26:41 +01:00
|
|
|
|
2023-12-10 18:14:02 +01:00
|
|
|
initialiser_timer(&min, &sec);
|
2023-12-07 09:13:31 +01:00
|
|
|
initialiserSerpent(serpent, &longueur);
|
|
|
|
dessinerGrille();
|
2023-12-12 20:11:39 +01:00
|
|
|
id_pomme = ChargerSprite("img/pomme1.png");
|
2023-12-07 09:13:31 +01:00
|
|
|
|
2023-12-12 20:11:39 +01:00
|
|
|
for (i = 0; i < nbPommes; i++) {
|
2023-12-07 09:13:31 +01:00
|
|
|
pommes[i] = creerPomme();
|
2023-12-12 20:11:39 +01:00
|
|
|
dessinerPomme(pommes[i], id_pomme);
|
2023-12-07 09:13:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
2023-12-12 20:11:39 +01:00
|
|
|
esc = gestionDeplacements(serpent, &direction_x, &direction_y);
|
|
|
|
if (esc == 1) {
|
|
|
|
return;
|
2023-12-11 18:56:40 +01:00
|
|
|
}
|
2023-12-07 09:13:31 +01:00
|
|
|
mettreAJourSerpent(serpent, &longueur, &direction_x, &direction_y);
|
|
|
|
|
2023-12-12 20:11:39 +01:00
|
|
|
for (i = 0; i < nbPommes; i++) {
|
2023-12-07 09:13:31 +01:00
|
|
|
if (serpent[0].x == pommes[i].x && serpent[0].y == pommes[i].y) {
|
2023-12-12 20:11:39 +01:00
|
|
|
longueur += 2;
|
2023-12-07 09:13:31 +01:00
|
|
|
score += 5;
|
2023-12-12 20:11:39 +01:00
|
|
|
if (vitesse >= 15000) {
|
|
|
|
vitesse -= 40;
|
|
|
|
}
|
2023-12-07 09:13:31 +01:00
|
|
|
pommes[i] = creerPomme();
|
2023-12-12 20:11:39 +01:00
|
|
|
dessinerPomme(pommes[i], id_pomme);
|
2023-12-07 09:13:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tuerSerpent(serpent, longueur)) {
|
|
|
|
int choixGameOver;
|
|
|
|
afficherMenuGameOver();
|
2023-12-10 18:14:02 +01:00
|
|
|
afficher_seconde(sec);
|
|
|
|
afficher_minute(min);
|
|
|
|
afficherScore(score);
|
2023-12-07 09:13:31 +01:00
|
|
|
|
|
|
|
/* Attend le choix du joueur après le game over */
|
2023-12-11 17:43:38 +01:00
|
|
|
attendreChoixGameOver();
|
|
|
|
return;
|
2023-12-07 09:13:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
dessinerSerpent(serpent, &longueur);
|
|
|
|
|
2023-12-07 18:15:48 +01:00
|
|
|
afficherScore(score);
|
2023-12-10 18:14:02 +01:00
|
|
|
update_timer(&min, &sec);
|
2023-12-07 09:13:31 +01:00
|
|
|
|
2023-12-10 18:14:02 +01:00
|
|
|
attendreSerpent(vitesse); /*Gère la vitesse*/
|
2023-12-07 09:13:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-12 20:11:39 +01:00
|
|
|
void lancer_jeu1(void) {
|
|
|
|
jouer(1, 100000);
|
|
|
|
}
|
2023-12-07 09:13:31 +01:00
|
|
|
|
2023-12-12 20:11:39 +01:00
|
|
|
void lancer_jeu2(void) {
|
|
|
|
jouer(2, 100000);
|
2023-12-07 09:13:31 +01:00
|
|
|
}
|
|
|
|
|
2023-12-09 21:43:13 +01:00
|
|
|
void lancer_jeu3(void) {
|
2023-12-12 20:11:39 +01:00
|
|
|
jouer(10, 90000);
|
|
|
|
}
|
2023-12-09 21:43:13 +01:00
|
|
|
|
2023-12-12 20:11:39 +01:00
|
|
|
void lancer_jeu4(void) {
|
|
|
|
jouer(25, 100000);
|
2023-12-11 18:40:04 +01:00
|
|
|
}
|