separation du coode ajout des menu
This commit is contained in:
parent
0ff1c36751
commit
19e7a1ccf6
89
Snake/Afficher.c
Normal file
89
Snake/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/Afficher.h
Normal file
17
Snake/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
|
82
Snake/Chemin.c
Normal file
82
Snake/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/Chemin.h
Normal file
20
Snake/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
|
356
Snake/Deplacement.c
Normal file
356
Snake/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;
|
||||
}
|
||||
}}
|
||||
}
|
Loading…
Reference in New Issue
Block a user