voila
This commit is contained in:
parent
dc3a592f57
commit
a549f7df3a
1
.#makefile
Symbolic link
1
.#makefile
Symbolic link
@ -0,0 +1 @@
|
||||
khadir@salle222-13.168261:1703162703
|
29
Makefile
Normal file
29
Makefile
Normal file
@ -0,0 +1,29 @@
|
||||
but : snake
|
||||
|
||||
OFILES = main.o \
|
||||
serpent.o \
|
||||
pomme.o \
|
||||
terrain.o\
|
||||
temps_et_score.o
|
||||
|
||||
CC = gcc
|
||||
|
||||
CFLAGS = -Wall -ansi -pedantic -g
|
||||
|
||||
serpent.o : serpent.h terrain.h temps_et_score.h
|
||||
|
||||
pomme.o : pomme.h terrain.h serpent.h
|
||||
|
||||
main.o : serpent.h pomme.h temps_et_score.h terrain.h
|
||||
|
||||
temps_et_score.o : temps_score.h
|
||||
|
||||
terrain.o : menu_terrain.h
|
||||
|
||||
snake : $(OFILES)
|
||||
$(CC) $(CFLAGS) -o snake $(OFILES) -lgraph
|
||||
|
||||
clean :
|
||||
-rm -f $(OFILES) snake
|
||||
|
||||
.PHONY : but clean
|
29
Makefile~
Normal file
29
Makefile~
Normal file
@ -0,0 +1,29 @@
|
||||
but : snake
|
||||
|
||||
OFILES = main.o \
|
||||
serpent.o \
|
||||
pastille.o \
|
||||
menu_terrain.o\
|
||||
temps_score.o
|
||||
|
||||
CC = gcc
|
||||
|
||||
CFLAGS = -Wall -ansi -pedantic -g
|
||||
|
||||
serpent.o : serpent.h menu_terrain.h temps_score.h
|
||||
|
||||
pastille.o : pastille.h menu_terrain.h serpent.h
|
||||
|
||||
main.o : serpent.h pastille.h temps_score.h menu_terrain.h
|
||||
|
||||
temps_score.o : temps_score.h
|
||||
|
||||
menu_terrain.o : menu_terrain.h
|
||||
|
||||
snake : $(OFILES)
|
||||
$(CC) $(CFLAGS) -o snake $(OFILES) -lgraph
|
||||
|
||||
clean :
|
||||
-rm -f $(OFILES) snake
|
||||
|
||||
.PHONY : but clean
|
@ -1,89 +0,0 @@
|
||||
#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();
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
#ifndef DEPLACEMENT_H
|
||||
#define DEPLACEMENT_H
|
||||
void input()
|
||||
void logique()
|
||||
|
||||
#endif /*DEPLACEMENT_H*/
|
110
main.c
Normal file
110
main.c
Normal file
@ -0,0 +1,110 @@
|
||||
#include <stdlib.h>
|
||||
#include <graph.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include "menu_terrain.h"
|
||||
#include "temps_score.h"
|
||||
#include "serpent.h"
|
||||
#include "pastille.h"
|
||||
#define CYCLE 1000000L
|
||||
#define MAX_LONGUEUR 100
|
||||
|
||||
|
||||
int main(){
|
||||
int rejouer;
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(350, 100, LARGEUR_FENETRE, HAUTEUR_FENETRE);
|
||||
srand(time(NULL));
|
||||
do{
|
||||
unsigned long suivant;
|
||||
unsigned int vitesse_serpent = VITESSE_INITIAL;
|
||||
int n = 0, minutes, secondes, score = 0, continuer;
|
||||
char texte[20];
|
||||
int nbr_pastille = 5, gameover, i, direction = 1, direction_avant = 1, longSerpent = TAILLE_SERPENT_INITIAL, max_longuer = MAX_LONGUEUR;
|
||||
Pastille *pomme = (Pastille *) malloc(nbr_pastille * sizeof(Pastille));
|
||||
Segment *serpent = (Segment *) malloc(MAX_LONGUEUR * sizeof(Segment));
|
||||
if (pomme == NULL || serpent == NULL)
|
||||
{
|
||||
printf("Erreur d'allocation de m<>moire.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
rejouer = 2;
|
||||
EffacerEcran(CouleurParNom("black"));
|
||||
Terrain();
|
||||
Creation_Serpent(serpent, longSerpent);
|
||||
Afficher_Serpent(serpent, longSerpent, direction);
|
||||
Creation_Pastille(NBR_PASTILLE_INITIAL, pomme, longSerpent, serpent);
|
||||
Afficher_Pastille(NBR_PASTILLE_INITIAL, pomme);
|
||||
do{
|
||||
gameover = 2;
|
||||
if (longSerpent >= MAX_LONGUEUR){
|
||||
serpent = (Segment*) realloc(serpent,(max_longuer+MAX_LONGUEUR));
|
||||
max_longuer += MAX_LONGUEUR;
|
||||
}
|
||||
/*Temps ecoul<75> debut*/
|
||||
if (Microsecondes() > suivant){
|
||||
suivant = Microsecondes() + CYCLE;
|
||||
n++;
|
||||
minutes = n / 60;
|
||||
secondes = n % 60;
|
||||
Afficher_Temps(minutes, secondes, texte);
|
||||
}
|
||||
/*Temps ecoul<75> fin */
|
||||
if (ToucheEnAttente()){
|
||||
switch (Touche()){
|
||||
case XK_Right:
|
||||
direction = 1;
|
||||
break;
|
||||
case XK_Left:
|
||||
direction = -1;
|
||||
break;
|
||||
case XK_Up:
|
||||
direction = 2;
|
||||
break;
|
||||
case XK_Down:
|
||||
direction = -2;
|
||||
break;
|
||||
case XK_space:
|
||||
continuer = 2;
|
||||
Pause(texte, minutes, secondes, score, &continuer);
|
||||
if (continuer == 0){
|
||||
FermerGraphique();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Afficher_Pastille(NBR_PASTILLE_INITIAL, pomme);
|
||||
Afficher_Serpent(serpent, longSerpent, direction);
|
||||
}
|
||||
}
|
||||
if (direction==direction_avant*(-1)){
|
||||
direction=direction_avant;
|
||||
}else{
|
||||
direction_avant=direction;
|
||||
}
|
||||
Deplacer_Serpent(&longSerpent, serpent, direction, vitesse_serpent);
|
||||
for (i = 0; i < NBR_PASTILLE_INITIAL; i++){
|
||||
/*Mise a zero du score*/
|
||||
ChoisirCouleurDessin(CouleurParNom("white"));
|
||||
sprintf(texte, "Score : %3d", score);
|
||||
EcrireTexte(825, 685, texte, 2);
|
||||
if (serpent[i].x == pomme[i].x && serpent[i].y == pomme[i].y)
|
||||
{
|
||||
longSerpent += 2;
|
||||
Validation_Coordonne( NBR_PASTILLE_INITIAL, pomme, longSerpent, serpent, &pomme[i]);
|
||||
score = score + 5;
|
||||
if (score % 40 == 0 && vitesse_serpent > 10U){
|
||||
vitesse_serpent -= 5U;
|
||||
}
|
||||
Afficher_Pastille(NBR_PASTILLE_INITIAL, pomme);
|
||||
Afficher_Score(score, texte);
|
||||
}
|
||||
}
|
||||
Contoure_Terrain();
|
||||
Mort_Serpent( longSerpent, serpent, score, minutes, secondes, texte, &rejouer, &gameover);
|
||||
}while (gameover);
|
||||
free(pomme);
|
||||
free(serpent);
|
||||
}while(rejouer);
|
||||
|
||||
FermerGraphique();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
11
makefile
11
makefile
@ -1,11 +0,0 @@
|
||||
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
|
86
menu_terrain.c
Normal file
86
menu_terrain.c
Normal file
@ -0,0 +1,86 @@
|
||||
#include <stdlib.h>
|
||||
#include <graph.h>
|
||||
#include <stdio.h>
|
||||
#include "menu_terrain.h"
|
||||
|
||||
/*Fonction initialisant le terrain de jeux*/
|
||||
void Terrain(){
|
||||
int i, j;
|
||||
|
||||
for (i = CONTOURE_H; i < LIGNES + CONTOURE_H; i++)
|
||||
{
|
||||
for (j = CONTOURE_L; j < COLONNES + CONTOURE_L; j++){
|
||||
ChoisirCouleurDessin(CouleurParComposante(0, 217, 87));
|
||||
RemplirRectangle(j * TAILLE_CASE, i * TAILLE_CASE, TAILLE_CASE, TAILLE_CASE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*Fonction dessinnant la bordure du terrain en noir pour enlever les block vert qui apparaissent*/
|
||||
void Contoure_Terrain(){
|
||||
int i, j;
|
||||
for (i = 0; i < CONTOURE_H; i++){
|
||||
for (j = 0; j < COLONNES; j++){
|
||||
ChoisirCouleurDessin(CouleurParNom("black"));
|
||||
RemplirRectangle(j * TAILLE_CASE, i * TAILLE_CASE, TAILLE_CASE, TAILLE_CASE);
|
||||
}
|
||||
}
|
||||
for (j = 0; j < CONTOURE_L; j++){
|
||||
for (i = 0; i < LIGNES; i++){
|
||||
ChoisirCouleurDessin(CouleurParNom("black"));
|
||||
RemplirRectangle(j * TAILLE_CASE, i * TAILLE_CASE, TAILLE_CASE, TAILLE_CASE);
|
||||
}
|
||||
}
|
||||
for (j = COLONNES + CONTOURE_L; j < CONTOURE_L; j++){
|
||||
for (i = 0; i < LIGNES; i++){
|
||||
ChoisirCouleurDessin(CouleurParNom("black"));
|
||||
RemplirRectangle(j * TAILLE_CASE, i * TAILLE_CASE, TAILLE_CASE, TAILLE_CASE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*Fonction qui affiche le menu pause*/
|
||||
void Pause(char* texte, int minutes, int secondes, int score, int* continuer){
|
||||
EcrireTexte(10,10,"pause !",2);
|
||||
while(*continuer == 2){
|
||||
if (ToucheEnAttente()){
|
||||
switch(Touche()){
|
||||
case XK_space :
|
||||
*continuer = 1;
|
||||
break;
|
||||
case XK_Escape :
|
||||
*continuer = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Terrain();
|
||||
}
|
||||
|
||||
/*Fonction qui affiche le menu perdu*/
|
||||
void Perdu(char *texte, int score, int minutes, int secondes, int* rejouer)
|
||||
{
|
||||
EffacerEcran(CouleurParNom("black"));
|
||||
EcrireTexte(10,100,"Perdu",2);
|
||||
/*Afficher le score sur l'image*/
|
||||
ChoisirCouleurDessin(CouleurParNom("black"));
|
||||
sprintf(texte, "%3d", score);
|
||||
EcrireTexte(550, 420, texte, 2);
|
||||
/*affichage du timer au menu*/
|
||||
sprintf(texte, "%02d:%02d", minutes, secondes);
|
||||
EcrireTexte(550, 485, texte, 2);
|
||||
while(*rejouer == 2){
|
||||
if (ToucheEnAttente()){
|
||||
switch(Touche()){
|
||||
case XK_Return :
|
||||
*rejouer = 1;
|
||||
break;
|
||||
case XK_Escape :
|
||||
*rejouer = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
18
menu_terrain.h~
Normal file
18
menu_terrain.h~
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef MENU_TERRAIN_H
|
||||
#define MENU_TERRAIN_H
|
||||
|
||||
void Terrain();
|
||||
void Contoure_Terrain();
|
||||
void Start(int* jouer);
|
||||
void Pause(char* texte, int minutes, int secondes, int score, int* continuer);
|
||||
void Perdu(char *texte, int score, int minutes, int secondes, int* rejouer);
|
||||
|
||||
#define LARGEUR_FENETRE 1050
|
||||
#define HAUTEUR_FENETRE 750
|
||||
#define TAILLE_CASE 15
|
||||
#define COLONNES 60
|
||||
#define LIGNES 40
|
||||
#define CONTOURE_H 2
|
||||
#define CONTOURE_L 5
|
||||
|
||||
#endif /* MENU_TERRAIN_H */
|
BIN
menu_terrain.o
Normal file
BIN
menu_terrain.o
Normal file
Binary file not shown.
17
pastille.h~
Normal file
17
pastille.h~
Normal file
@ -0,0 +1,17 @@
|
||||
#include "serpent.h"
|
||||
#ifndef PASTILLE_H
|
||||
#define PASTILLE_H
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} Pastille;
|
||||
|
||||
void Creation_Pastille(int z, Pastille pomme[], int longSerpent, Segment serpent[]);
|
||||
void Afficher_Pastille(int z, Pastille pomme[]);
|
||||
void Validation_Coordonne(int z, Pastille pomme[], int longSerpent, Segment serpent[], Pastille* nouvelle_pomme);
|
||||
|
||||
#define NBR_PASTILLE_INITIAL 5
|
||||
|
||||
#endif /* PASTILLE_H */
|
BIN
pastille.o
Normal file
BIN
pastille.o
Normal file
Binary file not shown.
102
pomme.c
102
pomme.c
@ -1,58 +1,54 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <graph.h>
|
||||
#define delta 1000000L
|
||||
|
||||
void DessinerScene(int sprite,int x,int y,int n)
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include "pomme.h"
|
||||
#include "terrain.h"
|
||||
#include "serpent.h"
|
||||
|
||||
/*Fonction permettant l'initialisation d'un nombre donnée en parametre de pastille*/
|
||||
void Creation_Pastille(int nombre, Pastille pomme[], int longSerpent, Segment serpent[])
|
||||
{
|
||||
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 i;
|
||||
for (i = 0; i < nombre; i++)
|
||||
{
|
||||
pomme[i].x = rand() % (COLONNES) * TAILLE_CASE + CONTOURE_L * TAILLE_CASE;
|
||||
pomme[i].y = rand() % (LIGNES) * TAILLE_CASE + (CONTOURE_H * TAILLE_CASE);
|
||||
Validation_Coordonne( i, pomme, longSerpent, serpent, &pomme[i]);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
/*Fonction validant les coordonnées des pastilles*/
|
||||
void Validation_Coordonne(int nombre, Pastille pomme[], int longSerpent, Segment serpent[], Pastille* nouvelle_pomme){
|
||||
int coordonee_ok, j;
|
||||
Pastille pastilles;
|
||||
do{
|
||||
coordonee_ok = 0;
|
||||
pastilles.x = (rand() % COLONNES) * TAILLE_CASE + (CONTOURE_L * TAILLE_CASE);
|
||||
pastilles.y = (rand() % LIGNES) * TAILLE_CASE + (CONTOURE_H * TAILLE_CASE);
|
||||
for (j = 0; j < longSerpent; j++){
|
||||
if (nouvelle_pomme->x == serpent[j].x && pomme->y == serpent[j].y){
|
||||
coordonee_ok = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (coordonee_ok == 0){
|
||||
for (j = 0; j < nombre; j++){
|
||||
if (nouvelle_pomme->x == pomme[j].x && nouvelle_pomme-> y== pomme[j].y){
|
||||
coordonee_ok = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}while (coordonee_ok);
|
||||
nouvelle_pomme->x =pastilles.x;
|
||||
nouvelle_pomme->y =pastilles.y;
|
||||
}
|
||||
|
||||
/*Fonction permettant l'affichage d'un nombre donnée de pastilles*/
|
||||
void Afficher_Pastille(int n,Pastille pomme[]){
|
||||
int i;
|
||||
for (i = 0; i < n;i++){
|
||||
ChargerImage("pomme.png", pomme[i].x, pomme[i].y, 26,26, TAILLE_CASE, TAILLE_CASE);
|
||||
}
|
||||
}
|
17
pomme.h
Normal file
17
pomme.h
Normal file
@ -0,0 +1,17 @@
|
||||
#include "serpent.h"
|
||||
#ifndef PASTILLE_H
|
||||
#define PASTILLE_H
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} Pastille;
|
||||
|
||||
void Creation_Pastille(int z, Pastille pomme[], int longSerpent, Segment serpent[]);
|
||||
void Afficher_Pastille(int z, Pastille pomme[]);
|
||||
void Validation_Coordonne(int z, Pastille pomme[], int longSerpent, Segment serpent[], Pastille* nouvelle_pomme);
|
||||
|
||||
#define NBR_PASTILLE_INITIAL 5
|
||||
|
||||
#endif /* PASTILLE_H */
|
BIN
pomme.png
BIN
pomme.png
Binary file not shown.
Before Width: | Height: | Size: 636 B After Width: | Height: | Size: 4.3 KiB |
124
serpent.c
124
serpent.c
@ -1,58 +1,76 @@
|
||||
#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);
|
||||
#include <stdio.h>
|
||||
#include "serpent.h"
|
||||
#include "terrain.h"
|
||||
#include "temps_et_score.h"
|
||||
|
||||
/*Fonction permettant de créer un serpent de base avec une taille donnée*/
|
||||
void Creation_Serpent(Segment serpent[], int taille){
|
||||
int i;
|
||||
for (i = 0; i < taille; i++)
|
||||
{
|
||||
serpent[i].x = (COLONNES / 2) * TAILLE_CASE;
|
||||
serpent[i].y = (LIGNES / 2) * TAILLE_CASE;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
|
||||
/*Fonction permettant d'afficher le serpent avec une taille donnée*/
|
||||
void Afficher_Serpent(Segment serpent[], int taille, int rotation)
|
||||
{
|
||||
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();
|
||||
int i;
|
||||
ChoisirCouleurDessin(CouleurParComposante(252, 220, 17));
|
||||
for(i=0; i<taille; i++) {
|
||||
RemplirRectangle(serpent[i].x, serpent[i].y, TAILLE_CASE, TAILLE_CASE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*Fonction permettant au serpent de se déplacer*/
|
||||
void Deplacer_Serpent(int *longSerpent, Segment serpent[], int direction, unsigned int vitesse_serpent){
|
||||
int i;
|
||||
ChoisirCouleurDessin(CouleurParComposante(0, 217, 87));
|
||||
RemplirRectangle(serpent[*longSerpent-1].x, serpent[*longSerpent-1].y, TAILLE_CASE, TAILLE_CASE);
|
||||
for (i = *longSerpent - 1; i > 0; i--)
|
||||
{
|
||||
serpent[i] = serpent[i - 1];
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case 1:
|
||||
serpent[0].x += TAILLE_CASE;
|
||||
break;
|
||||
case -1:
|
||||
serpent[0].x -= TAILLE_CASE;
|
||||
break;
|
||||
case 2:
|
||||
serpent[0].y -= TAILLE_CASE;
|
||||
break;
|
||||
case -2:
|
||||
serpent[0].y += TAILLE_CASE;
|
||||
break;
|
||||
}
|
||||
Afficher_Serpent(serpent, *longSerpent, direction);
|
||||
Attendre(vitesse_serpent);
|
||||
}
|
||||
|
||||
/*Fonction l'emplacement de la tête du serpent pour la mort*/
|
||||
void Mort_Serpent(int longSerpent, Segment serpent[], int score, int minutes, int secondes, char texte[], int* rejouer, int* gameover){
|
||||
int i;
|
||||
if (serpent[0].x < 5 * TAILLE_CASE || serpent[0].x >= (COLONNES * TAILLE_CASE) + 5 * TAILLE_CASE || serpent[0].y < CONTOURE_H * TAILLE_CASE || serpent[0].y >= (LIGNES * TAILLE_CASE) + 2 * TAILLE_CASE){
|
||||
ChoisirCouleurDessin(CouleurParNom("black"));
|
||||
RemplirRectangle(serpent[0].x, serpent[0].y, TAILLE_CASE, TAILLE_CASE);
|
||||
Attendre(1000);
|
||||
*gameover = 0;
|
||||
/*Execution de la fontion perdu*/
|
||||
Perdu(texte, score, minutes, secondes, rejouer);
|
||||
}
|
||||
for (i = 1; i < longSerpent; i++){
|
||||
if (serpent[0].x == serpent[i].x && serpent[0].y == serpent[i].y){
|
||||
Attendre(1000);
|
||||
*gameover = 0;
|
||||
Perdu(texte, score, minutes, secondes, rejouer);
|
||||
}
|
||||
}
|
||||
}
|
19
serpent.h
19
serpent.h
@ -1,5 +1,20 @@
|
||||
#ifndef SERPENT_H
|
||||
#define SERPENT_H
|
||||
void DessinerScene(int sprite,int x,int y,int n)
|
||||
|
||||
#endif /*SERPENT_H */
|
||||
typedef struct
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} Segment;
|
||||
|
||||
|
||||
void Creation_Serpent(Segment serpent[], int taille);
|
||||
void Afficher_Serpent(Segment serpent[], int taille, int rotation);
|
||||
void Deplacer_Serpent(int *longSerpent, Segment serpent[], int direction, unsigned int vitesse_serpent);
|
||||
void Mort_Serpent(int longSerpent, Segment serpent[], int score, int minutes, int secondes, char texte[], int* rejouer, int* gameover);
|
||||
|
||||
|
||||
#define TAILLE_SERPENT_INITIAL 10
|
||||
#define VITESSE_INITIAL 70U
|
||||
|
||||
#endif /* SERPENT_H */
|
||||
|
21
serpent.h~
21
serpent.h~
@ -1,7 +1,20 @@
|
||||
#ifndef SERPENT_H
|
||||
#define SERPENT_H
|
||||
void DessinerScene(int sprite,int x,int y,int n)
|
||||
int main()
|
||||
int serpent;
|
||||
|
||||
#endif /*SERPENT_H */
|
||||
typedef struct
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} Segment;
|
||||
|
||||
|
||||
void Creation_Serpent(Segment serpent[], int taille);
|
||||
void Afficher_Serpent(Segment serpent[], int taille, int rotation);
|
||||
void Deplacer_Serpent(int *longSerpent, Segment serpent[], int direction, unsigned int vitesse_serpent);
|
||||
void Mort_Serpent(int longSerpent, Segment serpent[], int score, int minutes, int secondes, char texte[], int* rejouer, int* gameover);
|
||||
|
||||
|
||||
#define TAILLE_SERPENT_INITIAL 10
|
||||
#define VITESSE_INITIAL 70U
|
||||
|
||||
#endif /* SERPENT_H */
|
||||
|
29
temps_et_score.c
Normal file
29
temps_et_score.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include <stdlib.h>
|
||||
#include <graph.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "temps_et_score.h"
|
||||
|
||||
void Attendre(unsigned int millisecondes){
|
||||
unsigned long debut = Microsecondes();
|
||||
unsigned long attente = millisecondes * 1000;
|
||||
while (Microsecondes() - debut < attente){
|
||||
}
|
||||
}
|
||||
|
||||
void Afficher_Temps(int minutes, int secondes, char texte[]){
|
||||
ChoisirCouleurDessin(CouleurParNom("black"));
|
||||
RemplirRectangle(75, 650, 250, 40);
|
||||
ChoisirCouleurDessin(CouleurParNom("white"));
|
||||
sprintf(texte, "Temps : %02d : %02d", minutes, secondes);
|
||||
EcrireTexte(85, 685, texte, 2);
|
||||
}
|
||||
|
||||
void Afficher_Score(int score, char texte[]){
|
||||
ChoisirCouleurDessin(CouleurParNom("black"));
|
||||
RemplirRectangle(825, 655, 150, 40);
|
||||
ChoisirCouleurDessin(CouleurParNom("white"));
|
||||
sprintf(texte, "Score : %3d", score);
|
||||
EcrireTexte(825, 685, texte, 2);
|
||||
}
|
||||
|
8
temps_et_score.h
Normal file
8
temps_et_score.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef TEMPS_SCORE_H
|
||||
#define TEMPS_SCORE_H
|
||||
|
||||
void Attendre(unsigned int millisecondes);
|
||||
void Afficher_Temps(int minutes, int secondes, char texte[]);
|
||||
void Afficher_Score(int score, char texte[]);
|
||||
|
||||
#endif /* TEMPS_SCORE_H */
|
8
temps_score.h~
Normal file
8
temps_score.h~
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef TEMPS_SCORE_H
|
||||
#define TEMPS_SCORE_H
|
||||
|
||||
void Attendre(unsigned int millisecondes);
|
||||
void Afficher_Temps(int minutes, int secondes, char texte[]);
|
||||
void Afficher_Score(int score, char texte[]);
|
||||
|
||||
#endif /* TEMPS_SCORE_H */
|
BIN
temps_score.o
Normal file
BIN
temps_score.o
Normal file
Binary file not shown.
94
terrain.c
94
terrain.c
@ -1,16 +1,86 @@
|
||||
|
||||
#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;
|
||||
#include <stdio.h>
|
||||
#include "terrain.h"
|
||||
|
||||
/*Fonction initialisant le terrain de jeux*/
|
||||
void Terrain(){
|
||||
int i, j;
|
||||
|
||||
for (i = CONTOURE_H; i < LIGNES + CONTOURE_H; i++)
|
||||
{
|
||||
for (j = CONTOURE_L; j < COLONNES + CONTOURE_L; j++){
|
||||
ChoisirCouleurDessin(CouleurParComposante(0, 217, 87));
|
||||
RemplirRectangle(j * TAILLE_CASE, i * TAILLE_CASE, TAILLE_CASE, TAILLE_CASE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*Fonction dessinnant la bordure du terrain en noir pour enlever les block vert qui apparaissent*/
|
||||
void Contoure_Terrain(){
|
||||
int i, j;
|
||||
for (i = 0; i < CONTOURE_H; i++){
|
||||
for (j = 0; j < COLONNES; j++){
|
||||
ChoisirCouleurDessin(CouleurParNom("black"));
|
||||
RemplirRectangle(j * TAILLE_CASE, i * TAILLE_CASE, TAILLE_CASE, TAILLE_CASE);
|
||||
}
|
||||
}
|
||||
for (j = 0; j < CONTOURE_L; j++){
|
||||
for (i = 0; i < LIGNES; i++){
|
||||
ChoisirCouleurDessin(CouleurParNom("black"));
|
||||
RemplirRectangle(j * TAILLE_CASE, i * TAILLE_CASE, TAILLE_CASE, TAILLE_CASE);
|
||||
}
|
||||
}
|
||||
for (j = COLONNES + CONTOURE_L; j < CONTOURE_L; j++){
|
||||
for (i = 0; i < LIGNES; i++){
|
||||
ChoisirCouleurDessin(CouleurParNom("black"));
|
||||
RemplirRectangle(j * TAILLE_CASE, i * TAILLE_CASE, TAILLE_CASE, TAILLE_CASE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*Fonction qui affiche le menu pause*/
|
||||
void Pause(char* texte, int minutes, int secondes, int score, int* continuer){
|
||||
EcrireTexte(10,10,"pause !",2);
|
||||
while(*continuer == 2){
|
||||
if (ToucheEnAttente()){
|
||||
switch(Touche()){
|
||||
case XK_space :
|
||||
*continuer = 1;
|
||||
break;
|
||||
case XK_Escape :
|
||||
*continuer = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Terrain();
|
||||
}
|
||||
|
||||
/*Fonction qui affiche le menu perdu*/
|
||||
void Perdu(char *texte, int score, int minutes, int secondes, int* rejouer)
|
||||
{
|
||||
EffacerEcran(CouleurParNom("black"));
|
||||
EcrireTexte(10,100,"Perdu",2);
|
||||
/*Afficher le score sur l'image*/
|
||||
ChoisirCouleurDessin(CouleurParNom("black"));
|
||||
sprintf(texte, "%3d", score);
|
||||
EcrireTexte(550, 420, texte, 2);
|
||||
/*affichage du timer au menu*/
|
||||
sprintf(texte, "%02d:%02d", minutes, secondes);
|
||||
EcrireTexte(550, 485, texte, 2);
|
||||
while(*rejouer == 2){
|
||||
if (ToucheEnAttente()){
|
||||
switch(Touche()){
|
||||
case XK_Return :
|
||||
*rejouer = 1;
|
||||
break;
|
||||
case XK_Escape :
|
||||
*rejouer = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
21
terrain.h
21
terrain.h
@ -1,5 +1,18 @@
|
||||
#ifndef TERRAIN_H
|
||||
#define TERRAIN_H
|
||||
int main(void)
|
||||
#ifndef MENU_TERRAIN_H
|
||||
#define MENU_TERRAIN_H
|
||||
|
||||
#endif /* TERRAIN_H */
|
||||
void Terrain();
|
||||
void Contoure_Terrain();
|
||||
void Start(int* jouer);
|
||||
void Pause(char* texte, int minutes, int secondes, int score, int* continuer);
|
||||
void Perdu(char *texte, int score, int minutes, int secondes, int* rejouer);
|
||||
|
||||
#define LARGEUR_FENETRE 1050
|
||||
#define HAUTEUR_FENETRE 750
|
||||
#define TAILLE_CASE 15
|
||||
#define COLONNES 60
|
||||
#define LIGNES 40
|
||||
#define CONTOURE_H 2
|
||||
#define CONTOURE_L 5
|
||||
|
||||
#endif /* MENU_TERRAIN_H */
|
||||
|
BIN
terrain.png
Normal file
BIN
terrain.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
Loading…
Reference in New Issue
Block a user