From fd0c4a36a8639b0eca507fc4a67697c91a0acda1 Mon Sep 17 00:00:00 2001 From: keraudre <yann.keraudren@etu-upec.fr> Date: Thu, 14 Dec 2023 01:07:57 +0100 Subject: [PATCH] =?UTF-8?q?avancement=20sur=20les=20d=C3=A9placement=20du?= =?UTF-8?q?=20serpent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snake/Makefile | 5 +- snake/deplacement.c | 187 +++++++++++++++++++++++++++---------------- snake/fenetre.c | 2 +- snake/lancement | Bin 0 -> 20736 bytes snake/main.c | 29 +++++-- snake/plateau_init.c | 51 +++++++++--- snake/plateau_init.h | 4 +- snake/supp_queue.c | 51 ++++++++++++ snake/supp_queue.h | 14 ++++ snake/update_queue.c | 35 -------- snake/update_queue.h | 12 --- 11 files changed, 256 insertions(+), 134 deletions(-) create mode 100755 snake/lancement create mode 100644 snake/supp_queue.c create mode 100644 snake/supp_queue.h delete mode 100644 snake/update_queue.c delete mode 100644 snake/update_queue.h diff --git a/snake/Makefile b/snake/Makefile index b92e83a..8e88d81 100755 --- a/snake/Makefile +++ b/snake/Makefile @@ -11,8 +11,9 @@ OFILES = plateau_init.o \ deplacement.o \ ajout_score.o \ score_init.o \ + supp_queue.o \ main.o - + CC = gcc @@ -26,6 +27,8 @@ fenetre.o : fenetre.h plateau_init.h deplacement.o : deplacement.h +supp_queue.o : supp_queue.h + ajout_score.o : ajout_score.h score_init.o : score_init.h diff --git a/snake/deplacement.c b/snake/deplacement.c index 803f4ca..155fcb3 100644 --- a/snake/deplacement.c +++ b/snake/deplacement.c @@ -7,7 +7,7 @@ #include <stdio.h> #include <graph.h> #include "plateau_init.h" -#include "update_queue.h" +#include "supp_queue.h" #include "deplacement.h" @@ -21,7 +21,11 @@ void deplacement (struct adresse* pointeur, unsigned char* sens) { unsigned char* tete = pointeur -> tete; - unsigned char* queue = pointeur -> queue; + unsigned int** corps_serpent = pointeur -> corps_serpent; + + unsigned int* indice_queue = pointeur -> indice_queue; + + int touche; couleur green, yellow; @@ -31,59 +35,6 @@ void deplacement (struct adresse* pointeur, unsigned char* sens) { - printf("%d %d", queue[0], queue[1]); - - - if ( *sens == BAS) { - - plateau[tete[0] + 1][tete[1]] = 1; - - plateau[queue[0]][queue[1]] = 0; - - tete[0] = tete[0] + 1; - - ChoisirCouleurDessin(yellow); - RemplirRectangle(20*(tete[1] + 1),20*(tete[0] +1 ),20,20); - - ChoisirCouleurDessin(green); - RemplirRectangle(20*(queue[1] +1 ),20*(queue[0] +1 ),20,20); - - queue[0] = queue[0] + 1; - - - - - } - - if ( *sens == HAUT) { - - plateau[tete[0] - 1][tete[1]] = 1; - - plateau[queue[0]][queue[1]] = 0; - - tete[0] = tete[0] -1; - - } - - if ( *sens == DROITE) { - - plateau[tete[0]][tete[1] + 1] = 1; - - plateau[queue[0]][queue[1]] = 0; - - tete[1] = tete[1] + 1; - - } - - if ( *sens == GAUCHE) { - - plateau[tete[0]][tete[1] - 1] = 1; - - plateau[queue[0]][queue[1]] = 0; - - tete[1] = tete[1] - 1; - - } @@ -91,71 +42,167 @@ void deplacement (struct adresse* pointeur, unsigned char* sens) { if (ToucheEnAttente() == 1) { - if (Touche() == XK_Left) { + touche = Touche(); + + if (touche == XK_Left) { plateau[tete[0]][tete[1]] = 0; plateau[tete[0]][tete[1] - 1] = 1; - plateau[queue[0]][queue[1]] = 0; + plateau[corps_serpent[*indice_queue][0]][corps_serpent[*indice_queue][1]] = 0; tete[1] = tete[1] - 1; + ChoisirCouleurDessin(yellow); + RemplirRectangle(20*(tete[1]+1),20*(tete[0]+1),20,20); + + *sens = GAUCHE; + + supp_queue(pointeur); + + return; } - if (Touche() == XK_Right) { + if (touche == XK_Right) { plateau[tete[0]][tete[1]] = 0; plateau[tete[0]][tete[1] + 1] = 1; - plateau[queue[0]][queue[1]] = 0; + plateau[corps_serpent[*indice_queue][0]][corps_serpent[*indice_queue][1]] = 0; tete[1] = tete[1] + 1; + ChoisirCouleurDessin(yellow); + RemplirRectangle(20*(tete[1]+1),20*(tete[0]+1),20,20); + + *sens = DROITE; + supp_queue(pointeur); + + return; } - if (Touche() == XK_Up) { + if (touche == XK_Up) { plateau[tete[0]][tete[1]] = 0; plateau[tete[0] - 1][tete[1]] = 1; - plateau[queue[0]][queue[1]] = 0; + plateau[corps_serpent[*indice_queue][0]][corps_serpent[*indice_queue][1]] = 0; tete[0] = tete[0] - 1; + ChoisirCouleurDessin(yellow); + RemplirRectangle(20*(tete[1]+1),20*(tete[0]+1),20,20); + + *sens = HAUT; + + supp_queue(pointeur); + + return; } - if (Touche() == XK_Down) { + if (touche == XK_Down) { plateau[tete[0]][tete[1]] = 0; plateau[tete[0] + 1][tete[1]] = 1; - plateau[queue[0]][queue[1]] = 0; + plateau[corps_serpent[*indice_queue][0]][corps_serpent[*indice_queue][1]] = 0; tete[0] = tete[0] + 1; - *sens = DROITE; + ChoisirCouleurDessin(yellow); + RemplirRectangle(20*(tete[1]+1),20*(tete[0]+1),20,20); + + + *sens = BAS; + + supp_queue(pointeur); + + return; } + + + } + + else { + + if ( *sens == BAS) { + + plateau[tete[0] + 1][tete[1]] = 1; + + plateau[corps_serpent[*indice_queue][0]][corps_serpent[*indice_queue][1]] = 0; + + tete[0] = tete[0] + 1; + + ChoisirCouleurDessin(yellow); + RemplirRectangle(20*(tete[1]+1),20*(tete[0]+1),20,20); + + + + } + + if ( *sens == HAUT) { + + plateau[tete[0] - 1][tete[1]] = 1; + + plateau[corps_serpent[*indice_queue][0]][corps_serpent[*indice_queue][1]] = 0; + + tete[0] = tete[0] - 1; + + ChoisirCouleurDessin(yellow); + RemplirRectangle(20*(tete[1]+1),20*(tete[0]+1),20,20); + + + } + + + + if ( *sens == DROITE) { + + plateau[tete[0]][tete[1] + 1] = 1; + + plateau[corps_serpent[*indice_queue][0]][corps_serpent[*indice_queue][1]] = 0; + + tete[1] = tete[1] + 1; + + ChoisirCouleurDessin(yellow); + RemplirRectangle(20*(tete[1]+1),20*(tete[0]+1),20,20); + + + } + + if ( *sens == GAUCHE) { + + plateau[tete[0]][tete[1] - 1] = 1; + + plateau[corps_serpent[*indice_queue][0]][corps_serpent[*indice_queue][1]] = 0; + + tete[1] = tete[1] - 1; + + ChoisirCouleurDessin(yellow); + RemplirRectangle(20*(tete[1]+1),20*(tete[0]+1),20,20); + + + } + + /* mise à jour de la position de queue dans le plateau et sur le plateau */ + + supp_queue( pointeur); + } - - - /* mise à jour de la position de queue dans le plateau */ - - - } diff --git a/snake/fenetre.c b/snake/fenetre.c index f75d270..6113b55 100755 --- a/snake/fenetre.c +++ b/snake/fenetre.c @@ -97,7 +97,7 @@ int start (struct adresse* pointeur) { yellow = CouleurParComposante(255,255,0); ChoisirCouleurDessin(yellow); - RemplirRectangle(20*(j+1),20*(i+1),20,20); + RemplirRectangle(20*(j+1),20*(i+1),20,40); } diff --git a/snake/lancement b/snake/lancement new file mode 100755 index 0000000000000000000000000000000000000000..95faf65f53a5468dafd4b6909b5286745617b61d GIT binary patch literal 20736 zcmb<-^>JfjWMqH=W(GS35HCOwBH{p{7#cjG3<d@U2L=lUUIqsSIR;q<HU<U;7O)sZ z9;O~f-(Z4>!)Oi&mw_3oPXfeXU|>L}WuWR{G{{XLArK9+55&fXGq@n4Fq%OC!UySN z1u>y~m^h5i6bDH%Fu-V-I7lDZJ_Cq60~&n;q=12e0Y)S11BJ~2TZp~`zNqvAXt=z9 z(lC7>E=b=6sJ;tOeK7h1)IJyu3r~<6LD&Ksp6E0zK43Juz6z*5blL^tYz7z&vI8U( z{Inzm#74IV#)sJhqha<1K=nC5!x5bh0U6G~zyPB`c7TKepO&P6!Ue=82E(E`2x=d$ zcyIs(I4J!>X=v~==;vf6nVIP4r0C{k=9O0HR#=$nnwjVo=j$1Ptp~Xa<ONWga`y{m zU}|7E01|`gXJlYR;WI(`V9n69FT%h8&Icg<Pt^ZBd~WbV>hYO2P5W~_Tb9OOzXUQ5 z<PVUUAT=PpATbaIu|XIl2g4vfu~?3gfk6n1;sOTj;vhQ|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Y_or<m>)K2>L|9?Kr{jh!qjE413pxqDn`4v#>84?*77(jgvn0{El1V+Qo z2Libf6m~HG!}<rA&@+5s`eFSX7!B*!!0ZE=0b_&cLIwuVHdDC!Vf_Xe4Q+nF`%N%= zV00Y=0|Tf}0^`H_B`_Kmf9UQ9*$u*=^L0RB3eykk7r|&)zX(12VE&&DZ5ug(3}awm zfc3LrG^iZ{k^<=m^~KP`Zy~rni|7}Enp`0DFdCG;!F(tIax0VxrskmOR{%BeL2XYc z4W0`GtAr3xVVLm@%hB}1+P5&82l;Rd(A*}(7&y5WO+T#t3Zr5DYnTRf_iu*khlM}- z`C_p6!=-;WntoV+0Y-!7W?_0kG`jsK(e%%NCO8=FfR<ok@dq*sgfBBNFn~5oL$fV> z+yJzP7$lFb9>#~!_Zb)%K%1*!`eEY=CqUbhVV!P}K~N0S2cus@#}r`tVf`Q2`Dw6o z(m?4SWCTnfEFFA-`X8nrcAm`vdyr}d22lSG!h(=6{V@6`nts^0#0#i?@P0msRxk<E z2cwx7A?Me??1%N!CO{(|=1#C?Y~jHO8JK|Shqd<?K=s4yf$2w!P6l46{m^KKDPw@? zN6&vS{m3*t?ZS04FdTr|{{x!fK;<xK><Q)`Sor}OZ-KcTNjt+1R|szdn&B{eA+ih% TpkV`S`ZGKrD#Xw<pm7-h%8cRG literal 0 HcmV?d00001 diff --git a/snake/main.c b/snake/main.c index 9f57e6e..e01b2ad 100644 --- a/snake/main.c +++ b/snake/main.c @@ -6,7 +6,7 @@ #include "deplacement.h" -#define CYCLE 1000000L +#define CYCLE 200000L int main(void) { @@ -16,9 +16,10 @@ int main(void) { short int* compteur = NULL; - int i; + int i = 0; + unsigned int* indice_queue = pointeur -> indice_queue; unsigned char* sens = NULL; @@ -27,6 +28,7 @@ int main(void) { unsigned long suivant; + sens = malloc(sizeof(unsigned char)); *sens = 2; @@ -59,11 +61,15 @@ int main(void) { if (Microsecondes() > suivant) { - + printf("%u %u\n", pointeur -> corps_serpent[*indice_queue][0], pointeur -> corps_serpent[*indice_queue][1]); + + deplacement(pointeur, sens); suivant = Microsecondes() + CYCLE; + + } @@ -79,13 +85,26 @@ int main(void) { } + + for ( i =0; i < TAILLE_SERPENT; i++) { + + free(pointeur -> corps_serpent[i]); + + } + + free(pointeur -> corps_serpent); + + + free(pointeur -> plateau); free(pointeur -> tete); - free(pointeur -> queue); + free(pointeur -> indice_queue); - free(sens); + free(sens); + + free(pointeur -> taille_serpent); free(pointeur); diff --git a/snake/plateau_init.c b/snake/plateau_init.c index b985944..b15546c 100755 --- a/snake/plateau_init.c +++ b/snake/plateau_init.c @@ -14,10 +14,12 @@ struct adresse* plateau_init(void) { int ligne_pomme, colonne_pomme, i; - unsigned char* tete = NULL; - unsigned char* queue = NULL; + unsigned int* indice_queue = NULL; + unsigned int* taille_serpent = NULL; + unsigned int** corps_serpent = NULL; + int** plateau = NULL; @@ -27,19 +29,28 @@ struct adresse* plateau_init(void) { srand(time(NULL)); + + + /* allocation du pointeur */ pointeur = malloc(sizeof( struct adresse)); + + /* allocation du tableau tete et queue */ tete = malloc(2*sizeof(unsigned char)); - queue = malloc(2*sizeof(unsigned char)); + indice_queue = malloc(sizeof(unsigned int)); - /* allocation du tableau dans le tas */ + + + + + /* allocation du plateau dans le tas */ plateau = calloc(LIGNES, sizeof(int*)); @@ -49,9 +60,26 @@ struct adresse* plateau_init(void) { } - + + /* allocation du corps du serpent */ + + corps_serpent = malloc(TAILLE_SERPENT * sizeof(unsigned int*)); + + for ( i = 0; i < TAILLE_SERPENT; i++) { + + corps_serpent[i] = malloc( 2 * sizeof(unsigned int)); + + } + + + + /* allocation de la taille du serpent */ + + taille_serpent = malloc(sizeof(unsigned int)); + + /* positionnement du serpent et marquage de la tete et la queue */ tete[0] = ((LIGNES/2)+(TAILLE_SERPENT/2)-1); @@ -59,13 +87,14 @@ struct adresse* plateau_init(void) { - queue[0] = ((LIGNES/2)-(TAILLE_SERPENT/2)); - queue[1] = COLONNES/2; for (i = 0; i < TAILLE_SERPENT ; i++) { plateau[((LIGNES/2)-5)+i][COLONNES/2] = 1; + + corps_serpent[i][0] = ((LIGNES/2)-5) + i; + corps_serpent[i][1] = COLONNES/2; } @@ -96,11 +125,15 @@ struct adresse* plateau_init(void) { } + *taille_serpent = TAILLE_SERPENT; + + *indice_queue = 0; pointeur -> plateau = plateau; pointeur -> tete = tete; - pointeur -> queue = queue; - + pointeur -> indice_queue = indice_queue; + pointeur -> corps_serpent = corps_serpent; + pointeur -> taille_serpent = taille_serpent; diff --git a/snake/plateau_init.h b/snake/plateau_init.h index 0ffc960..55843a2 100644 --- a/snake/plateau_init.h +++ b/snake/plateau_init.h @@ -15,8 +15,10 @@ struct adresse { int** plateau; + unsigned int** corps_serpent; + unsigned int* taille_serpent; unsigned char* tete; - unsigned char* queue; + unsigned int* indice_queue; }; diff --git a/snake/supp_queue.c b/snake/supp_queue.c new file mode 100644 index 0000000..a384983 --- /dev/null +++ b/snake/supp_queue.c @@ -0,0 +1,51 @@ +/* Fonction qui mets à jour la position de la queue en fonction des déplacement du serpent + + Written by Yann KERAUDREN and Titouan LERICHE */ + + +#include <stdlib.h> +#include <stdio.h> +#include <graph.h> +#include "supp_queue.h" + + + + +void supp_queue( struct adresse* pointeur ) { + + + unsigned int** corps_serpent = pointeur -> corps_serpent; + + unsigned int* taille_serpent = pointeur -> taille_serpent; + + unsigned char* tete = pointeur -> tete; + + unsigned int* indice_queue = pointeur -> indice_queue; + + + + + couleur green; + + + green = CouleurParComposante(50,205,50); + ChoisirCouleurDessin(green); + RemplirRectangle(20*(corps_serpent[*indice_queue][1]+1),20*(corps_serpent[*indice_queue][0]+1),20,20); + + corps_serpent[*indice_queue][0] = tete[0]; + corps_serpent[*indice_queue][1] = tete[1]; + + + *indice_queue = *indice_queue + 1; + + if ( *indice_queue == *taille_serpent ) { + + *indice_queue = 0; + + } + + +} + + + diff --git a/snake/supp_queue.h b/snake/supp_queue.h new file mode 100644 index 0000000..f97ac29 --- /dev/null +++ b/snake/supp_queue.h @@ -0,0 +1,14 @@ +/* fichier d'en-tête du fichier source supp_queue.c */ + + +#ifndef SUPP_QUEUE_H +#define SUPP_QUEUE_H + +#include "plateau_init.h" + +void supp_queue(struct adresse* pointeur) ; + +#endif /* SUPP_QUEUE_H */ + + + diff --git a/snake/update_queue.c b/snake/update_queue.c deleted file mode 100644 index 7496d58..0000000 --- a/snake/update_queue.c +++ /dev/null @@ -1,35 +0,0 @@ -/* Fonction qui mets à jour la position de la queue en fonction des déplacement du serpent - - Written by Yann KERAUDREN and Titouan LERICHE */ - - -#include <stdlib.h> -#include <stdio.h> - - -void maj_queue(int* queue, int** p) { - - if ( p[queue[0] +1 ][queue[1]] == 1 ) { - - queue[0] = queue[0] +1 ; - - } - - if ( p[queue[0] - 1][queue[1]] == 1 ) { - - queue[0] = queue[0] -1; - } - - if ( p [queue[0]][queue[1]+1] == 1) { - - queue[1] = queue [1] +1; - - } - - if ( p [queue[0]][queue[1]-1] == 1) { - - queue[1] = queue[1] -1; - - } - -} diff --git a/snake/update_queue.h b/snake/update_queue.h deleted file mode 100644 index e565eb6..0000000 --- a/snake/update_queue.h +++ /dev/null @@ -1,12 +0,0 @@ -/* fichier d'en-tête du fichier source test_queue.c */ - - -#ifndef UPDATE_QUEUE_H -#define UPDATE_QUEUE_H - -int test_queue(int* queue, int** p) ; - -#endif /* UPDATE_QUEUE_H */ - - -