correction de l'affichage du menu de fin
This commit is contained in:
parent
9b5560c17d
commit
afbde8d4c9
@ -29,17 +29,11 @@ void AfficheTab(int tab[H][L], int posx, int posy, int i, int j){
|
||||
RemplirArc(posx+5,posy+5,10,10,360,360);
|
||||
}
|
||||
if(tab[i][j]==30){
|
||||
c=CouleurParNom("black");
|
||||
ChoisirCouleurDessin(c);
|
||||
RemplirRectangle(posx,posy,20,20);
|
||||
c=CouleurParNom("red");
|
||||
ChoisirCouleurDessin(c);
|
||||
RemplirArc(posx,posy,20,20,360,360);
|
||||
}
|
||||
if(tab[i][j]==50){
|
||||
c=CouleurParNom("black");
|
||||
ChoisirCouleurDessin(c);
|
||||
RemplirRectangle(posx,posy,20,20);
|
||||
if(tab[i][j]==50){
|
||||
c=CouleurParNom("purple");
|
||||
ChoisirCouleurDessin(c);
|
||||
RemplirArc(posx,posy,20,20,360,360);
|
||||
|
@ -49,19 +49,6 @@ int VerifChemin(int tab[H][L], int x, int y){
|
||||
}
|
||||
}
|
||||
|
||||
/*Verification sir le joueuer a gagner ou perdu*/
|
||||
int Gagne(int tab[H][L]){
|
||||
int i,j;
|
||||
for(i=0;i<=H;i++){
|
||||
for(j=0;j<=L;j++){
|
||||
if(tab[i][j]==0||tab[i][j]==30||tab[i][j]==30){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*regarde la case ou la queue est pour savoir ou elle va aller ensuite*/
|
||||
int VoirCase(int tab[H][L],int x, int y,int defaut){
|
||||
if(tab[x][y]==9){
|
||||
|
@ -15,6 +15,5 @@ int Semage(int tab[H][L], int direction, int sxmax, int symax, int *pause, int *
|
||||
unsigned long TempsArret(int *temoin);
|
||||
int VerifChemin(int tab[H][L], int x, int y);
|
||||
int VoirCase(int tab[H][L], int x, int y, int defaut);
|
||||
int Gagne(int tab[H][L]);
|
||||
|
||||
#endif // CHEMIN_H
|
||||
|
@ -2,9 +2,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <graph.h>
|
||||
#include "Chemin.h"
|
||||
#include "Afficher.h"
|
||||
#include "ModifTab.h"
|
||||
|
||||
/*verifie les touches cliquée par le joueur*/
|
||||
int CliqueTouche(int defaut,int* pause,int* fin){
|
||||
@ -32,12 +29,11 @@ int CliqueTouche(int defaut,int* pause,int* fin){
|
||||
case XK_space:
|
||||
if(*pause==1){
|
||||
*pause=0;
|
||||
return defaut;
|
||||
}
|
||||
else if(*pause==0){
|
||||
*pause=1;
|
||||
return defaut;
|
||||
}
|
||||
return defaut;
|
||||
case XK_Escape:
|
||||
*fin=1;
|
||||
return defaut;
|
||||
@ -47,29 +43,7 @@ int CliqueTouche(int defaut,int* pause,int* fin){
|
||||
}
|
||||
|
||||
/*deplacement de la queue du serpent en fonction de la trace laissée par la tete*/
|
||||
void DeplacementQueue(int tab[H][L],int* sxmin,int* symin,int* direc, int menu){
|
||||
if(menu==3){
|
||||
if(*direc==0){
|
||||
*sxmin=*sxmin+1;
|
||||
*direc=VoirCase(tab,*sxmin,*symin,*direc);
|
||||
tab[*sxmin][*symin]=40;
|
||||
}
|
||||
else if(*direc==1){
|
||||
*symin=*symin-1;
|
||||
*direc=VoirCase(tab,*sxmin,*symin,*direc);
|
||||
tab[*sxmin][*symin]=40;
|
||||
}
|
||||
else if(*direc==2){
|
||||
*sxmin=*sxmin-1;
|
||||
*direc=VoirCase(tab,*sxmin,*symin,*direc);
|
||||
tab[*sxmin][*symin]=40;
|
||||
}
|
||||
else if(*direc==3){
|
||||
*symin=*symin+1;
|
||||
*direc=VoirCase(tab,*sxmin,*symin,*direc);
|
||||
tab[*sxmin][*symin]=40;
|
||||
}
|
||||
}else{
|
||||
void DeplacementQueue(int tab[H][L],int* sxmin,int* symin,int* direc){
|
||||
if(*direc==0){
|
||||
*sxmin=*sxmin+1;
|
||||
*direc=VoirCase(tab,*sxmin,*symin,*direc);
|
||||
@ -90,13 +64,11 @@ void DeplacementQueue(int tab[H][L],int* sxmin,int* symin,int* direc, int menu){
|
||||
*direc=VoirCase(tab,*sxmin,*symin,*direc);
|
||||
tab[*sxmin][*symin]=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*Deplacement de la tete du seroent en fonction de la direction*/
|
||||
void DeplacementTete(int tab[H][L],int* sxmax,int* symax,int direction,int* temoin,int* fin,int* point,int mode){
|
||||
if(mode==1){
|
||||
if(direction==2){
|
||||
void DeplacementTete(int tab[H][L],int* sxmax,int* symax,int direction,int* temoin,int* fin,int* point){
|
||||
if(direction==2){
|
||||
if(VerifChemin(tab,*sxmax-1,*symax)==1){
|
||||
*sxmax=*sxmax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
@ -180,177 +152,5 @@ void DeplacementTete(int tab[H][L],int* sxmax,int* symax,int direction,int* temo
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
}/*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa*/
|
||||
}if(mode==2){
|
||||
if(direction==2){
|
||||
if(VerifChemin(tab,*sxmax-1,*symax)==1){
|
||||
*sxmax=*sxmax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}else if(VerifChemin(tab,*sxmax-1,*symax)==3){
|
||||
*sxmax=*sxmax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax-1,*symax)==2){
|
||||
*sxmax=*sxmax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
Pastille(tab,5,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
}
|
||||
/*droite*/
|
||||
if(direction==3){
|
||||
if(VerifChemin(tab,*sxmax,*symax+1)==1){
|
||||
*symax=*symax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}else if(VerifChemin(tab,*sxmax,*symax+1)==3){
|
||||
*symax=*symax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax,*symax+1)==2){
|
||||
*symax=*symax+1;
|
||||
tab[*sxmax][*symax]=1;;
|
||||
Pastille(tab,5,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
}
|
||||
/*gauche*/
|
||||
if(direction==1){
|
||||
if(VerifChemin(tab,*sxmax,*symax-1)==1){
|
||||
*symax=*symax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}
|
||||
else if(VerifChemin(tab,*sxmax,*symax-1)==3){
|
||||
*symax=*symax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax,*symax-1)==2){
|
||||
*symax=*symax-1;
|
||||
tab[*sxmax][*symax]=1;;
|
||||
Pastille(tab,5,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
}
|
||||
/*bas*/
|
||||
if(direction==0){
|
||||
if(VerifChemin(tab,*sxmax+1,*symax)==1){
|
||||
*sxmax=*sxmax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}
|
||||
else if(VerifChemin(tab,*sxmax+1,*symax)==3){
|
||||
*sxmax=*sxmax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax+1,*symax)==2){
|
||||
*sxmax=*sxmax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
Pastille(tab,5,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
/*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa*/
|
||||
}}if(mode==3){
|
||||
if(direction==2){
|
||||
if(VerifChemin(tab,*sxmax-1,*symax)==1){
|
||||
*sxmax=*sxmax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}else if(VerifChemin(tab,*sxmax-1,*symax)==3){
|
||||
*sxmax=*sxmax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax-1,*symax)==2){
|
||||
*sxmax=*sxmax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
Pastille(tab,20,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
}
|
||||
/*droite*/
|
||||
if(direction==3){
|
||||
if(VerifChemin(tab,*sxmax,*symax+1)==1){
|
||||
*symax=*symax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}else if(VerifChemin(tab,*sxmax,*symax+1)==3){
|
||||
*symax=*symax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax,*symax+1)==2){
|
||||
*symax=*symax+1;
|
||||
tab[*sxmax][*symax]=1;;
|
||||
Pastille(tab,20,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
}
|
||||
/*gauche*/
|
||||
if(direction==1){
|
||||
if(VerifChemin(tab,*sxmax,*symax-1)==1){
|
||||
*symax=*symax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}
|
||||
else if(VerifChemin(tab,*sxmax,*symax-1)==3){
|
||||
*symax=*symax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax,*symax-1)==2){
|
||||
*symax=*symax-1;
|
||||
tab[*sxmax][*symax]=1;;
|
||||
Pastille(tab,20,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
}
|
||||
/*bas*/
|
||||
if(direction==0){
|
||||
if(VerifChemin(tab,*sxmax+1,*symax)==1){
|
||||
*sxmax=*sxmax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}
|
||||
else if(VerifChemin(tab,*sxmax+1,*symax)==3){
|
||||
*sxmax=*sxmax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax+1,*symax)==2){
|
||||
*sxmax=*sxmax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
Pastille(tab,20,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
#define L 62
|
||||
|
||||
int CliqueTouche(int defaut, int *pause, int *fin);
|
||||
void DeplacementQueue(int tab[H][L], int *sxmin, int *symin, int *direc,int);
|
||||
void DeplacementTete(int tab[H][L], int *sxmax, int *symax, int direction, int *temoin, int *fin, int *point,int menu);
|
||||
void DeplacementQueue(int tab[H][L], int *sxmin, int *symin, int *direc);
|
||||
void DeplacementTete(int tab[H][L], int *sxmax, int *symax, int direction, int *temoin, int *fin, int *point);
|
||||
|
||||
#endif // DEPLACEMENT_H
|
||||
|
@ -5,7 +5,10 @@
|
||||
#include <graph.h>
|
||||
|
||||
/*initialisation du plateau de jeu*/
|
||||
void init(int tab[H][L], int mode){
|
||||
void init(int tab[H][L]){
|
||||
/*creation de la page*/
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(10,10,1700,1000);
|
||||
int i,j;
|
||||
couleur c;
|
||||
c=CouleurParNom("dark blue");
|
||||
@ -13,7 +16,7 @@ void init(int tab[H][L], int mode){
|
||||
RemplirRectangle(0,0,1700,1000);
|
||||
DessinerScore(0);
|
||||
DessinerTimer(0);
|
||||
/*initialisation de la grille a 0(noir)*/
|
||||
/*initialisation de la grille a 0(vert)*/
|
||||
for(i=1;i<H;i++){
|
||||
for(j=1;j<L;j++){
|
||||
tab[i][j]=0;
|
||||
@ -21,36 +24,26 @@ void init(int tab[H][L], int mode){
|
||||
}
|
||||
|
||||
/*initialisation bordure*/
|
||||
if(mode==2){
|
||||
for(i=0;i<=H;i++){
|
||||
tab[i][L]=0;
|
||||
tab[i][0]=0;
|
||||
}
|
||||
}
|
||||
else{
|
||||
for(i=0;i<=H;i++){
|
||||
tab[i][L]=40;
|
||||
tab[i][0]=40;
|
||||
}
|
||||
}
|
||||
for(i=0;i<=L;i++){
|
||||
tab[H][i]=40;
|
||||
tab[0][i]=40;
|
||||
}
|
||||
|
||||
/*initialisation du serpent*/
|
||||
tab[18][30]=0;
|
||||
tab[18][30]=0;
|
||||
tab[27][30]=1;
|
||||
tab[2][2]=0;
|
||||
tab[11][2]=1;
|
||||
tab[11][2]=1;
|
||||
|
||||
for(i=18;i<28;i++){
|
||||
tab[i][30]=1;
|
||||
for(i=2;i<11;i++){
|
||||
tab[i][2]=1;
|
||||
}
|
||||
/*Initalisation des differences pastilles*/
|
||||
if(mode==3||mode==2){
|
||||
Pastille(tab,2,2);
|
||||
}
|
||||
Pastille(tab,5,1);
|
||||
Pastille(tab,2,2);
|
||||
}
|
||||
|
||||
/*Mise en place de pastilles le plateau de jeu
|
||||
|
@ -10,6 +10,6 @@
|
||||
#define L 62
|
||||
|
||||
int Pastille(int tab[H][L], int nb_de_pastilles, int type_pastille);
|
||||
void init(int tab[H][L],int);
|
||||
void init(int tab[H][L]);
|
||||
|
||||
#endif // MODIFTAB_H
|
||||
|
23
Snake/main.c
23
Snake/main.c
@ -7,15 +7,14 @@
|
||||
#include "ModifTab.h"
|
||||
#include "Deplacement.h"
|
||||
#include "Chemin.h"
|
||||
#include "Menu.h"
|
||||
|
||||
#define DELTA 1000000L;
|
||||
#define DELTO 1000L
|
||||
#define DELTI 900000L
|
||||
|
||||
int main(void) {
|
||||
int tab[H][L], direction = 0, temoin = 0, direc = 0, pause = 1,mode=0;
|
||||
int sxmin = 17, symin = 30, sxmax = 27, symax = 30, fin = 0, point = 0, Compteur_Temps = 0;
|
||||
int tab[H][L], direction = 0, temoin = 0, direc = 0, pause = 1;
|
||||
int sxmin = 1, symin = 2, sxmax = 11, symax = 2, fin = 0, point = 0, Compteur_Temps = 0;
|
||||
int *pointeur_pause = &pause;
|
||||
int *pointeur_sxmin = &sxmin;
|
||||
int *pointeur_symin = &symin;
|
||||
@ -28,12 +27,9 @@ int main(void) {
|
||||
unsigned long suivant = Microsecondes() + DELTA;
|
||||
unsigned long suivant2 = Microsecondes() + DELTO;
|
||||
unsigned long suivant3 = Microsecondes() + DELTO;
|
||||
InitEcran();
|
||||
mode=MenuDebut();
|
||||
init(tab,mode);
|
||||
init(tab);
|
||||
|
||||
while (1) {
|
||||
if(fin!=1){
|
||||
Affiche(tab);
|
||||
if (ToucheEnAttente() == 1) {
|
||||
direction = Semage(tab, direction, sxmax, symax, pointeur_pause, pointeur_fin);
|
||||
@ -45,21 +41,16 @@ int main(void) {
|
||||
suivant = Microsecondes() + DELTA;
|
||||
}
|
||||
if (Microsecondes() > suivant3) {
|
||||
DeplacementQueue(tab, pointeur_sxmin, pointeur_symin, pointeur_direc,mode);
|
||||
DeplacementQueue(tab, pointeur_sxmin, pointeur_symin, pointeur_direc);
|
||||
suivant3 = TempsArret(pointeur_temoin);
|
||||
}
|
||||
if (Microsecondes() > suivant2) {
|
||||
DeplacementTete(tab, pointeur_sxmax, pointeur_symax, direction, pointeur_temoin, pointeur_fin, pointeur_point,mode);
|
||||
DeplacementTete(tab, pointeur_sxmax, pointeur_symax, direction, pointeur_temoin, pointeur_fin, pointeur_point);
|
||||
suivant2 = Microsecondes() + DELTO;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (fin == 1) {
|
||||
if(Gagne(tab)==0){
|
||||
MenuFinGagne();
|
||||
}else{
|
||||
MenuFinPerdu();
|
||||
}
|
||||
if (fin == 1) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,14 @@
|
||||
exec : Chemin.o Deplacement.o Afficher.o ModifTab.o main.o Menu.o
|
||||
gcc -ansi -o exec Chemin.o Deplacement.o Afficher.o ModifTab.o main.o Menu.o -lgraph
|
||||
run : exec
|
||||
exec : ModifTab.o Afficher.o Chemin.o Deplacement.o main.o
|
||||
gcc -o exec ModifTab.o Afficher.o Chemin.o Deplacement.o main.o -lgraph
|
||||
run : exec
|
||||
./exec
|
||||
ModifTab.o : ModifTab.c
|
||||
gcc -c ModifTab.c -lgraph
|
||||
Afficher.o : Afficher.c
|
||||
gcc -c Afficher.c -lgraph
|
||||
Chemin.o : Chemin.c
|
||||
gcc -c Chemin.c -lgraph
|
||||
Deplacement.o : Deplacement.c
|
||||
gcc -c Deplacement.c -lgraph
|
||||
Afficher.o : Afficher.c
|
||||
gcc -c Afficher.c -lgraph
|
||||
ModifTab.o : ModifTab.c
|
||||
gcc -c ModifTab.c -lgraph
|
||||
main.o : main.c
|
||||
gcc -c main.c -lgraph
|
||||
Menu.o : Menu.c
|
||||
gcc -c Menu.c -lgraph
|
||||
clean :
|
||||
rm -f *~
|
||||
rm -f *.o
|
||||
rm exec
|
||||
|
89
Snake_ancien/Afficher.c
Normal file
89
Snake_ancien/Afficher.c
Normal file
@ -0,0 +1,89 @@
|
||||
#include "Afficher.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <graph.h>
|
||||
|
||||
/*affichage du plateau de jeu en fonction du tableau*/
|
||||
void AfficheTab(int tab[H][L], int posx, int posy, int i, int j){
|
||||
couleur c;
|
||||
if(tab[i][j]==0){
|
||||
c=CouleurParNom("black");
|
||||
ChoisirCouleurDessin(c);
|
||||
RemplirRectangle(posx,posy,20,20);
|
||||
}
|
||||
|
||||
if(tab[i][j]==40){
|
||||
c=CouleurParNom("dark grey");
|
||||
ChoisirCouleurDessin(c);
|
||||
RemplirRectangle(posx,posy,20,20);
|
||||
c=CouleurParNom("black");
|
||||
ChoisirCouleurDessin(c);
|
||||
DessinerRectangle(posx+2,posy+2,16,16);
|
||||
}
|
||||
if(tab[i][j]==1||tab[i][j]==9||tab[i][j]==7||tab[i][j]==8||tab[i][j]==6){
|
||||
c=CouleurParNom("dark orange");
|
||||
ChoisirCouleurDessin(c);
|
||||
RemplirRectangle(posx,posy,20,20);
|
||||
c=CouleurParNom("brown");
|
||||
ChoisirCouleurDessin(c);
|
||||
RemplirArc(posx+5,posy+5,10,10,360,360);
|
||||
}
|
||||
if(tab[i][j]==30){
|
||||
c=CouleurParNom("black");
|
||||
ChoisirCouleurDessin(c);
|
||||
RemplirRectangle(posx,posy,20,20);
|
||||
c=CouleurParNom("red");
|
||||
ChoisirCouleurDessin(c);
|
||||
RemplirArc(posx,posy,20,20,360,360);
|
||||
}
|
||||
if(tab[i][j]==50){
|
||||
c=CouleurParNom("black");
|
||||
ChoisirCouleurDessin(c);
|
||||
RemplirRectangle(posx,posy,20,20);
|
||||
c=CouleurParNom("purple");
|
||||
ChoisirCouleurDessin(c);
|
||||
RemplirArc(posx,posy,20,20,360,360);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*parcours du tableau pour rendu graphique*/
|
||||
void Affiche(int tab[H][L]){
|
||||
int i,j,posx=0,posy=0;
|
||||
for(i=0;i<=H;i++){
|
||||
for(j=0;j<=L;j++){
|
||||
AfficheTab(tab, posx, posy, i, j);
|
||||
posx=posx+20;
|
||||
}
|
||||
posx=0;
|
||||
posy=posy+20;
|
||||
}
|
||||
posx=0;
|
||||
posy=0;
|
||||
}
|
||||
|
||||
/*affichage du score*/
|
||||
void DessinerScore(int n){
|
||||
couleur c;
|
||||
char buf[100];
|
||||
c=CouleurParNom("dark blue");
|
||||
ChoisirCouleurDessin(c);
|
||||
RemplirRectangle(200,875,200,100);
|
||||
c=CouleurParNom("yellow");
|
||||
ChoisirCouleurDessin(c);
|
||||
snprintf(buf,100,"score : %d",n);
|
||||
EcrireTexte(250,900,buf,2);
|
||||
}
|
||||
|
||||
/*affichage du timer*/
|
||||
void DessinerTimer(int n){
|
||||
couleur c;
|
||||
char buf[100];
|
||||
c=CouleurParNom("dark blue");
|
||||
ChoisirCouleurDessin(c);
|
||||
RemplirRectangle(0,875,200,100);
|
||||
c=CouleurParNom("red");
|
||||
ChoisirCouleurDessin(c);
|
||||
snprintf(buf,100,"time : %d",n);
|
||||
EcrireTexte(50,900,buf,2);
|
||||
}
|
17
Snake_ancien/Afficher.h
Normal file
17
Snake_ancien/Afficher.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef AFFICHER_H
|
||||
#define AFFICHER_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <graph.h>
|
||||
#include <time.h>
|
||||
|
||||
#define H 42
|
||||
#define L 62
|
||||
|
||||
void AfficheTab(int tab[H][L], int posx, int posy, int i, int j);
|
||||
void Affiche(int tab[H][L]);
|
||||
void DessinerScore(int n);
|
||||
void DessinerTimer(int n);
|
||||
|
||||
#endif // AFFICHER_H
|
BIN
Snake_ancien/Afficher.o
Normal file
BIN
Snake_ancien/Afficher.o
Normal file
Binary file not shown.
82
Snake_ancien/Chemin.c
Normal file
82
Snake_ancien/Chemin.c
Normal file
@ -0,0 +1,82 @@
|
||||
#include "Chemin.h"
|
||||
#include "Deplacement.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <graph.h>
|
||||
|
||||
/*seme les angles pour dire a la queue où aller*/
|
||||
int Semage(int tab[H][L],int direction,int sxmax,int symax,int* pause,int* fin){
|
||||
int newdirec;
|
||||
newdirec=CliqueTouche(direction,pause,fin);
|
||||
if(newdirec!=direction){
|
||||
if(newdirec==0){
|
||||
tab[sxmax][symax]=6;
|
||||
}
|
||||
if(newdirec==1){
|
||||
tab[sxmax][symax]=7;
|
||||
}
|
||||
if(newdirec==2){
|
||||
tab[sxmax][symax]=8;
|
||||
}
|
||||
if(newdirec==3){
|
||||
tab[sxmax][symax]=9;
|
||||
}
|
||||
direction=newdirec;
|
||||
return direction;
|
||||
}
|
||||
}
|
||||
|
||||
/*arrete la queue le temps que la tete avance un peu pour permettre au serpent de grandir*/
|
||||
unsigned long TempsArret(int* temoin){
|
||||
if(*temoin==1){
|
||||
*temoin=0;
|
||||
return Microsecondes()+DELTI;
|
||||
}else if(*temoin==0){
|
||||
return Microsecondes()+DELTO;
|
||||
}
|
||||
}
|
||||
|
||||
/*verification de la case ou on va aller*/
|
||||
int VerifChemin(int tab[H][L], int x, int y){
|
||||
if(tab[x][y]==0){
|
||||
return 1;
|
||||
}else if(tab[x][y]==30){
|
||||
return 3;
|
||||
}else if(tab[x][y]==50){
|
||||
return 2;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*Verification sir le joueuer a gagner ou perdu*/
|
||||
int Gagne(int tab[H][L]){
|
||||
int i,j;
|
||||
for(i=0;i<=H;i++){
|
||||
for(j=0;j<=L;j++){
|
||||
if(tab[i][j]==0||tab[i][j]==30||tab[i][j]==30){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*regarde la case ou la queue est pour savoir ou elle va aller ensuite*/
|
||||
int VoirCase(int tab[H][L],int x, int y,int defaut){
|
||||
if(tab[x][y]==9){
|
||||
return 3;
|
||||
}
|
||||
else if(tab[x][y]==8){
|
||||
return 2;
|
||||
}
|
||||
else if(tab[x][y]==7){
|
||||
return 1;
|
||||
}
|
||||
else if(tab[x][y]==6){
|
||||
return 0;
|
||||
}
|
||||
else{
|
||||
return defaut;
|
||||
}
|
||||
}
|
20
Snake_ancien/Chemin.h
Normal file
20
Snake_ancien/Chemin.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef CHEMIN_H
|
||||
#define CHEMIN_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <graph.h>
|
||||
#include <time.h>
|
||||
|
||||
#define H 42
|
||||
#define L 62
|
||||
#define DELTO 1000L
|
||||
#define DELTI 900000L
|
||||
|
||||
int Semage(int tab[H][L], int direction, int sxmax, int symax, int *pause, int *fin);
|
||||
unsigned long TempsArret(int *temoin);
|
||||
int VerifChemin(int tab[H][L], int x, int y);
|
||||
int VoirCase(int tab[H][L], int x, int y, int defaut);
|
||||
int Gagne(int tab[H][L]);
|
||||
|
||||
#endif // CHEMIN_H
|
BIN
Snake_ancien/Chemin.o
Normal file
BIN
Snake_ancien/Chemin.o
Normal file
Binary file not shown.
356
Snake_ancien/Deplacement.c
Normal file
356
Snake_ancien/Deplacement.c
Normal file
@ -0,0 +1,356 @@
|
||||
#include "Deplacement.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <graph.h>
|
||||
#include "Chemin.h"
|
||||
#include "Afficher.h"
|
||||
#include "ModifTab.h"
|
||||
|
||||
/*verifie les touches cliquée par le joueur*/
|
||||
int CliqueTouche(int defaut,int* pause,int* fin){
|
||||
switch(Touche()){
|
||||
case XK_Up:
|
||||
if(defaut!=0){
|
||||
defaut=2;
|
||||
return defaut;
|
||||
}
|
||||
case XK_Down:
|
||||
if(defaut!=2){
|
||||
defaut=0;
|
||||
return defaut;
|
||||
}
|
||||
case XK_Right:
|
||||
if(defaut!=1){
|
||||
defaut=3;
|
||||
return defaut;
|
||||
}
|
||||
case XK_Left:
|
||||
if(defaut!=3){
|
||||
defaut=1;
|
||||
return defaut;
|
||||
}
|
||||
case XK_space:
|
||||
if(*pause==1){
|
||||
*pause=0;
|
||||
return defaut;
|
||||
}
|
||||
else if(*pause==0){
|
||||
*pause=1;
|
||||
return defaut;
|
||||
}
|
||||
case XK_Escape:
|
||||
*fin=1;
|
||||
return defaut;
|
||||
default :
|
||||
return defaut;
|
||||
}
|
||||
}
|
||||
|
||||
/*deplacement de la queue du serpent en fonction de la trace laissée par la tete*/
|
||||
void DeplacementQueue(int tab[H][L],int* sxmin,int* symin,int* direc, int menu){
|
||||
if(menu==3){
|
||||
if(*direc==0){
|
||||
*sxmin=*sxmin+1;
|
||||
*direc=VoirCase(tab,*sxmin,*symin,*direc);
|
||||
tab[*sxmin][*symin]=40;
|
||||
}
|
||||
else if(*direc==1){
|
||||
*symin=*symin-1;
|
||||
*direc=VoirCase(tab,*sxmin,*symin,*direc);
|
||||
tab[*sxmin][*symin]=40;
|
||||
}
|
||||
else if(*direc==2){
|
||||
*sxmin=*sxmin-1;
|
||||
*direc=VoirCase(tab,*sxmin,*symin,*direc);
|
||||
tab[*sxmin][*symin]=40;
|
||||
}
|
||||
else if(*direc==3){
|
||||
*symin=*symin+1;
|
||||
*direc=VoirCase(tab,*sxmin,*symin,*direc);
|
||||
tab[*sxmin][*symin]=40;
|
||||
}
|
||||
}else{
|
||||
if(*direc==0){
|
||||
*sxmin=*sxmin+1;
|
||||
*direc=VoirCase(tab,*sxmin,*symin,*direc);
|
||||
tab[*sxmin][*symin]=0;
|
||||
}
|
||||
else if(*direc==1){
|
||||
*symin=*symin-1;
|
||||
*direc=VoirCase(tab,*sxmin,*symin,*direc);
|
||||
tab[*sxmin][*symin]=0;
|
||||
}
|
||||
else if(*direc==2){
|
||||
*sxmin=*sxmin-1;
|
||||
*direc=VoirCase(tab,*sxmin,*symin,*direc);
|
||||
tab[*sxmin][*symin]=0;
|
||||
}
|
||||
else if(*direc==3){
|
||||
*symin=*symin+1;
|
||||
*direc=VoirCase(tab,*sxmin,*symin,*direc);
|
||||
tab[*sxmin][*symin]=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*Deplacement de la tete du seroent en fonction de la direction*/
|
||||
void DeplacementTete(int tab[H][L],int* sxmax,int* symax,int direction,int* temoin,int* fin,int* point,int mode){
|
||||
if(mode==1){
|
||||
if(direction==2){
|
||||
if(VerifChemin(tab,*sxmax-1,*symax)==1){
|
||||
*sxmax=*sxmax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}else if(VerifChemin(tab,*sxmax-1,*symax)==3){
|
||||
*sxmax=*sxmax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax-1,*symax)==2){
|
||||
*sxmax=*sxmax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
Pastille(tab,5,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
}
|
||||
/*droite*/
|
||||
if(direction==3){
|
||||
if(VerifChemin(tab,*sxmax,*symax+1)==1){
|
||||
*symax=*symax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}else if(VerifChemin(tab,*sxmax,*symax+1)==3){
|
||||
*symax=*symax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax,*symax+1)==2){
|
||||
*symax=*symax+1;
|
||||
tab[*sxmax][*symax]=1;;
|
||||
Pastille(tab,5,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
}
|
||||
/*gauche*/
|
||||
if(direction==1){
|
||||
if(VerifChemin(tab,*sxmax,*symax-1)==1){
|
||||
*symax=*symax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}
|
||||
else if(VerifChemin(tab,*sxmax,*symax-1)==3){
|
||||
*symax=*symax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax,*symax-1)==2){
|
||||
*symax=*symax-1;
|
||||
tab[*sxmax][*symax]=1;;
|
||||
Pastille(tab,5,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
}
|
||||
/*bas*/
|
||||
if(direction==0){
|
||||
if(VerifChemin(tab,*sxmax+1,*symax)==1){
|
||||
*sxmax=*sxmax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}
|
||||
else if(VerifChemin(tab,*sxmax+1,*symax)==3){
|
||||
*sxmax=*sxmax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax+1,*symax)==2){
|
||||
*sxmax=*sxmax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
Pastille(tab,5,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
}/*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa*/
|
||||
}if(mode==2){
|
||||
if(direction==2){
|
||||
if(VerifChemin(tab,*sxmax-1,*symax)==1){
|
||||
*sxmax=*sxmax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}else if(VerifChemin(tab,*sxmax-1,*symax)==3){
|
||||
*sxmax=*sxmax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax-1,*symax)==2){
|
||||
*sxmax=*sxmax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
Pastille(tab,5,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
}
|
||||
/*droite*/
|
||||
if(direction==3){
|
||||
if(VerifChemin(tab,*sxmax,*symax+1)==1){
|
||||
*symax=*symax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}else if(VerifChemin(tab,*sxmax,*symax+1)==3){
|
||||
*symax=*symax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax,*symax+1)==2){
|
||||
*symax=*symax+1;
|
||||
tab[*sxmax][*symax]=1;;
|
||||
Pastille(tab,5,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
}
|
||||
/*gauche*/
|
||||
if(direction==1){
|
||||
if(VerifChemin(tab,*sxmax,*symax-1)==1){
|
||||
*symax=*symax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}
|
||||
else if(VerifChemin(tab,*sxmax,*symax-1)==3){
|
||||
*symax=*symax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax,*symax-1)==2){
|
||||
*symax=*symax-1;
|
||||
tab[*sxmax][*symax]=1;;
|
||||
Pastille(tab,5,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
}
|
||||
/*bas*/
|
||||
if(direction==0){
|
||||
if(VerifChemin(tab,*sxmax+1,*symax)==1){
|
||||
*sxmax=*sxmax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}
|
||||
else if(VerifChemin(tab,*sxmax+1,*symax)==3){
|
||||
*sxmax=*sxmax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax+1,*symax)==2){
|
||||
*sxmax=*sxmax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
Pastille(tab,5,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
/*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa*/
|
||||
}}if(mode==3){
|
||||
if(direction==2){
|
||||
if(VerifChemin(tab,*sxmax-1,*symax)==1){
|
||||
*sxmax=*sxmax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}else if(VerifChemin(tab,*sxmax-1,*symax)==3){
|
||||
*sxmax=*sxmax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax-1,*symax)==2){
|
||||
*sxmax=*sxmax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
Pastille(tab,20,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
}
|
||||
/*droite*/
|
||||
if(direction==3){
|
||||
if(VerifChemin(tab,*sxmax,*symax+1)==1){
|
||||
*symax=*symax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}else if(VerifChemin(tab,*sxmax,*symax+1)==3){
|
||||
*symax=*symax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax,*symax+1)==2){
|
||||
*symax=*symax+1;
|
||||
tab[*sxmax][*symax]=1;;
|
||||
Pastille(tab,20,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
}
|
||||
/*gauche*/
|
||||
if(direction==1){
|
||||
if(VerifChemin(tab,*sxmax,*symax-1)==1){
|
||||
*symax=*symax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}
|
||||
else if(VerifChemin(tab,*sxmax,*symax-1)==3){
|
||||
*symax=*symax-1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax,*symax-1)==2){
|
||||
*symax=*symax-1;
|
||||
tab[*sxmax][*symax]=1;;
|
||||
Pastille(tab,20,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
}
|
||||
/*bas*/
|
||||
if(direction==0){
|
||||
if(VerifChemin(tab,*sxmax+1,*symax)==1){
|
||||
*sxmax=*sxmax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
}
|
||||
else if(VerifChemin(tab,*sxmax+1,*symax)==3){
|
||||
*sxmax=*sxmax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
*point=*point+5;
|
||||
DessinerScore(*point);
|
||||
Pastille(tab,1,1);
|
||||
*temoin=1;
|
||||
}else if(VerifChemin(tab,*sxmax+1,*symax)==2){
|
||||
*sxmax=*sxmax+1;
|
||||
tab[*sxmax][*symax]=1;
|
||||
Pastille(tab,20,3);
|
||||
Pastille(tab,1,2);
|
||||
}else{
|
||||
*fin=1;
|
||||
}
|
||||
}}
|
||||
}
|
16
Snake_ancien/Deplacement.h
Normal file
16
Snake_ancien/Deplacement.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef DEPLACEMENT_H
|
||||
#define DEPLACEMENT_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <graph.h>
|
||||
#include <time.h>
|
||||
|
||||
#define H 42
|
||||
#define L 62
|
||||
|
||||
int CliqueTouche(int defaut, int *pause, int *fin);
|
||||
void DeplacementQueue(int tab[H][L], int *sxmin, int *symin, int *direc,int);
|
||||
void DeplacementTete(int tab[H][L], int *sxmax, int *symax, int direction, int *temoin, int *fin, int *point,int menu);
|
||||
|
||||
#endif // DEPLACEMENT_H
|
BIN
Snake_ancien/Deplacement.o
Normal file
BIN
Snake_ancien/Deplacement.o
Normal file
Binary file not shown.
BIN
Snake_ancien/Menu.o
Normal file
BIN
Snake_ancien/Menu.o
Normal file
Binary file not shown.
81
Snake_ancien/ModifTab.c
Normal file
81
Snake_ancien/ModifTab.c
Normal file
@ -0,0 +1,81 @@
|
||||
#include "ModifTab.h"
|
||||
#include "Afficher.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <graph.h>
|
||||
|
||||
/*initialisation du plateau de jeu*/
|
||||
void init(int tab[H][L], int mode){
|
||||
int i,j;
|
||||
couleur c;
|
||||
c=CouleurParNom("dark blue");
|
||||
ChoisirCouleurDessin(c);
|
||||
RemplirRectangle(0,0,1700,1000);
|
||||
DessinerScore(0);
|
||||
DessinerTimer(0);
|
||||
/*initialisation de la grille a 0(noir)*/
|
||||
for(i=1;i<H;i++){
|
||||
for(j=1;j<L;j++){
|
||||
tab[i][j]=0;
|
||||
}
|
||||
}
|
||||
|
||||
/*initialisation bordure*/
|
||||
if(mode==2){
|
||||
for(i=0;i<=H;i++){
|
||||
tab[i][L]=0;
|
||||
tab[i][0]=0;
|
||||
}
|
||||
}
|
||||
else{
|
||||
for(i=0;i<=H;i++){
|
||||
tab[i][L]=40;
|
||||
tab[i][0]=40;
|
||||
}
|
||||
}
|
||||
for(i=0;i<=L;i++){
|
||||
tab[H][i]=40;
|
||||
tab[0][i]=40;
|
||||
}
|
||||
|
||||
/*initialisation du serpent*/
|
||||
tab[18][30]=0;
|
||||
tab[18][30]=0;
|
||||
tab[27][30]=1;
|
||||
|
||||
for(i=18;i<28;i++){
|
||||
tab[i][30]=1;
|
||||
}
|
||||
/*Initalisation des differences pastilles*/
|
||||
if(mode==3||mode==2){
|
||||
Pastille(tab,2,2);
|
||||
}
|
||||
Pastille(tab,5,1);
|
||||
}
|
||||
|
||||
/*Mise en place de pastilles le plateau de jeu
|
||||
en fonction de ce que l'on veut placer */
|
||||
int Pastille(int tab[H][L],int nb_de_pastilles,int type_pastille){
|
||||
int ia,ja;
|
||||
if(nb_de_pastilles==0){
|
||||
return 1;
|
||||
}
|
||||
srand(time(NULL));
|
||||
while(nb_de_pastilles!=0){
|
||||
ia=rand()%40;
|
||||
ja=rand()%60;
|
||||
if(tab[ia][ja]==0){
|
||||
if(type_pastille==1){
|
||||
/*pommes*/
|
||||
tab[ia][ja]=30;
|
||||
}else if(type_pastille==2){
|
||||
/*pommes pour mur*/
|
||||
tab[ia][ja]=50;
|
||||
}else if(type_pastille==3){
|
||||
/*mur*/
|
||||
tab[ia][ja]=40;
|
||||
}
|
||||
nb_de_pastilles=nb_de_pastilles-1;
|
||||
}
|
||||
}
|
||||
}
|
15
Snake_ancien/ModifTab.h
Normal file
15
Snake_ancien/ModifTab.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef MODIFTAB_H
|
||||
#define MODIFTAB_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <graph.h>
|
||||
#include <time.h>
|
||||
|
||||
#define H 42
|
||||
#define L 62
|
||||
|
||||
int Pastille(int tab[H][L], int nb_de_pastilles, int type_pastille);
|
||||
void init(int tab[H][L],int);
|
||||
|
||||
#endif // MODIFTAB_H
|
BIN
Snake_ancien/ModifTab.o
Normal file
BIN
Snake_ancien/ModifTab.o
Normal file
Binary file not shown.
BIN
Snake_ancien/exec
Executable file
BIN
Snake_ancien/exec
Executable file
Binary file not shown.
65
Snake_ancien/main.c
Normal file
65
Snake_ancien/main.c
Normal file
@ -0,0 +1,65 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <graph.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "Afficher.h"
|
||||
#include "ModifTab.h"
|
||||
#include "Deplacement.h"
|
||||
#include "Chemin.h"
|
||||
#include "Menu.h"
|
||||
|
||||
#define DELTA 1000000L;
|
||||
#define DELTO 1000L
|
||||
#define DELTI 900000L
|
||||
|
||||
int main(void) {
|
||||
int tab[H][L], direction = 0, temoin = 0, direc = 0, pause = 1,mode=0;
|
||||
int sxmin = 17, symin = 30, sxmax = 27, symax = 30, fin = 0, point = 0, Compteur_Temps = 0;
|
||||
int *pointeur_pause = &pause;
|
||||
int *pointeur_sxmin = &sxmin;
|
||||
int *pointeur_symin = &symin;
|
||||
int *pointeur_direc = &direc;
|
||||
int *pointeur_temoin = &temoin;
|
||||
int *pointeur_sxmax = &sxmax;
|
||||
int *pointeur_symax = &symax;
|
||||
int *pointeur_fin = &fin;
|
||||
int *pointeur_point = &point;
|
||||
unsigned long suivant = Microsecondes() + DELTA;
|
||||
unsigned long suivant2 = Microsecondes() + DELTO;
|
||||
unsigned long suivant3 = Microsecondes() + DELTO;
|
||||
InitEcran();
|
||||
mode=MenuDebut();
|
||||
init(tab,mode);
|
||||
|
||||
while (1) {
|
||||
if(fin!=1){
|
||||
Affiche(tab);
|
||||
if (ToucheEnAttente() == 1) {
|
||||
direction = Semage(tab, direction, sxmax, symax, pointeur_pause, pointeur_fin);
|
||||
}
|
||||
if (pause == 1) {
|
||||
if (Microsecondes() > suivant) {
|
||||
Compteur_Temps++;
|
||||
DessinerTimer(Compteur_Temps);
|
||||
suivant = Microsecondes() + DELTA;
|
||||
}
|
||||
if (Microsecondes() > suivant3) {
|
||||
DeplacementQueue(tab, pointeur_sxmin, pointeur_symin, pointeur_direc,mode);
|
||||
suivant3 = TempsArret(pointeur_temoin);
|
||||
}
|
||||
if (Microsecondes() > suivant2) {
|
||||
DeplacementTete(tab, pointeur_sxmax, pointeur_symax, direction, pointeur_temoin, pointeur_fin, pointeur_point,mode);
|
||||
suivant2 = Microsecondes() + DELTO;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (fin == 1) {
|
||||
if(Gagne(tab)==0){
|
||||
MenuFinGagne();
|
||||
}else{
|
||||
MenuFinPerdu();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
Snake_ancien/main.o
Normal file
BIN
Snake_ancien/main.o
Normal file
Binary file not shown.
20
Snake_ancien/makefile
Normal file
20
Snake_ancien/makefile
Normal file
@ -0,0 +1,20 @@
|
||||
exec : Chemin.o Deplacement.o Afficher.o ModifTab.o main.o Menu.o
|
||||
gcc -ansi -o exec Chemin.o Deplacement.o Afficher.o ModifTab.o main.o Menu.o -lgraph
|
||||
run : exec
|
||||
./exec
|
||||
Chemin.o : Chemin.c
|
||||
gcc -c Chemin.c -lgraph
|
||||
Deplacement.o : Deplacement.c
|
||||
gcc -c Deplacement.c -lgraph
|
||||
Afficher.o : Afficher.c
|
||||
gcc -c Afficher.c -lgraph
|
||||
ModifTab.o : ModifTab.c
|
||||
gcc -c ModifTab.c -lgraph
|
||||
main.o : main.c
|
||||
gcc -c main.c -lgraph
|
||||
Menu.o : Menu.c
|
||||
gcc -c Menu.c -lgraph
|
||||
clean :
|
||||
rm -f *~
|
||||
rm -f *.o
|
||||
rm exec
|
Loading…
Reference in New Issue
Block a user