travaille

This commit is contained in:
Soraya KHADIR 2023-12-12 16:07:54 +01:00
parent f3aa5365f3
commit dc3a592f57
18 changed files with 427 additions and 15 deletions

BIN
a.out

Binary file not shown.

89
deplacement.c Normal file
View File

@ -0,0 +1,89 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <graph.h>
#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();
}

6
deplacement.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef DEPLACEMENT_H
#define DEPLACEMENT_H
void input()
void logique()
#endif /*DEPLACEMENT_H*/

7
deplacement.h~ Normal file
View File

@ -0,0 +1,7 @@
#ifndef DEPLACEMENT_H
#define DEPLACEMENT_H
void input()
void logique()
int main()
#endif /*DEPLACEMENT_H*/

13
image.c~ Normal file
View File

@ -0,0 +1,13 @@
#include<stdlib.h>
#include<graph.h>
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;
}

11
makefile Normal file
View File

@ -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

8
makefile~ Normal file
View File

@ -0,0 +1,8 @@
OFILES = deplacement.o \
terrain.o \
serpent.o \
CC = gcc
CFLAGS = -Wall -ansi -pedantic -g

58
pomme.c Normal file
View File

@ -0,0 +1,58 @@
#include <stdio.h>
#include <stdlib.h>
#include <graph.h>
#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();
}

BIN
pomme.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 636 B

58
serpent.c Normal file
View File

@ -0,0 +1,58 @@
#include <stdio.h>
#include <stdlib.h>
#include <graph.h>
#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();
}

5
serpent.h Normal file
View File

@ -0,0 +1,5 @@
#ifndef SERPENT_H
#define SERPENT_H
void DessinerScene(int sprite,int x,int y,int n)
#endif /*SERPENT_H */

7
serpent.h~ Normal file
View File

@ -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 */

BIN
serpent.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 509 B

144
snake.c~ Normal file
View File

@ -0,0 +1,144 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <graph.h>
#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;
}

View File

@ -1,15 +0,0 @@
#include<stdlib.h>
#include<graph.h>
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;
}

16
terrain.c Normal file
View File

@ -0,0 +1,16 @@
#include <stdlib.h>
#include <graph.h>
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;
}

5
terrain.h Normal file
View File

@ -0,0 +1,5 @@
#ifndef TERRAIN_H
#define TERRAIN_H
int main(void)
#endif /* TERRAIN_H */

0
terrain.h~ Normal file
View File