From 3e84113c421998901b0c600e86b596dfd71c30f5 Mon Sep 17 00:00:00 2001 From: ColinDrieu <colin.drieu@insa-rennes.fr> Date: Mon, 11 Apr 2016 18:34:05 +0200 Subject: [PATCH] Debut du code du controleur. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajout de controleur.h et controleur.c et code de quelques fonctions. Ajout de affichageConsole2.c et affichageConsole2.h pour separer l'affichage du moteur du jeu (pas d'appel aux données dans ces deux fichiers) Correction des erreurs de compilation dans AffichageConsole.c Ajout d'une fonction permettant d'obtenir une case d'après ses coordonnées dans case.c Mise à jour de structure.h partie.c et partie.h, une partie possede maintenant un attribut Carte. Ajout de mainPartieConsole.c : pour l'instant ce fichier est juste là pour se retrouver dans l'appel aux fonctions du controleur Mise à jour du projet codeblocks : il devrait normalement permettre de compiler le projet sans erreurs. --- .../ElderInternalIgnition.cbp | 1 + src/AffichageConsole.c | 24 +++----- src/AffichageConsole.h | 9 +-- src/affichageConsole2.c | 47 +++++++++++++++ src/affichageConsole2.h | 14 +++++ src/case.c | 24 +++++++- src/case.h | 5 +- src/controleur.c | 57 +++++++++++++++++++ src/controleur.h | 16 ++++++ src/controlleur.c | 1 + src/mainPartieConsole.c | 16 ++++++ src/partie.c | 35 +++++++++++- src/partie.h | 2 + src/structures.h | 5 ++ 14 files changed, 227 insertions(+), 29 deletions(-) create mode 100644 src/affichageConsole2.c create mode 100644 src/affichageConsole2.h create mode 100644 src/controleur.c create mode 100644 src/controleur.h create mode 100644 src/controlleur.c create mode 100644 src/mainPartieConsole.c diff --git a/ElderInternalIgnition/ElderInternalIgnition.cbp b/ElderInternalIgnition/ElderInternalIgnition.cbp index 8895fd2..753729e 100644 --- a/ElderInternalIgnition/ElderInternalIgnition.cbp +++ b/ElderInternalIgnition/ElderInternalIgnition.cbp @@ -48,6 +48,7 @@ <Unit filename="../src/TerrainsXML.c"> <Option compilerVar="CC" /> </Unit> + <Unit filename="../src/TerrainsXML.h" /> <Unit filename="../src/affichage.c"> <Option compilerVar="CC" /> </Unit> diff --git a/src/AffichageConsole.c b/src/AffichageConsole.c index d029bd8..e0099b5 100644 --- a/src/AffichageConsole.c +++ b/src/AffichageConsole.c @@ -6,12 +6,12 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "structures.h" #include "AffichageConsole.h" +#include "partie.h" #include "joueur.h" +#include "joueurList.h" #include "personnage.h" #include "case.h" -#include "joueurList.h" /*! * \fn void afficheEnsembleJoueur(Partie *p) @@ -19,19 +19,20 @@ * * \param Un pointeur vers les joueur a afficher avec leur personnage et ses coordonnees. */ + void afficheEnsembleJoueur(Partie *p){ Joueur * Temporaire = getCurrentJoueur(p->participants); /* On sauve l'emplacement du current actuel*/ setOnFirstJoueur(p->participants); /* On se positionne sur le premier joueur*/ while(!outOfJoueurList(p->participants)){ /*Tant qu'on est pas arrivé au dernier current*/ afficheNomJoueur(getCurrentJoueur(p->participants)); - afficheNomPersonnage(getPersonnage(getCurrentJoueur(p),0)); - afficheCoordonneePersonnage(getPosition(getPersonnage(getCurrentJoueur(p),0))); + afficheNomPersonnage(getPersonnage(getCurrentJoueur(getListJoueur(p)),0)); + afficheCoordonneesPersonnage(getPosition(getPersonnage(getCurrentJoueur(getListJoueur(p)),0))); nextJoueur(p->participants); } /*On affiche le dernier current (personnage)*/ afficheNomJoueur(getCurrentJoueur(p->participants)); - afficheNomPersonnage(getPersonnage(getCurrentJoueur(p),0)); - afficheCoordonneePersonnage(getPosition(getPersonnage(getCurrentJoueur(p),0))); + afficheNomPersonnage(getPersonnage(getCurrentJoueur(getListJoueur(p)),0)); + afficheCoordonneesPersonnage(getPosition(getPersonnage(getCurrentJoueur(getListJoueur(p)),0))); setOnJoueur(p->participants, Temporaire); /* On retourne sur le current original*/ } @@ -78,14 +79,3 @@ void afficheEtatPersonnage(Personnage *p){ printf("Points de vie: %d\n", get_PV(p)); printf("Mana: %d\n", get_mana(p)); } - -/*! - * \fn void affichePremierChoix(Partie *p) - * \brief La fonction permet de faire appel a la fonction afficheEnsembleJoueur(Partie *p), ainsi que le premier choix que doit faire le joueur dont le tour commence. - * - * \param Un pointeur vers la fonction afficheEnsembleJoueur(Partie *p) ainsi que le premier choix que doit faire le joueur dont le tour commence. - */ -void affichePremierChoix(Partie *p){ - afficheEnsembleJoueur(p); - printf("%s : Que voulez-vous faire?\n 1-Sélectionner un personnage\n 2-Fin du tour\n", getNomJoueur(getCurrentJoueur(p->participants))); -} diff --git a/src/AffichageConsole.h b/src/AffichageConsole.h index 9455599..9b35f7f 100644 --- a/src/AffichageConsole.h +++ b/src/AffichageConsole.h @@ -3,20 +3,15 @@ * \brief Fichier contenant les signatures des fonctions liees a la structure AffichageConsole. */ -#include "structures.h" -#include "joueur.h" -#include "personnage.h" -#include "case.h" -#include "joueurList.h" - #ifndef AFFICHAGECONSOLE_H #define AFFICHAGECONSOLE_H +#include "structures.h" + void afficheEnsembleJoueur(Partie *p); void afficheNomJoueur(Joueur * j); void afficheNomPersonnage(Personnage * p); void afficheCoordonneesPersonnage(Case *c); void afficheEtatPersonnage(Personnage *p); -void affichePremierChoix(Partie *p); #endif // AFFICHAGECONSOLE_H diff --git a/src/affichageConsole2.c b/src/affichageConsole2.c new file mode 100644 index 0000000..b223f34 --- /dev/null +++ b/src/affichageConsole2.c @@ -0,0 +1,47 @@ +#include <stdio.h> +#include <stdlib.h> + +/*! + * \fn void affichePremierChoix(Partie * p, int * i) + * \brief La fonction affiche le choix offert et modifie la variable entiere donnee en entree. + * + * \param un pointeur vers le premier caractere d'un tableau (il contient le nom du Joueur, voir le controleur), un pointeur vers un entier representant la variable de choix a modifier. + */ +void affichePremierChoix(char * c, int * i){ + printf("%s : Que voulez-vous faire?\n 1-Sélectionner un personnage\n 2-Fin du tour\n", c); + scanf("%d",&i); + printf("\n"); +} + +/*! + * \fn void afficherEntrerCoordonnees(int * cX, int * cY) + * \brief La fonction affiche une requete au Joueur et modifie les variable entiere pointee par les entrees en fonction des entrees clavier. + * + * \param les pointeurs vers les entiers representant les coordonnees a modifier. + */ + void afficherEntrerCoordonnees(int * cX, int * cY){ + printf("Entrez une abscisse : x = "); + scanf("%d",&cX); + printf("\n"); + printf("Entrez une ordonnée : y = "); + scanf("%d",&cY); + printf("\n"); + } + + /*! + * \fn void afficherChoixImpossible() + * \brief La fonction affiche un message + */ + void afficherChoixImpossible(){ + printf("Vous ne pouvez pas faire ça."); + } + + /*! + * \fn void afficheFinTour(char * c) + * \brief La fonction affiche une un message de fin de tour. + * + * \param Un pointeur vers le premier caractere du nom du Joueur dont ca va etre le tour (voir l'appel dans controlleur.c) + */ + void afficheFinTour(char * c){ + printf("Fin du tour.\n Nouveau tour : Tour de %s",c); + } diff --git a/src/affichageConsole2.h b/src/affichageConsole2.h new file mode 100644 index 0000000..d788017 --- /dev/null +++ b/src/affichageConsole2.h @@ -0,0 +1,14 @@ +/*! +* \file affichageConsole2.h +* \brief Fichier contenant les signatures des fonctions liees a la structure AffichageConsole. +*/ + +#ifndef AFFICHAGECONSOLE_H +#define AFFICHAGECONSOLE_H + +void affichePremierChoix(char * c, int * i); +void afficherChoixImpossible(); +void afficherEntrerCoordonnees(int * cX, int * cY); +void afficheFinTour(char * c); + +#endif // AFFICHAGECONSOLE_H diff --git a/src/case.c b/src/case.c index 6592a8c..26a3bdb 100644 --- a/src/case.c +++ b/src/case.c @@ -48,15 +48,35 @@ Terrain* get_terrain(Case *c){ int init_carte(Carte* c,unsigned short int largeur, unsigned short int hauteur){ int i,j,n; + n=0; if (largeur*hauteur>TAILLE_MAX_CARTE){ printf("erreur : taille maximum de la carte dépassée"); return 1; } - for (i=0;i<largeur;i++){ - for (j=0;j<hauteur;j++){ + for (i=0;i<(largeur);i++){ + for (j=0;j<(hauteur);j++){ init_case(c[n],i,j,NULL); n++; } } return 0; } + +/*! + * \fn Case * trouverCase(Carte * c, int x, int y) + * \brief La fonction renvoie un pointeur vers la case qui possede les coordonnees en entree. + * + * \param Les coordonnees a tester + * \return Un pointeur vers la Case qui possede les coordonnees en entree, NULL s'il n'y a pas de Case avec ces coordonnees. + */ +Case * trouverCase(Carte * c, int x, int y){ + if((x<0)||(x>=LARG_MAX_CARTE)){ + return NULL; + } + else if((y<0)||(y>=HAUT_MAX_CARTE)){ + return NULL; + } + else{ + return c[(x*LARG_MAX_CARTE)+y]; + } +} diff --git a/src/case.h b/src/case.h index fe44797..8d1a643 100644 --- a/src/case.h +++ b/src/case.h @@ -3,11 +3,12 @@ #include "structures.h" + + Case* Librairie_Cases(const char *filename); Case* Remplir_Cases_log(const char *filename); - Case* init_case(Case *c,int x, int y, Terrain *t); int get_x(Case *c); @@ -30,6 +31,8 @@ Terrain* get_terrain(Case *c); int init_carte(Carte* c,unsigned short int largeur, unsigned short int hauteur); +Case * trouverCase(Carte * c, int x, int y); + #endif diff --git a/src/controleur.c b/src/controleur.c new file mode 100644 index 0000000..b73413e --- /dev/null +++ b/src/controleur.c @@ -0,0 +1,57 @@ +/*! +* \file controleur.c +* \brief Fichier contenant le code des fonctions du controleur. +*/ + +#include <stdio.h> +#include <stdlib.h> + +#include "partie.h" +#include "joueur.h" +#include "affichageConsole2.h" +#include "joueurList.h" +#include "case.h" + + /*! + * \fn void choixPrincipal() + * \brief La fonction fait l'interface entre le moteur et l'affichage du jeu pour le premier choix principal d'un Joueur lors de son tour. + * + * \param La Partie p en cours. + */ +int choixPrincipal(Partie * p){ + int choix; + choix = 0; + affichePremierChoix(getNomJoueur(getCurrentJoueur(getListJoueur(p))),&choix); + switch(choix){ + case 1:{ + return 1; + } + case 2:{ + finTour(p); + afficheFinTour(getNomJoueur(getCurrentJoueur(getListJoueur(p)))); + return 0; + } + default:{ + afficherChoixImpossible(); + return 0; + } + } +} + + /*! + * \fn void choixPrincipal() + * \brief La fonction fait l'interface entre le moteur et l'affichage du jeu pour la saisie de coordonnees d'un Personnage. + * + * \param La Partie p en cours. + * \return Un pointeur vers le personnage aux coordonnees entrees, NULL si les coordonnees ne sont pas valides. + */ + +Case * entrerCoordonnees(Partie * p){ + int x, y; + Case * caseTemp = NULL; + x=-1; + y=-1; + afficherEntrerCoordonnees(&x,&y); + caseTemp=trouverCase(getCarte(p),x,y); + return caseTemp; +} diff --git a/src/controleur.h b/src/controleur.h new file mode 100644 index 0000000..c98b3a8 --- /dev/null +++ b/src/controleur.h @@ -0,0 +1,16 @@ +/*! +* \file controleur.h +* \brief Fichier contenant la definition des fonctions du controleur. +*/ + +#include "structures.h" + +#ifndef CONTROLEUR_H +#define CONTROLEUR_H + +int choixPrincipal(Partie * p); +Case * entrerCoordonnees(Partie * p); +void actionPersonnage(Partie * p); + +#endif // CONTROLEUR_H + diff --git a/src/controlleur.c b/src/controlleur.c new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/controlleur.c @@ -0,0 +1 @@ + diff --git a/src/mainPartieConsole.c b/src/mainPartieConsole.c new file mode 100644 index 0000000..4aed0c5 --- /dev/null +++ b/src/mainPartieConsole.c @@ -0,0 +1,16 @@ +#include <stdio.h> +#include <stdlib.h> +#include "structures.h" +#include "controleur.h" +#include "partie.h" + +int mainPartieConsole(){ + Partie * partieEnCours=initPartie(); + while(!victoire(partieEnCours)){ + if(choixPrincipal(partieEnCours)==1){ + entrerCoordonnees(partieEnCours); + + } + } + return 1; +} diff --git a/src/partie.c b/src/partie.c index c0b8a4e..cbd31e0 100644 --- a/src/partie.c +++ b/src/partie.c @@ -18,9 +18,12 @@ */ Partie * initPartie(){ Partie * p = malloc(sizeof(Partie)); - p->nbTours=0; ListJoueur * l = initJoueurList(); + Carte * carteJeu = NULL; + p->nbTours=0; p->participants=l; + init_carte(carteJeu,LARG_MAX_CARTE,HAUT_MAX_CARTE); + p->c=carteJeu; return p; } @@ -49,6 +52,34 @@ int getNbTour(Partie * p){ return -1; } + /*! + * \fn ListJoueur * getListJoueur(Partie * p) + * \brief La fonction renvoie un pointeur vers la liste de Joueurs de la Partie. + * + * \param La Partie p a tester. + * \return Un pointeur vers la ListJoueur de la Partie, NULL si l'entree est NULL. + */ +ListJoueur * getListJoueur(Partie * p){ + if(p!=NULL){ + return p->participants; + } + return NULL; +} + + /*! + * \fn Carte * getCarte(Partie * p) + * \brief La fonction renvoie un pointeur vers la Carte de la Partie. + * + * \param La Partie p a tester. + * \return Un pointeur vers la Carte de la Partie, NULL si l'entree est NULL. + */ +Carte * getCarte(Partie * p){ + if(p!=NULL){ + return p->c; + } + return NULL; +} + /*! * \fn void augmenterNbTour(Partie * p) * \brief La fonction incremente le nombre de tours de la Partie @@ -152,7 +183,7 @@ int victoire(Partie * p){ } /*! - * \fn int victoire(Partie * p) + * \fn finPartie(Partie * p) * \brief La fonction sauve les informations necessaires (Joueur) et supprime la partie. * * \param La Partie p a modifier diff --git a/src/partie.h b/src/partie.h index f8f4974..89a06d4 100644 --- a/src/partie.h +++ b/src/partie.h @@ -12,6 +12,8 @@ Partie * initPartie(); void deletePartie(Partie * p); int getNbTour(Partie * p); +ListJoueur * getListJoueur(Partie * p); +Carte * getCarte(Partie * p); void augmenterNbTour(Partie * p); int addParticipant(Partie * p, Joueur * j); diff --git a/src/structures.h b/src/structures.h index fa3f023..1fb6a28 100644 --- a/src/structures.h +++ b/src/structures.h @@ -24,6 +24,10 @@ #define TAILLE_NOMS 16 /*! \def TAILLE_MAX_GROUPE */ #define TAILLE_MAX_GROUPE 3 +/*! \def LARG_MAX_CARTE */ +#define LARG_MAX_CARTE 16 +/*! \def LONG_MAX_CARTE */ +#define HAUT_MAX_CARTE 16 /*! \enum boolean * \brief Definition du type Boolean. @@ -172,6 +176,7 @@ typedef struct Effet_Competence{ typedef struct Partie{ ListJoueur * participants; /*!< La liste de joueurs prennant parts à la partie*/ int nbTours; /*!<Le nombre de tours actuel*/ + Carte * c; /*!<La Carte associee a la Partie*/ }Partie; #endif -- GitLab