Skip to content
Snippets Groups Projects
Commit f0797b61 authored by MOSA SAMY's avatar MOSA SAMY
Browse files

Ajout Doxygen : Noms de fichiers

parent 768c6b50
Branches
No related merge requests found
/**
* \file grille.c
* code pour les grilles
* \author Samy MOSA
*/
#include "grille.h"
void init_grille_from_file(char *filename, grille *g)
......
/**
* \file grille.h
* header pour les grilles
* \author Samy MOSA
*/
#ifndef __GRILLE_H
#define __GRILLE_H
......@@ -6,25 +12,30 @@
#include <assert.h>
// structure grille : nombre de lignes, nombre de colonnes, tableau de tableau de cellules
typedef struct {int nbl; int nbc; int** cellules;} grille;
typedef struct
{
int nbl;
int nbc;
int **cellules;
} grille;
// alloue une grille de taille l*c, et initialise toutes les cellules à mortes
void alloue_grille (int l, int c, grille* g);
void alloue_grille(int l, int c, grille *g);
// libère une grille
void libere_grille (grille* g);
void libere_grille(grille *g);
// alloue et initalise la grille g à partir d'un fichier
void init_grille_from_file (char * filename, grille* g);
void init_grille_from_file(char *filename, grille *g);
// rend vivante la cellule (i,j) de la grille g
static inline void set_vivante(int i, int j, grille g){g.cellules[i][j] = 1;}
static inline void set_vivante(int i, int j, grille g) { g.cellules[i][j] = 1; }
// rend morte la cellule (i,j) de la grille g
static inline void set_morte(int i, int j, grille g){g.cellules[i][j] = 0;}
static inline void set_morte(int i, int j, grille g) { g.cellules[i][j] = 0; }
// teste si la cellule (i,j) de la grille g est vivante
static inline int est_vivante(int i, int j, grille g){return g.cellules[i][j] == 1;}
static inline int est_vivante(int i, int j, grille g) { return g.cellules[i][j] == 1; }
// recopie gs dans gd (sans allocation)
void copie_grille (grille gs, grille gd);
void copie_grille(grille gs, grille gd);
#endif
/**
* \file io.c
* code pour les I/O (entrées/sorties)
* \author Samy MOSA
*/
#include "io.h"
void affiche_trait (int c){
void affiche_trait(int c)
{
int i;
for (i=0; i<c; ++i) printf ("|---");
for (i = 0; i < c; ++i)
printf("|---");
printf("|\n");
return;
}
void affiche_ligne (int c, int* ligne){
void affiche_ligne(int c, int *ligne)
{
int i;
for (i=0; i<c; ++i)
if (ligne[i] == 0 ) printf ("| "); else printf ("| O ");
for (i = 0; i < c; ++i)
if (ligne[i] == 0)
printf("| ");
else
printf("| O ");
printf("|\n");
return;
}
void affiche_grille (grille g){
int i, l=g.nbl, c=g.nbc;
void affiche_grille(grille g)
{
int i, l = g.nbl, c = g.nbc;
printf("\n");
affiche_trait(c);
for (i=0; i<l; ++i) {
for (i = 0; i < l; ++i)
{
affiche_ligne(c, g.cellules[i]);
affiche_trait(c);
}
printf("\n");
}
printf("\n");
return;
}
void efface_grille (grille g){
printf("\n\e[%dA",g.nbl*2 + 5);
void efface_grille(grille g)
{
printf("\n\e[%dA", g.nbl * 2 + 5);
}
void debut_jeu(grille *g, grille *gc){
char c = getchar();
void debut_jeu(grille *g, grille *gc)
{
char c = getchar();
while (c != 'q') // touche 'q' pour quitter
{
switch (c) {
case '\n' :
{ // touche "entree" pour évoluer
evolue(g,gc);
efface_grille(*g);
affiche_grille(*g);
break;
}
default :
{ // touche non traitée
printf("\n\e[1A");
break;
}
{
switch (c)
{
case '\n':
{ // touche "entree" pour évoluer
evolue(g, gc);
efface_grille(*g);
affiche_grille(*g);
break;
}
c = getchar();
default:
{ // touche non traitée
printf("\n\e[1A");
break;
}
}
c = getchar();
}
return;
return;
}
......@@ -2,20 +2,26 @@
#define __IO_H
#include <stdio.h>
/**
* \file io.h
* header pour les I/O (entrées/sorties)
* \author Samy MOSA
*/
#include "grille.h"
#include "jeu.h"
// affichage d'un trait horizontal
void affiche_trait (int c);
void affiche_trait(int c);
// affichage d'une ligne de la grille
void affiche_ligne (int c, int* ligne);
void affiche_ligne(int c, int *ligne);
// affichage d'une grille
void affiche_grille (grille g);
void affiche_grille(grille g);
// effacement d'une grille
void efface_grille (grille g);
void efface_grille(grille g);
// debute le jeu
void debut_jeu(grille *g, grille *gc);
......
/**
* \file jeu.c
* code pour le jeu
* \author Samy MOSA
*/
#include "jeu.h"
int compte_voisins_vivants (int i, int j, grille g){
int v = 0, l=g.nbl, c = g.nbc;
v+= est_vivante(modulo(i-1,l),modulo(j-1,c),g);
v+= est_vivante(modulo(i-1,l),modulo(j,c),g);
v+= est_vivante(modulo(i-1,l),modulo(j+1,c),g);
v+= est_vivante(modulo(i,l),modulo(j-1,c),g);
v+= est_vivante(modulo(i,l),modulo(j+1,c),g);
v+= est_vivante(modulo(i+1,l),modulo(j-1,c),g);
v+= est_vivante(modulo(i+1,l),modulo(j,c),g);
v+= est_vivante(modulo(i+1,l),modulo(j+1,c),g);
int compte_voisins_vivants(int i, int j, grille g)
{
int v = 0, l = g.nbl, c = g.nbc;
v += est_vivante(modulo(i - 1, l), modulo(j - 1, c), g);
v += est_vivante(modulo(i - 1, l), modulo(j, c), g);
v += est_vivante(modulo(i - 1, l), modulo(j + 1, c), g);
v += est_vivante(modulo(i, l), modulo(j - 1, c), g);
v += est_vivante(modulo(i, l), modulo(j + 1, c), g);
v += est_vivante(modulo(i + 1, l), modulo(j - 1, c), g);
v += est_vivante(modulo(i + 1, l), modulo(j, c), g);
v += est_vivante(modulo(i + 1, l), modulo(j + 1, c), g);
return v;
return v;
}
void evolue (grille *g, grille *gc){
copie_grille (*g,*gc); // copie temporaire de la grille
int i,j,l=g->nbl, c = g->nbc,v;
for (i=0; i<l; i++)
void evolue(grille *g, grille *gc)
{
copie_grille(*g, *gc); // copie temporaire de la grille
int i, j, l = g->nbl, c = g->nbc, v;
for (i = 0; i < l; i++)
{
for (j=0; j<c; ++j)
for (j = 0; j < c; ++j)
{
v = compte_voisins_vivants (i, j, *gc);
if (est_vivante(i,j,*g))
v = compte_voisins_vivants(i, j, *gc);
if (est_vivante(i, j, *g))
{ // evolution d'une cellule vivante
if ( v!=2 && v!= 3 ) set_morte(i,j,*g);
if (v != 2 && v != 3)
set_morte(i, j, *g);
}
else
else
{ // evolution d'une cellule morte
if ( v==3 ) set_vivante(i,j,*g);
if (v == 3)
set_vivante(i, j, *g);
}
}
}
......
/**
* \file jeu.h
* header pour le jeu
* \author Samy MOSA
*/
#ifndef __JEU_H
#define __JEU_H
......
/**
* \file main.c
* code principal
* \author Samy MOSA
*/
#include <stdio.h>
#include "grille.h"
#include "io.h"
#include "jeu.h"
int main (int argc, char ** argv) {
if (argc != 2 )
int main(int argc, char **argv)
{
if (argc != 2)
{
printf("usage : main <fichier grille>");
return 1;
}
grille g, gc;
init_grille_from_file(argv[1],&g);
alloue_grille (g.nbl, g.nbc, &gc);
init_grille_from_file(argv[1], &g);
alloue_grille(g.nbl, g.nbc, &gc);
affiche_grille(g);
debut_jeu(&g, &gc);
libere_grille(&g);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment