ajout de l'écran de fin du jeu
This commit is contained in:
parent
1e79f977be
commit
0873aebe7d
@ -14,6 +14,8 @@ OFILES = plateau_init.o \
|
||||
ajout_score.o \
|
||||
score_init.o \
|
||||
supp_queue.o \
|
||||
affichage_timer.o \
|
||||
ecran_fin.o \
|
||||
main.o
|
||||
|
||||
|
||||
@ -33,13 +35,17 @@ augmentation_serpent.o : augmentation_serpent.h
|
||||
|
||||
deplacement.o : deplacement.h supp_queue.h
|
||||
|
||||
supp_queue.o : supp_queue.h augmentation_serpent.h ajout_score.h
|
||||
supp_queue.o : supp_queue.h augmentation_serpent.h ajout_score.h
|
||||
|
||||
ecran_fin.o : ecran_fin.h
|
||||
|
||||
ajout_score.o : ajout_score.h
|
||||
|
||||
score_init.o : score_init.h
|
||||
|
||||
main.o : main.c fenetre.h deplacement.h
|
||||
affichage_timer.o : affichage_timer.h
|
||||
|
||||
main.o : main.c fenetre.h deplacement.h affichage_timer.h ecran_fin.h
|
||||
|
||||
|
||||
|
||||
|
43
snake/affichage_timer.c
Normal file
43
snake/affichage_timer.c
Normal file
@ -0,0 +1,43 @@
|
||||
/* fonction d'affichage du score dans la fenêtre graphique */
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "affichage_timer.h"
|
||||
|
||||
|
||||
void affichage_timer(unsigned char minutes, unsigned char secondes) {
|
||||
|
||||
|
||||
char min[5];
|
||||
char sec[5];
|
||||
|
||||
couleur grey, white;
|
||||
|
||||
|
||||
|
||||
grey = CouleurParComposante(35,35,35);
|
||||
ChoisirCouleurDessin(grey);
|
||||
RemplirRectangle(1250, 150, 170, 70);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
sprintf(min, "%hhu", minutes);
|
||||
|
||||
sprintf(sec, "%hhu", secondes);
|
||||
|
||||
|
||||
|
||||
white = CouleurParComposante(255, 255, 255);
|
||||
ChoisirCouleurDessin(white);
|
||||
|
||||
EcrireTexte(1290, 180, min, 2);
|
||||
|
||||
EcrireTexte(1330, 180, ":", 2);
|
||||
|
||||
EcrireTexte(1370, 180, sec, 2);
|
||||
|
||||
|
||||
}
|
12
snake/affichage_timer.h
Normal file
12
snake/affichage_timer.h
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
#ifndef AFFICHAGE_TIMER_H
|
||||
#define AFFICHAGE_TIMER_H
|
||||
|
||||
#include <graph.h>
|
||||
|
||||
|
||||
void affichage_timer( unsigned char minutes, unsigned char secondes) ;
|
||||
|
||||
|
||||
#endif /* AFFICHAGE_TIMER_H */
|
@ -27,12 +27,12 @@ void ajout_score(short int* compteur) {
|
||||
|
||||
|
||||
ChoisirCouleurDessin(grey);
|
||||
RemplirRectangle( 1250, 570, 70, 40);
|
||||
RemplirRectangle( 1300, 620, 70, 40);
|
||||
|
||||
|
||||
|
||||
ChoisirCouleurDessin(white);
|
||||
EcrireTexte(1270, 600, a, 2);
|
||||
EcrireTexte(1310, 650, a, 2);
|
||||
|
||||
|
||||
}
|
||||
|
@ -256,10 +256,49 @@ unsigned char deplacement (struct adresse* pointeur, unsigned char* sens, unsign
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* pour quiiter directement le jeu */
|
||||
|
||||
if ( touche == XK_Escape) {
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* pour mette le jeu pause puis soit reprendere le jeu soit quiiter le jeu */
|
||||
|
||||
if (touche == XK_space) {
|
||||
|
||||
touche = Touche();
|
||||
|
||||
if ( touche == XK_space) {
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
if ( touche == XK_Escape) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
else {
|
||||
|
@ -6,20 +6,24 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <graph.h>
|
||||
#include "ecran_fin.h"
|
||||
|
||||
|
||||
|
||||
void ecran_fin(short int* compteur, unsigned char minutes, unsigned char secondes) {
|
||||
|
||||
int main(void) {
|
||||
|
||||
couleur grey, green, yellow, red, black;
|
||||
|
||||
|
||||
InitialiserGraphique();
|
||||
|
||||
|
||||
CreerFenetre(400,150,650,500);
|
||||
couleur grey, white, red;
|
||||
|
||||
char comp[10];
|
||||
|
||||
char min[5];
|
||||
char sec[5];
|
||||
|
||||
int touche;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -27,40 +31,60 @@ couleur grey, green, yellow, red, black;
|
||||
grey = CouleurParComposante(60, 60, 60);
|
||||
ChoisirCouleurDessin(grey);
|
||||
|
||||
RemplirRectangle(0,0,650,500);
|
||||
RemplirRectangle(400,150,650,500);
|
||||
|
||||
red = CouleurParComposante(255,0,0);
|
||||
ChoisirCouleurDessin(red);
|
||||
|
||||
EcrireTexte(280,50, "DEAD", 2);
|
||||
EcrireTexte(680,250, "DEAD", 2);
|
||||
|
||||
EcrireTexte(90,370, "space = play", 2);
|
||||
EcrireTexte(490,370, "espace = rejouer", 2);
|
||||
|
||||
EcrireTexte(400,370, "echap = quit", 2);
|
||||
EcrireTexte(800,370, "echap = quitter", 2);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
yellow = CouleurParComposante(255,255,0);
|
||||
ChoisirCouleurDessin(yellow);
|
||||
white = CouleurParComposante(255,255,255);
|
||||
ChoisirCouleurDessin(white);
|
||||
|
||||
EcrireTexte(20,200, "score : ", 2);
|
||||
EcrireTexte(420,500, "Votre score : ", 2);
|
||||
|
||||
EcrireTexte(20,250, " time : ", 2);
|
||||
sprintf(comp, "%hd", *compteur);
|
||||
|
||||
EcrireTexte( 620, 500, comp, 2);
|
||||
|
||||
|
||||
EcrireTexte(750,500, "Temps ", 2);
|
||||
|
||||
sprintf(min, "%hhd", minutes);
|
||||
|
||||
EcrireTexte (875, 500, min, 2);
|
||||
|
||||
EcrireTexte (900, 500, ":", 2);
|
||||
|
||||
sprintf( sec, "%hhd", secondes);
|
||||
|
||||
EcrireTexte( 920, 500, sec, 2);
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
ajout_score();
|
||||
time()
|
||||
*/
|
||||
|
||||
Touche();
|
||||
FermerGraphique();
|
||||
free(compteur);
|
||||
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
touche = Touche();
|
||||
|
||||
if ( touche == XK_Escape ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( touche == XK_space) {
|
||||
|
||||
main();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
11
snake/ecran_fin.h
Normal file
11
snake/ecran_fin.h
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
#ifndef ECRAN_FIN_H
|
||||
#define ECRAN_FIN_H
|
||||
|
||||
#include <graph.h>
|
||||
|
||||
void ecran_fin( short int* compteur, unsigned char minutes, unsigned char secondes);
|
||||
|
||||
|
||||
#endif /* ECRAN_FIN_H */
|
@ -18,11 +18,11 @@ int start (struct adresse* pointeur) {
|
||||
int i, j;
|
||||
|
||||
|
||||
char* texte1 = "espace = lancer";
|
||||
char* texte1 = "Touche directionnelles = déplacement";
|
||||
|
||||
char* texte2 = "espace = pause";
|
||||
char* texte2 = "Espace = pause";
|
||||
|
||||
char* texte3 = "echap = quitter";
|
||||
char* texte3 = "Echap = quitter";
|
||||
|
||||
int score=0;
|
||||
|
||||
@ -63,14 +63,12 @@ int start (struct adresse* pointeur) {
|
||||
|
||||
white = CouleurParComposante(255,255,255);
|
||||
ChoisirCouleurDessin(white);
|
||||
EcrireTexte(1250, 300, texte1, 1);
|
||||
EcrireTexte(1250, 345, texte2, 1);
|
||||
EcrireTexte(1250, 390, texte3, 1);
|
||||
|
||||
/*affichage compteur pomme (score)*/
|
||||
|
||||
|
||||
|
||||
EcrireTexte(1290, 140, "Temps", 2);
|
||||
EcrireTexte(1250, 300, "Utiliser les fleches", 1);
|
||||
EcrireTexte(1250, 320, "pour se deplacer", 1);
|
||||
EcrireTexte(1250, 370, "Espace = pause", 1);
|
||||
EcrireTexte(1250, 435, "Echape = quiiter", 1);
|
||||
EcrireTexte(1290, 600, "Score",2);
|
||||
|
||||
|
||||
|
||||
|
68
snake/main.c
68
snake/main.c
@ -7,10 +7,12 @@
|
||||
#include "deplacement.h"
|
||||
#include "score_init.h"
|
||||
#include "ecran_lancement.h"
|
||||
#include "affichage_timer.h"
|
||||
#include "ecran_fin.h"
|
||||
|
||||
|
||||
#define CYCLE 200000L
|
||||
|
||||
#define CYCLE_SERPENT 200000L
|
||||
#define CYCLE_TIMER 1000000L
|
||||
|
||||
int main(void) {
|
||||
|
||||
@ -21,7 +23,7 @@ int main(void) {
|
||||
|
||||
short int* compteur = NULL;
|
||||
|
||||
int i = 0, j;
|
||||
int i;
|
||||
|
||||
|
||||
unsigned short* indice_queue = pointeur -> indice_queue;
|
||||
@ -32,13 +34,14 @@ int main(void) {
|
||||
|
||||
unsigned char* tete = pointeur -> tete;
|
||||
|
||||
unsigned char jeu;
|
||||
unsigned char jeu, entrer, minutes, secondes;
|
||||
|
||||
unsigned long suivant;
|
||||
unsigned long suivant_serpent, suivant_timer;
|
||||
|
||||
unsigned long acceleration = 0L;
|
||||
|
||||
int numsprite;
|
||||
int numsprite;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -51,7 +54,10 @@ int main(void) {
|
||||
*retard = 0;
|
||||
|
||||
|
||||
suivant = Microsecondes() + CYCLE;
|
||||
suivant_serpent = Microsecondes() + CYCLE_SERPENT;
|
||||
|
||||
suivant_timer = Microsecondes() + CYCLE_TIMER;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -66,29 +72,35 @@ int main(void) {
|
||||
|
||||
jeu = ecran_lancement();
|
||||
|
||||
if (jeu == 1) {
|
||||
|
||||
entrer = 1;
|
||||
}
|
||||
|
||||
|
||||
numsprite = start(pointeur);
|
||||
|
||||
compteur = score_init();
|
||||
|
||||
minutes = 0;
|
||||
|
||||
secondes = 0;
|
||||
|
||||
affichage_timer(minutes, secondes);
|
||||
|
||||
|
||||
|
||||
while (jeu == 1) {
|
||||
|
||||
if (Microsecondes() > suivant) {
|
||||
|
||||
/* printf("(%d %d)\n", pointeur -> corps_serpent[*indice_queue][0], pointeur -> corps_serpent[*indice_queue][1]);
|
||||
|
||||
printf("[%hhu %hhu]\n", tete[0], tete[1]);*/
|
||||
|
||||
if (Microsecondes() > suivant_serpent) {
|
||||
|
||||
|
||||
|
||||
jeu = deplacement(pointeur, sens, retard, compteur, &acceleration, numsprite);
|
||||
|
||||
suivant = Microsecondes() + CYCLE - acceleration;
|
||||
suivant_serpent = Microsecondes() + CYCLE_SERPENT - acceleration;
|
||||
|
||||
printf("{%ld}", acceleration);
|
||||
printf("%u:%u\n", minutes, secondes);
|
||||
|
||||
|
||||
|
||||
@ -96,8 +108,27 @@ int main(void) {
|
||||
|
||||
}
|
||||
|
||||
if (Microsecondes () > suivant_timer) {
|
||||
|
||||
|
||||
secondes++;
|
||||
|
||||
suivant_timer = Microsecondes() + CYCLE_TIMER;
|
||||
|
||||
if (secondes == 60) {
|
||||
|
||||
secondes = 0;
|
||||
|
||||
minutes++;
|
||||
|
||||
|
||||
}
|
||||
affichage_timer(minutes,secondes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
LibererSprite(numsprite);
|
||||
|
||||
|
||||
@ -132,13 +163,14 @@ int main(void) {
|
||||
|
||||
free(pointeur);
|
||||
|
||||
free(compteur);
|
||||
|
||||
free(retard);
|
||||
free(retard);
|
||||
|
||||
|
||||
if (entrer == 1 ) {
|
||||
|
||||
ecran_fin(compteur, minutes, secondes);
|
||||
|
||||
}
|
||||
|
||||
FermerGraphique();
|
||||
|
||||
|
BIN
snake/pomme.png
BIN
snake/pomme.png
Binary file not shown.
Before ![]() (image error) Size: 1.4 KiB After ![]() (image error) Size: 1.5 KiB ![]() ![]() |
@ -10,23 +10,23 @@ short int* score_init(void) {
|
||||
|
||||
couleur white;
|
||||
|
||||
short int* compteur = NULL;
|
||||
char a[20];
|
||||
short int* compteur = NULL;
|
||||
char a[20];
|
||||
|
||||
|
||||
|
||||
|
||||
white = CouleurParComposante(255,255,255);
|
||||
ChoisirCouleurDessin(white);
|
||||
white = CouleurParComposante(255,255,255);
|
||||
ChoisirCouleurDessin(white);
|
||||
|
||||
compteur = malloc(sizeof(short int));
|
||||
*compteur = 0;
|
||||
compteur = malloc(sizeof(short int));
|
||||
*compteur = 0;
|
||||
|
||||
|
||||
sprintf(a, "%d", *compteur);
|
||||
sprintf(a, "%hd", *compteur);
|
||||
|
||||
EcrireTexte(1270, 600, a, 2);
|
||||
EcrireTexte(1310, 650, a, 2);
|
||||
|
||||
return compteur;
|
||||
return compteur;
|
||||
}
|
||||
|
||||
|
97
snake/time.c
97
snake/time.c
@ -1,97 +0,0 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <graph.h>
|
||||
|
||||
|
||||
#define CYCLE 1000000L
|
||||
|
||||
|
||||
int main(void) {
|
||||
|
||||
unsigned long suivant;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* int* time = NULL; */
|
||||
|
||||
/* time = malloc( sizeof(short int));
|
||||
|
||||
time[0] = 0;
|
||||
time[1] = 0; */
|
||||
|
||||
|
||||
suivant = Microsecondes() + CYCLE;
|
||||
|
||||
/*printf("%d : %d\n", &time[0],&time[1]);*/
|
||||
|
||||
while (1) {
|
||||
|
||||
if (Microsecondes() > suivant) {
|
||||
|
||||
|
||||
|
||||
/* une periode s'est écoulé */
|
||||
/* prochaine date */
|
||||
|
||||
suivant = Microsecondes()+CYCLE;
|
||||
|
||||
/*time[1]++;
|
||||
|
||||
if ( time[1] == 60) {
|
||||
|
||||
time[1] = 0;
|
||||
|
||||
time[0] ++;
|
||||
|
||||
}*/
|
||||
printf("%lu", Microsecondes());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* if ( ToucheEnAttente() == 1 ) {
|
||||
|
||||
if (Touche() == XK_space) {
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
}
|
10
snake/time.h
10
snake/time.h
@ -1,10 +0,0 @@
|
||||
|
||||
|
||||
|
||||
#ifndef TIME_H
|
||||
#define TIME_H
|
||||
|
||||
void time(void);
|
||||
|
||||
|
||||
#endif /* TIME_H */
|
Loading…
x
Reference in New Issue
Block a user