From a68fef55e86315a84bf5ce5c92cf2840de93dccf Mon Sep 17 00:00:00 2001 From: keraudre Date: Thu, 30 Nov 2023 14:48:19 +0100 Subject: [PATCH] =?UTF-8?q?R=C3=A9organisation=20des=20dossiers=20et=20de?= =?UTF-8?q?=20l'emplacement=20des=20fichiers=20pour=20permettre=20la=20com?= =?UTF-8?q?pilation=20par=20n'importe=20quelle=20machine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snake/Makefile | 26 ++++++++++++ snake/fenetre.c | 95 ++++++++++++++++++++++++++++++++++++++++++++ snake/plateau_init.c | 76 +++++++++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+) create mode 100644 snake/Makefile create mode 100644 snake/fenetre.c create mode 100644 snake/plateau_init.c diff --git a/snake/Makefile b/snake/Makefile new file mode 100644 index 0000000..e1ffbad --- /dev/null +++ b/snake/Makefile @@ -0,0 +1,26 @@ +#Snake : fichier Makefile + +#BUT FINAL + +but : snake + +#VARIABLES + +OFILES = plateau_init.o \ + fenetre.o \ + main.o + +CC = gcc + +CFLAGS = -ansi - pedantic -lgraph + +#DEPENDANCES (REGLES IMPLICITES) + +plateau_init.o : plateau_init.h + +fenetre.o : fenetre.h plateau_init.h + +main.o : fenetre.h + + +#DEPENDANCES AVEC COMMANDES diff --git a/snake/fenetre.c b/snake/fenetre.c new file mode 100644 index 0000000..3846a4d --- /dev/null +++ b/snake/fenetre.c @@ -0,0 +1,95 @@ +/* Affichage de la fenêtre de jeu avec plateau de jeu, temps écoulé, score, actions des touches + + written by Yann KERAUDREN and Titouan LERICHE */ + + +#include +#include +#include "plateau_init.c" + + +int main (void) { + + couleur green, grey, yellow, red, black; + + int** tableau = plateau_init(); + + int i, j; + + + InitialiserGraphique(); + CreerFenetre(10,10,1450,840); + + + /* remplisage du fond d'écran */ + + grey = CouleurParComposante(35,35,35); + ChoisirCouleurDessin(grey); + RemplirRectangle(0,0,1450,840); + + /* affichage des contours */ + black = CouleurParComposante(0,0,0); + ChoisirCouleurDessin(black); + RemplirRectangle( 17, 17, 1206, 3); + + RemplirRectangle( 17, 17, 3, 806); + + RemplirRectangle( 17, 820, 1206, 3); + + RemplirRectangle( 1220, 17, 3, 806); + + + /* remplissage du plateau de jeux avec les couleur adéquate */ + + + for (i = 0; i < LIGNES; i++) { + for (j = 0; j < COLONNES; j++) { + + if ( tableau[i][j] == 0) { + + green = CouleurParComposante(50,205,50); + ChoisirCouleurDessin(green); + RemplirRectangle(20*(j+1),20*(i+1),20,20); + + } + if ( tableau[i][j] == 1) { + + yellow = CouleurParComposante(255,255,0); + ChoisirCouleurDessin(yellow); + RemplirRectangle(20*(j+1),20*(i+1),20,20); + + } + + if ( tableau[i][j] == 2) { + + red = CouleurParComposante(255,0,0); + ChoisirCouleurDessin(red); + RemplirRectangle(20*(j+1),20*(i+1),20,20); + } + + } + } + + + + /* déallocation du tableau */ + + for ( i = 0; i < LIGNES; i++) { + + free(tableau[i]); + + } + free(tableau); + + + + + + Touche(); + FermerGraphique(); + + + + return EXIT_SUCCESS; + +} diff --git a/snake/plateau_init.c b/snake/plateau_init.c new file mode 100644 index 0000000..ba8b75a --- /dev/null +++ b/snake/plateau_init.c @@ -0,0 +1,76 @@ +/* Création du plateau de jeu avec les pastilles et le serpent + + written by Yann KERAUDREN and Titouan LERICHE*/ + + +#include +#include +#include +#define LIGNES 40 +#define COLONNES 60 +#define NBR_POMME 5 +#define TAILLE_SERPENT 10 + +int** plateau_init(void) { + + int ligne_pomme, colonne_pomme, i; + + int** tableau = NULL; + + + srand(time(NULL)); + + + /* allocation du tableau dans le tas */ + + tableau = calloc(LIGNES, sizeof(double)); + + for ( i = 0; i < LIGNES; i++) { + + tableau[i] = calloc(COLONNES, sizeof(int)); + + } + + + /* positionnement du serpent */ + + for (i = 0; i < TAILLE_SERPENT; i++) { + + tableau[((LIGNES/2)-5)+i][COLONNES/2] = 1; + + } + + + + + /* positionnement alétoire des pommes */ + + for ( i = 0; i < NBR_POMME; i++) { + + + ligne_pomme = rand() % 40; + colonne_pomme = rand() % 60; + + + /* teste pour faire apparaitre exactement 5 pommes */ + + while (tableau[ligne_pomme][colonne_pomme] == 2) { + + ligne_pomme = rand() % 40; + colonne_pomme = rand() % 60; + + } + + + /* le chiffre "2" definit une pomme */ + + tableau[ligne_pomme][colonne_pomme] = 2; + + } + + + + + + return tableau; +}