Commit 44eb975c70d14c8bbb8e51340de8bc6f4ceda366

Authored by Pierre Cwik
1 parent 39758f3e

snake bouge

projets/Centipede/centipede
No preview for this file type
projets/Centipede/progprinc.c
@@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
4 #include <libgraph.h> 4 #include <libgraph.h>
5 #include <unistd.h> 5 #include <unistd.h>
6 #include <time.h> 6 #include <time.h>
  7 +#include <SDL/SDL.h>
7 #define MAX_ELEMENTS 50 8 #define MAX_ELEMENTS 50
8 9
9 typedef struct { 10 typedef struct {
@@ -24,63 +25,130 @@ void affichage(element_t e) @@ -24,63 +25,130 @@ void affichage(element_t e)
24 25
25 26
26 int main() { 27 int main() {
  28 + SDL_keysym* detail;
27 srand(time(NULL)); 29 srand(time(NULL));
28 char touche; 30 char touche;
29 unsigned char bas; 31 unsigned char bas;
30 - void* detail;  
31 int largeur = 1000; 32 int largeur = 1000;
32 int hauteur = 1000; 33 int hauteur = 1000;
33 liste_champi muschrooms={.nombre=0}; 34 liste_champi muschrooms={.nombre=0};
  35 + liste_t listecenti={NULL,0,0};
34 int h,w,l,i; 36 int h,w,l,i;
35 char *titre = "Le Centipède"; 37 char *titre = "Le Centipède";
36 38
37 - creerSurface(largeur,hauteur,titre); 39 +
38 int champi = chargerLutin("Lutins/millepatte_champi.bmp",0); 40 int champi = chargerLutin("Lutins/millepatte_champi.bmp",0);
39 - if(champi<0){ printf("Champi pas là\n"); exit(-1); }  
40 int Teted = chargerLutin("Lutins/millepatte_tete_droite.bmp",0); 41 int Teted = chargerLutin("Lutins/millepatte_tete_droite.bmp",0);
  42 +/* int Teteg = chargerLutin("Lutins/millepatte_tete_gauche.bmp",0);
  43 + int Teteh = chargerLutin("Lutins/millepatte_tete_haut.bmp",0);
  44 + int Teteb = chargerLutin("Lutins/millepatte_tete_bas.bmp",0);
  45 + int Corpsg = chargerLutin("Lutins/millepatte_corps_gauche.bmp",0); */
  46 + int Corpsd = chargerLutin("Lutins/millepatte_corps_droite.bmp",0);
  47 +/* int Corpsh = chargerLutin("Lutins/millepatte_corps_haut.bmp",0);
  48 + int Corpsb = chargerLutin("Lutins/millepatte_corps_bas.bmp",0); */
  49 +
  50 + if(champi<0){ printf("Champi pas là\n"); exit(-1); }
41 tailleLutin(champi,&l,&h); 51 tailleLutin(champi,&l,&h);
  52 +
  53 +
  54 + position *pos;
42 position poschampi; 55 position poschampi;
  56 + position posmillepatte;
43 57
44 - int x = (rand()%20)*50+2;  
45 - int y = (rand()%20)*50;  
46 - afficherLutin(Teted,x,y); 58 + creerSurface(largeur,hauteur,titre);
  59 +
  60 + int x = 300;
  61 + int y = 500;
  62 +
  63 + for(i=0; i<4; i++)
  64 + {
  65 + posmillepatte.x = (x + 50*i);
  66 + posmillepatte.y = y;
  67 + enfiler(&listecenti,&posmillepatte,sizeof(position));
  68 + }
  69 + //affichage des corpsd du centipede
  70 + for(i=0; i<4; i++)
  71 + {
  72 + pos = enieme(i,&listecenti);
  73 + afficherLutin(Corpsd,pos->x,pos->y);
  74 + }
  75 +
  76 + posmillepatte.x = (x+200);
  77 + posmillepatte.y = y;
  78 + enfiler(&listecenti,&posmillepatte,sizeof(position)); //affichage de la tete du Centipède
  79 + pos = enieme(4, &listecenti);
  80 + afficherLutin(Teted,pos->x,pos->y);
47 81
48 for(i = 0 ; i < 20; i++) 82 for(i = 0 ; i < 20; i++)
49 { 83 {
50 - rectanglePlein(i*50,0,1,1000,5); 84 + rectanglePlein(i*50,0,1,1000,5); //pose de la grille
51 rectanglePlein(0,i*50,1000,1,5); 85 rectanglePlein(0,i*50,1000,1,5);
52 } 86 }
53 87
54 for(w=0;w<10;w++) { 88 for(w=0;w<10;w++) {
55 - poschampi.x = (rand()%20)*50; 89 + poschampi.x = (rand()%20)*50; //fixe coordonnées des champignons
56 poschampi.y = (rand()%20)*50; 90 poschampi.y = (rand()%20)*50;
57 - muschrooms.contenu[muschrooms.nombre++]=poschampi; 91 + if(poschampi.y > 550 || poschampi.y < 450) {
  92 + muschrooms.contenu[muschrooms.nombre++]=poschampi; }
  93 + else w--;
58 } 94 }
59 95
60 -  
61 -  
62 printf("%d %d \n",l,h); 96 printf("%d %d \n",l,h);
63 97
64 for(w=0;w<10;w++){ 98 for(w=0;w<10;w++){
65 afficherLutin(champi,(muschrooms.contenu[w].x)+1,(muschrooms.contenu[w].y)+6); 99 afficherLutin(champi,(muschrooms.contenu[w].x)+1,(muschrooms.contenu[w].y)+6);
66 - }  
67 - majSurface(); 100 + }//affiche les champis
  101 + majSurface();
  102 +
  103 + int gomme = creerLutin(0,0,50,50,0);
  104 + majSurface();
68 105
69 106
70 107
71 while(1){ 108 while(1){
72 - while(!lireTouche(&bas,&touche,&detail));  
73 - printf("%d %c\n",bas,touche); 109 + if(lireTouche(&bas,&touche,(void **)&detail) && bas==1) {
  110 +
  111 + if(detail->sym==SDLK_RIGHT) {
  112 + printf("dans le droite\n");
  113 + pos = premier(&listecenti);
  114 + afficherLutin(gomme,pos->x,pos->y);
  115 + defiler(&listecenti);
  116 +
  117 + pos = dernier(&listecenti);
  118 + afficherLutin(gomme,pos->x,pos->y);
  119 + afficherLutin(Corpsd,(pos->x),pos->y);
  120 + posmillepatte.x = pos->x+50;
  121 + posmillepatte.y = pos->y;
  122 + enfiler(&listecenti,&posmillepatte,sizeof(posmillepatte));
  123 + afficherLutin(Teted,posmillepatte.x,posmillepatte.y);
  124 + majSurface();
  125 + }
  126 +
  127 + if(detail->sym==SDLK_LEFT) {
  128 +
  129 + }
  130 +
  131 + if(detail->sym==SDLK_UP) {
  132 +
  133 + }
  134 +
  135 + if(detail->sym==SDLK_DOWN) {
  136 +
  137 + }
  138 +
  139 +
  140 +
  141 +
74 if(touche=='a') 142 if(touche=='a')
75 { 143 {
76 - fermerSurface(); 144 + fermerSurface(); //condition d'arret
77 return 0; 145 return 0;
78 146
79 } 147 }
80 - } 148 + }}
81 149
82 150
83 return 0; 151 return 0;
84 } 152 }
85 153
86 -  
87 \ No newline at end of file 154 \ No newline at end of file
  155 +
projets/Centipede/progprinc.o
No preview for this file type
projets/Liste/libFile.c
@@ -43,3 +43,13 @@ int defiler(liste_t *l) @@ -43,3 +43,13 @@ int defiler(liste_t *l)
43 } 43 }
44 return 0; 44 return 0;
45 } 45 }
  46 +
  47 +element_t premier(liste_t *l) {
  48 + return l->contenu[0]; }
  49 +
  50 +element_t dernier(liste_t *l) {
  51 + return l->contenu[(l->nombre)-1];}
  52 +
  53 +element_t enieme(int x, liste_t *l) {
  54 + return l->contenu[x];
  55 +}
projets/Liste/libFile.h
@@ -7,6 +7,9 @@ typedef void *element_t; @@ -7,6 +7,9 @@ typedef void *element_t;
7 } liste_t; 7 } liste_t;
8 8
9 int taille(liste_t *l); 9 int taille(liste_t *l);
10 -int enfiler (liste_t *l, element_t e, int taille); 10 +int enfiler (liste_t *l,element_t e, int taille);
11 int afficher (liste_t *l, void(*affichage)(element_t)); 11 int afficher (liste_t *l, void(*affichage)(element_t));
12 int defiler(liste_t *l); 12 int defiler(liste_t *l);
  13 +element_t dernier(liste_t *l);
  14 +element_t premier(liste_t *l);
  15 +element_t enieme(int x, liste_t *l);
projets/Liste/libFile.o
No preview for this file type
projets/Liste/libListe.a
No preview for this file type