91 lines
2.4 KiB
C
91 lines
2.4 KiB
C
#include <graph.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "main.h"
|
|
|
|
|
|
void AfficherTimerEtScore(int m,int n,int score) /*Afficher le temps passé et le score*/
|
|
{
|
|
char buf[100];
|
|
char buff[100];
|
|
couleur j;
|
|
j=CouleurParNom("yellow");
|
|
ChoisirCouleurDessin(j);
|
|
|
|
ChoisirEcran(1);
|
|
CopierZone(2,1,0,0,930,710,0,0);
|
|
snprintf(buf,100,"temps : %02d:%02d",m,n);
|
|
snprintf(buff,100,"SCORE : %07d",score);
|
|
EcrireTexte(60,650,buf,2);
|
|
EcrireTexte(600,650,buff,2);
|
|
CopierZone(1,0,0,0,930,710,0,0);
|
|
}
|
|
|
|
|
|
void MangerPastille(int *serpent, int* pastilles, int longueur_serpent, int longueur_pastilles)
|
|
{
|
|
int i = 0;
|
|
|
|
for(i=0;i<longueur_pastilles;i+=2)
|
|
{
|
|
if(serpent[0] == pastilles[i] && serpent[1] == pastilles[i+1])
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void DeplacementSerpent(int direction ,int *serpent, int longueur)
|
|
{
|
|
int tempX = serpent[0];
|
|
int tempY = serpent[1];
|
|
int i;
|
|
couleur g;
|
|
couleur j;
|
|
ChoisirEcran(2);
|
|
j=CouleurParNom("yellow");
|
|
g=CouleurParNom("lightgreen");
|
|
|
|
ChoisirCouleurDessin(g);
|
|
RemplirRectangle(serpent[longueur-2],serpent[longueur-1],T_PIXEL,T_PIXEL);
|
|
|
|
for (i = 2; i < longueur; i += 2) {
|
|
int tempX2 = serpent[i];
|
|
int tempY2 = serpent[i + 1];
|
|
|
|
serpent[i] = tempX;
|
|
serpent[i + 1] = tempY;
|
|
|
|
tempX = tempX2;
|
|
tempY = tempY2;
|
|
}
|
|
|
|
ChoisirCouleurDessin(j);
|
|
if(direction == 0) /* Direction vers la gauche */
|
|
{
|
|
printf("Gauche %d\n",direction);
|
|
serpent[0]-=T_PIXEL;
|
|
|
|
RemplirRectangle(serpent[0],serpent[1],T_PIXEL,T_PIXEL);
|
|
printf("Longueur = %d | x %d | y %d",longueur,serpent[longueur-1],serpent[longueur-2]);
|
|
}
|
|
else if(direction == 1) /* Direction vers le haut */
|
|
{
|
|
printf("Haut %d\n",direction);
|
|
serpent[1]-=T_PIXEL;
|
|
RemplirRectangle(serpent[0],serpent[1],T_PIXEL,T_PIXEL);
|
|
}
|
|
else if(direction == 2) /* Direction vers la droite */
|
|
{
|
|
printf("Droite %d\n",direction);
|
|
serpent[0]+=T_PIXEL;
|
|
RemplirRectangle(serpent[0],serpent[1],T_PIXEL,T_PIXEL);
|
|
}
|
|
else if(direction == 3) /* Direction vers le bas */
|
|
{
|
|
printf("Bas %d\n",direction);
|
|
serpent[1]+=T_PIXEL;
|
|
RemplirRectangle(serpent[0],serpent[1],T_PIXEL,T_PIXEL);
|
|
}
|
|
} |