Réorganisation des dossiers et de l'emplacement des fichiers pour permettre la compilation par n'importe quelle machine

This commit is contained in:
Yann KERAUDREN 2023-11-30 14:48:19 +01:00
parent adcf884a33
commit a68fef55e8
3 changed files with 197 additions and 0 deletions

26
snake/Makefile Normal file

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

95
snake/fenetre.c Normal file

@ -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 <stdlib.h>
#include <graph.h>
#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;
}

76
snake/plateau_init.c Normal file

@ -0,0 +1,76 @@
/* Création du plateau de jeu avec les pastilles et le serpent
written by Yann KERAUDREN and Titouan LERICHE*/
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#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;
}