From dc3a592f57df5715e3c8c1838053467257016fbf Mon Sep 17 00:00:00 2001 From: khadir Date: Tue, 12 Dec 2023 16:07:54 +0100 Subject: [PATCH] travaille --- a.out | Bin 15720 -> 16088 bytes deplacement.c | 89 ++++++++++++++++++++++++++++++ deplacement.h | 6 +++ deplacement.h~ | 7 +++ image.c~ | 13 +++++ makefile | 11 ++++ makefile~ | 8 +++ pomme.c | 58 ++++++++++++++++++++ pomme.png | Bin 0 -> 636 bytes serpent.c | 58 ++++++++++++++++++++ serpent.h | 5 ++ serpent.h~ | 7 +++ serpent.png | Bin 0 -> 509 bytes snake.c~ | 144 +++++++++++++++++++++++++++++++++++++++++++++++++ snake3.c | 15 ------ terrain.c | 16 ++++++ terrain.h | 5 ++ terrain.h~ | 0 18 files changed, 427 insertions(+), 15 deletions(-) create mode 100644 deplacement.c create mode 100644 deplacement.h create mode 100644 deplacement.h~ create mode 100644 image.c~ create mode 100644 makefile create mode 100644 makefile~ create mode 100644 pomme.c create mode 100644 pomme.png create mode 100644 serpent.c create mode 100644 serpent.h create mode 100644 serpent.h~ create mode 100644 serpent.png create mode 100644 snake.c~ delete mode 100644 snake3.c create mode 100644 terrain.c create mode 100644 terrain.h create mode 100644 terrain.h~ diff --git a/a.out b/a.out index 9253acb17dfdf2f6b7dfa44b13da59c270c6d0b8..f2f82021e908884ef8d2e517dc1458f53a08959b 100755 GIT binary patch literal 16088 zcmeHOe{dXi75`q+&;V_cBGmxe-XL`fwAZ9fLue;(`LXFn8z^mpg%OwQ-6q+R+#P$D z8meHlrSv>96Lkg|2gl-clyOD|RG3o65-8IjicT06>r5FlT9~`BXbKfmm7ec?zwd4K zws#$eKOCLeZ|3%W-{<}KzVF*#-`#!rvbM3SA`lSVD#a~Aa*GraCc)O5SVM@gXb}rx zyF`3KTmtYs_=QRAr6($sfN3@9RRTr3dhC>-A6Kwo$`K+(yK?QsrAoq7)F~eAs<2DE zm-dlUrYv{H3!*W!pxiq2EU`@8c9@&Vl}cfV+bVaD4;b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H>PcZ#Fea}WzAk*lWhf2N}d8dGoJd!iHO!;n+5P{rhVzh~nfmQ>^ zFiaLY-C@b-hQt4jhT&e}GB-OPZZ|d>9xg)iVWrhs#5``dK(adF1*_e?gi{Q|Mu&Z3 z0Y0`mX&!uKRor|JEGmatO9<15P$VkUo{c-2t)nI9Mx~05+em9=6$&8_dOXFe-e6J^ zJrx>2CVDFW6$VYS>9Xj_{AmyR$0pLEHdDN6i0Q7Gi26;sz99&G(h7P3j!Tub|Dc{^ z>N=xGL$5P8dg9k~QS@Yp&7+m=#WvTaY1;MtA7M&TUi-7;5}Px3Y(dk;AK=kkX3Z5F za#vZC`w|1VrKY89s;_hXtb3w$_VP{)USXf*>Uk!+VDizEt+PzmiG5?{zK7m(-23Jl zA@_?b=c7ln?T(8}vNNJr7?mySUQVfM0%xNYdCf9n9zKq{nzjS+G~x!tQ};COAau%W zR(2rs6f$IUp`I@6iqzwC>5iri!Q1khKGt->&bs+hiz8lz;iHkIbId9-igi^AU@Y1Fq zGIAThhxKABs}Am6Od}K%S1CG+tVgdPX*lnzfO?C=eHLR9yUwy9vY6U2HkbQ4_DcR| z2S4cb=`S{yZvi!u;3CnmIn)FjejUd1OU|QC81Xw{*l#H-A?_ze)v~BBfMZ#-YMB%V=GuQ9}` xzwOO{9d3nOB4^j@ti7e$He~9i1PHdQ7dz^VVMDOLC19Ikr3Y;}h0B4;e*vA-phN%w diff --git a/deplacement.c b/deplacement.c new file mode 100644 index 0000000..902f3f2 --- /dev/null +++ b/deplacement.c @@ -0,0 +1,89 @@ +#include +#include +#include +#include +#include + +#define LARGEUR 40 +#define HAUTEUR 60 +#define TAILLE_MAX 100 + + + int x, y; + +input(); + + if (_kbhit()) { + switch (_getch()) { + case "XK_Right": + x ++; + break; + case "XK_Left": + x --; + break; + case "XK_Up": + y ++; + break; + case "XK_Down": + y --; + gameOver = 1; + break; + } + } +} + +void logique() { + int i; + int gameOver,y,x, queueX[], queueY[], longueurQueue[]; + int prevX = queueX[0]; + int prevY = queueY[0]; + int prev2X, prev2Y; + queueX[0] = x; + queueY[0] = y; + for (i = 1; i < longueurQueue; i++) { + prev2X = queueX[i]; + prev2Y = queueY[i]; + queueX[i] = prevX; + queueY[i] = prevY; + prevX = prev2X; + prevY = prev2Y; + } + switch (_getch()) { + + gameOver = 1; + break; + case "XK_Right": + x++; + break; + case "XK_Left": + x--; + break; + case "XK_Up": + y++; + break; + case "XK_Down": + y--; + } + +} + +int main(void) { + int score; + int gameOver; + InitialiserGraphique(); + CreerFenetre(0,0,800,500); + + srand(time(NULL)); + initialiser(); + while (gameOver != 1) { + dessiner(); + input(); + logique(); + Sleep(50); + } + printf("Game Over!\n"); + printf("Votre score est: %d\n", score); + + } + FermerGraphique(); +} \ No newline at end of file diff --git a/deplacement.h b/deplacement.h new file mode 100644 index 0000000..482ac61 --- /dev/null +++ b/deplacement.h @@ -0,0 +1,6 @@ +#ifndef DEPLACEMENT_H +#define DEPLACEMENT_H +void input() +void logique() + +#endif /*DEPLACEMENT_H*/ diff --git a/deplacement.h~ b/deplacement.h~ new file mode 100644 index 0000000..48894c3 --- /dev/null +++ b/deplacement.h~ @@ -0,0 +1,7 @@ +#ifndef DEPLACEMENT_H +#define DEPLACEMENT_H +void input() +void logique() + int main() + +#endif /*DEPLACEMENT_H*/ diff --git a/image.c~ b/image.c~ new file mode 100644 index 0000000..98d9108 --- /dev/null +++ b/image.c~ @@ -0,0 +1,13 @@ +#include +#include + +int main(void) { + InitialiserGraphique(); + CreerFenetre(10,10,500,500); + ChargerImageFond("../img/pixilart-drawing (2).png"); + SauverImage("../img/pixilart-drawing (2).png"); + Touche(); + FermerGraphique(); + return EXIT_SUCCESS; +} + diff --git a/makefile b/makefile new file mode 100644 index 0000000..1c4be5e --- /dev/null +++ b/makefile @@ -0,0 +1,11 @@ +terrain: terrain.o serpent.o deplacement.o + gcc -o terrain terrain.o serpent.o deplacement.o + +terrain.o: terrain.c serpent.h deplacement.h + gcc -c terrain.c + + serpent.o: serpent.c serpent.h + gcc -c serpent.c + + deplacement.o: deplacement.c deplacement.h + gcc -c deplacement.c diff --git a/makefile~ b/makefile~ new file mode 100644 index 0000000..dc6e5a6 --- /dev/null +++ b/makefile~ @@ -0,0 +1,8 @@ +OFILES = deplacement.o \ + terrain.o \ + serpent.o \ + + +CC = gcc + +CFLAGS = -Wall -ansi -pedantic -g diff --git a/pomme.c b/pomme.c new file mode 100644 index 0000000..ef5e01e --- /dev/null +++ b/pomme.c @@ -0,0 +1,58 @@ +#include +#include +#include +#define delta 1000000L + +void DessinerScene(int sprite,int x,int y,int n) +{ + char buf[100]; + ChoisirEcran(1); + CopierZone(2,1,0,0,800,500,0,0); + snprintf(buf,100,"temps : %05d",n); + EcrireTexte(10,20,buf,0); + AfficherSprite(sprite,x,y); + CopierZone(1,0,0,0,800,500,0,0); +} + +int main() +{ + int pomme; + int x,y,old_x,old_y; + int n; + unsigned long suivant; + int go_on=1; + + InitialiserGraphique(); + CreerFenetre(0,0,800,500); + ChoisirEcran(2); + ChargerImageFond("pixilart-drawing(2)(1).jpg"); + ChargerImageFond("pomme.png"); + x=y=old_x=old_y=10; + n=0; + DessinerScene(pomme,x,y,0); + suivant=Microsecondes()+delta; + + while(go_on) + { + if (SourisCliquee()) go_on=0; + else + { + if (Microsecondes()>suivant) + { + n++; + DessinerScene(pomme,x,y,n); + suivant=Microsecondes()+delta; + } + SourisPosition(); + x=_X; + y=_Y; + if (x!=old_x || y!=old_y) + { + DessinerScene(pomme,x,y,n); + old_x=x; + old_y=y; + } + } + } + FermerGraphique(); +} diff --git a/pomme.png b/pomme.png new file mode 100644 index 0000000000000000000000000000000000000000..aa087cbbcb43f2f519e378f8b0479657fed2dc72 GIT binary patch literal 636 zcmeAS@N?(olHy`uVBq!ia0vp^DImU^4S`aSW-5 zdppC>i#bt*Eq=oWk4$wjr>-X)W?fqqI+kA)ev#=Su*P+^jG`u!SW^1TLrzon|45A$ z+}tvuGBHShw!X3T?$vugG%H#lGi6k-Z>W57@?_1Nnhd+z?@Rr~+eMn;^F z;?gvF_r2^<=C5CmZ}YeBF8uUq+O{cET0T zojcd +#include +#include +#define delta 1000000L + +void DessinerScene(int sprite,int x,int y,int n) +{ + char buf[100]; + ChoisirEcran(1); + CopierZone(2,1,0,0,800,500,0,0); + snprintf(buf,100,"temps : %05d",n); + EcrireTexte(10,20,buf,0); + AfficherSprite(sprite,x,y); + CopierZone(1,0,0,0,800,500,0,0); +} + +int main() +{ + int serpent; + int x,y,old_x,old_y; + int n; + unsigned long suivant; + int go_on=1; + + InitialiserGraphique(); + CreerFenetre(0,0,800,500); + ChoisirEcran(2); + ChargerImageFond("serpent.jpg"); + ChargerImageFond("serpent.png"); + x=y=old_x=old_y=10; + n=0; + DessinerScene(serpent,x,y,0); + suivant=Microsecondes()+delta; + + while(go_on) + { + if (SourisCliquee()) go_on=0; + else + { + if (Microsecondes()>suivant) + { + n++; + DessinerScene(serpent,x,y,n); + suivant=Microsecondes()+delta; + } + SourisPosition(); + x=_X; + y=_Y; + if (x!=old_x || y!=old_y) + { + DessinerScene(serpent,x,y,n); + old_x=x; + old_y=y; + } + } + } + FermerGraphique(); +} diff --git a/serpent.h b/serpent.h new file mode 100644 index 0000000..dfad686 --- /dev/null +++ b/serpent.h @@ -0,0 +1,5 @@ +#ifndef SERPENT_H +#define SERPENT_H +void DessinerScene(int sprite,int x,int y,int n) + +#endif /*SERPENT_H */ diff --git a/serpent.h~ b/serpent.h~ new file mode 100644 index 0000000..628b361 --- /dev/null +++ b/serpent.h~ @@ -0,0 +1,7 @@ +#ifndef SERPENT_H +#define SERPENT_H +void DessinerScene(int sprite,int x,int y,int n) +int main() +int serpent; + +#endif /*SERPENT_H */ diff --git a/serpent.png b/serpent.png new file mode 100644 index 0000000000000000000000000000000000000000..283e8685388446c48bc0a98c1cc734df167859c9 GIT binary patch literal 509 zcmeAS@N?(olHy`uVBq!ia0vp^DIm1o@ig)Nh<%`P`;jHu=xb&pP%8Y~JY^$?vkOJ7>79@=osK&*eX7%2}Q+`mvm4 zr`d +#include +#include +#include +#include + +#define LARGEUR 20 +#define HAUTEUR 20 +#define TAILLE_MAX 100 + +int main(void) { +int x, y, fruitX, fruitY, score, gameOver; +ChargerImageFond("../img/pixilart-drawing (2).png"); +void initialiser() { + x = LARGEUR / 2; + y = HAUTEUR / 2; + fruitX = rand() % LARGEUR; + fruitY = rand() % HAUTEUR; + score = 0; + gameOver = 0; +} + +void dessiner() { + int i, j; + for (i = 0; i < LARGEUR + 2; i++) + printf("#"); + printf("\n"); + + for (i = 0; i < HAUTEUR; i++) { + for (j = 0; j < LARGEUR; j++) { + if (j == 0) + printf("#"); + if (i == y && j == x) + printf("O"); + else if (i == fruitY && j == fruitX) + printf("F"); + else { + int affiche = 0; + for (int k = 0; k < longueurQueue; k++) { + if (queueX[k] == j && queueY[k] == i) { + printf("o"); + affiche = 1; + } + } + if (!affiche) + printf(" "); + } + if (j == LARGEUR - 1) + printf("#"); + } + printf("\n"); + } + + for (i = 0; i < LARGEUR + 2; i++) + printf("#"); + printf("\n"); + printf("Score: %d\n", score); +} + +void input() { + if (_kbhit()) { + switch (_getch()) { + case 'a': + x--; + break; + case 'd': + x++; + break; + case 'w': + y--; + break; + case 's': + y++; + break; + case 'x': + gameOver = 1; + break; + } + } +} + +void logique() { + int i; + int prevX = queueX[0]; + int prevY = queueY[0]; + int prev2X, prev2Y; + queueX[0] = x; + queueY[0] = y; + for (i = 1; i < longueurQueue; i++) { + prev2X = queueX[i]; + prev2Y = queueY[i]; + queueX[i] = prevX; + queueY[i] = prevY; + prevX = prev2X; + prevY = prev2Y; + } + switch (_getch()) { + case 'a': + x--; + break; + case 'd': + x++; + break; + case 'w': + y--; + break; + case 's': + y++; + break; + case 'x': + gameOver = 1; + break; + } + if (x > LARGEUR || x < 0 || y > HAUTEUR || y < 0) + gameOver = 1; + for (i = 0; i < longueurQueue; i++) + if (queueX[i] == x && queueY[i] == y) + gameOver = 1; + if (x == fruitX && y == fruitY) { + score += 10; + fruitX = rand() % LARGEUR; + fruitY = rand() % HAUTEUR; + longueurQueue++; + } +} + +int main() { + srand(time(NULL)); + initialiser(); + while (!gameOver) { + dessiner(); + input(); + logique(); + Sleep(50); + } + printf("Game Over!\n"); + printf("Votre score est: %d\n", score); + return 0; +} + + + + + diff --git a/snake3.c b/snake3.c deleted file mode 100644 index 5d70734..0000000 --- a/snake3.c +++ /dev/null @@ -1,15 +0,0 @@ - -#include -#include - -int main(void) { - couleur c; - InitialiserGraphique(); - CreerFenetre(10,10,500,500); - c=CouleurParNom("green"); - c=CouleurParComposante(161,232,90); - EffacerEcran(c); - Touche(); - FermerGraphique(); - return EXIT_SUCCESS; -} diff --git a/terrain.c b/terrain.c new file mode 100644 index 0000000..18f1cbd --- /dev/null +++ b/terrain.c @@ -0,0 +1,16 @@ + +#include +#include + +int main(void) { + couleur c; + InitialiserGraphique(); + CreerFenetre(10,10,500,500); + c=CouleurParNom("green"); + c=CouleurParComposante(161,232,90); + EffacerEcran(c); + Touche(); + FermerGraphique(); + return EXIT_SUCCESS; +} + diff --git a/terrain.h b/terrain.h new file mode 100644 index 0000000..340ea78 --- /dev/null +++ b/terrain.h @@ -0,0 +1,5 @@ +#ifndef TERRAIN_H +#define TERRAIN_H +int main(void) + +#endif /* TERRAIN_H */ diff --git a/terrain.h~ b/terrain.h~ new file mode 100644 index 0000000..e69de29