From 0aa419035e5c5b9dd77f4ae9d12acec4deab0e67 Mon Sep 17 00:00:00 2001 From: ColinDrieu <colin.drieu@insa-rennes.fr> Date: Wed, 13 Apr 2016 11:27:39 +0200 Subject: [PATCH] Suite du code du controleur et du deroullement du programme. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajout de fonctions à controleur.c, MAJ du header Ajout de fonctions à affichageConsole2.c, MAJ du header MAJ de mainPartieConsole.c Ajout de la fonction appartientJoueur à partie.c, la fonction jouerPersonnage devient inutile. Ajout de getters et d'une fonction de test à personnage.c Ajout de getters au fichier classe.c Pour continuer le code du controleur, je ferai encore des modifications sur certains fichiers de données. --- src/affichageConsole2.c | 30 ++++++++++++++ src/affichageConsole2.h | 8 ++-- src/classe.c | 44 ++++++++++++++++++++ src/classe.h | 8 ++++ src/controleur.c | 90 ++++++++++++++++++++++++++++++++--------- src/controleur.h | 4 +- src/mainPartieConsole.c | 52 ++++++++++++++++++++++-- src/partie.c | 23 +++++++++++ src/partie.h | 1 + src/personnage.c | 25 ++++++++++++ src/personnage.h | 6 +++ src/structures.h | 2 +- 12 files changed, 266 insertions(+), 27 deletions(-) diff --git a/src/affichageConsole2.c b/src/affichageConsole2.c index 4aba73b..2def0fc 100644 --- a/src/affichageConsole2.c +++ b/src/affichageConsole2.c @@ -45,3 +45,33 @@ void affichePremierChoix(char * c, int * i){ void afficheFinTour(char * c){ printf("Fin du tour.\n Nouveau tour : Tour de %s",c); } + + /*! + * \fn void afficheEtatPersonnage(char * nomJoueur, char * nomPersonnage, char * nomClasse, int * caracteristiques) + * \brief La fonction affiche les informations concernant l'etat d'un Personnage + * + * \param Un pointeur vers des chaines de caracteres et un tableau d'entier representant respectivement : + * le nom du Joueur possedant le Personnage + * le nom du Personnage + * le nom de sa Classe + * ses points de vie actuels et maximum + * son mana actuel et maximum + * ses points de deplacement actuels et maximum + */ + void afficheCaracteristiquesPersonnage(char * nomJoueur, char * nomPersonnage, char * nomClasse, int * caracteristiques){ + printf("%s : %s\n %s \n", nomPersonnage, nomClasse, nomJoueur); + printf("PV : %d/%d \n Mana : %d/%d \n PD : %d/%d \n", caracteristiques[0], caracteristiques[1], caracteristiques[2], caracteristiques[3], caracteristiques[4], caracteristiques[5]); + } + + /*! + * \fn void affichePremierChoix(Partie * p, int * i) + * \brief La fonction affiche le choix offert pour l'action d'un Personnage et modifie la variable entiere donnee en entree. + * + * \param un pointeur vers les premiers caracteres de tableaux (ils contiennent le nom du Joueur et le nom du Personnage respectivement, voir le controleur), + * un pointeur vers un entier representant la variable de choix a modifier. + */ + void afficheChoixActionPersonnage(char * nJ, char * nP, int * i){ + printf("%s : %s \n Que voulez vous faire ?\n", nJ,nP); + printf("1- Attaque \n 2- Déplacement \n 3- Retour à la selection de Personnage \n, Fin du Tour"); + scanf("%d",i); + } diff --git a/src/affichageConsole2.h b/src/affichageConsole2.h index d788017..b7793b7 100644 --- a/src/affichageConsole2.h +++ b/src/affichageConsole2.h @@ -3,12 +3,14 @@ * \brief Fichier contenant les signatures des fonctions liees a la structure AffichageConsole. */ -#ifndef AFFICHAGECONSOLE_H -#define AFFICHAGECONSOLE_H +#ifndef AFFICHAGECONSOLE2_H +#define AFFICHAGECONSOLE2_H void affichePremierChoix(char * c, int * i); +void afficheChoixActionPersonnage(char * nJ, char * nP, int * i); void afficherChoixImpossible(); void afficherEntrerCoordonnees(int * cX, int * cY); void afficheFinTour(char * c); +void afficheCaracteristiquesPersonnage(char * nomJoueur, char * nomPersonnage, char * nomClasse, int * caracteristiques); -#endif // AFFICHAGECONSOLE_H +#endif // AFFICHAGECONSOLE2_H diff --git a/src/classe.c b/src/classe.c index c890c93..4b32b34 100644 --- a/src/classe.c +++ b/src/classe.c @@ -32,5 +32,49 @@ Classe* Remplir_Classes_log(const char *filename) } } + /*! + * \fn int getPVMax(Classe * c) + * \brief La fonction retourne le nombre de PV maximum de la Classe. + * + * \param La Classe a tester + * \return un entier representant le nombre de PV maximum de la Classe + */ +int getPVMax(Classe * c){ + return c->PV_max; +} + + /*! + * \fn int getManaMax(Classe * c) + * \brief La fonction retourne le Mana maximum de la Classe. + * + * \param La Classe a tester + * \return un entier representant le Mana maximum de la Classe + */ +int getManaMax(Classe * c){ + return c->mana_max; +} + + /*! + * \fn int getManaMax(Classe * c) + * \brief La fonction retourne le nombre de PD maximum de la Classe. + * + * \param La Classe a tester + * \return un entier representant le nombre de PD maximum de la Classe + */ +int getPDMax(Classe * c){ + return c->points_deplacement_max; +} + + /*! + * \fn int getNomClasse(Classe * c) + * \brief La fonction retourne un pointeur vers le nom de la Classe. + * + * \param La Classe a tester + * \return un Pointeur vers le nom de la Classe. + */ +char * getNomClasse(Classe * c){ + return c->nom; +} + diff --git a/src/classe.h b/src/classe.h index ea3b197..141d521 100644 --- a/src/classe.h +++ b/src/classe.h @@ -9,4 +9,12 @@ Classe* Librairie_Classes(const char *filename); Classe* Remplir_Classes_log(const char *filename); +char * getNomClasse(Classe * c); + +int getPVMax(Classe * c); + +int getManaMax(Classe * c); + +int getPDMax(Classe * c); + #endif // CLASSE_H_INCLUDED diff --git a/src/controleur.c b/src/controleur.c index b73413e..0ba4a2e 100644 --- a/src/controleur.c +++ b/src/controleur.c @@ -11,41 +11,44 @@ #include "affichageConsole2.h" #include "joueurList.h" #include "case.h" +#include "personnage.h" +#include "classe.h" /*! - * \fn void choixPrincipal() + * \fn int 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. + * \return un entier representant la valeur du choix du Joueur. */ 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; - } - } + return choix; } /*! - * \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. + * \fn int choixActionPersonnage(Partie * p) + * \brief La fonction fait l'interface entre le moteur et l'affichage du jeu pour le choix d'une action 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. + * \return un entier representant la valeur du choix du Joueur. */ +int choixActionPersonnage(Partie * p, Personnage * persSel, Joueur * j){ + int i; + i=0; + afficheChoixActionPersonnage(getNomJoueur(j),getNomPersonnage(persSel),&i); + return i; +} + /*! + * \fn Case * entrerCoordonnees(Partie * p) + * \brief La fonction fait l'interface entre le moteur et l'affichage du jeu pour la saisie de coordonnees. + * + * \param La Partie p en cours. + * \return Un pointeur vers la Case aux coordonnees entrees, NULL si les coordonnees ne sont pas valides. + */ Case * entrerCoordonnees(Partie * p){ int x, y; Case * caseTemp = NULL; @@ -55,3 +58,54 @@ Case * entrerCoordonnees(Partie * p){ caseTemp=trouverCase(getCarte(p),x,y); return caseTemp; } + + /*! + * \fn Personnage * coordonneesValidesPersonnage(Partie * p, Case * c) + * \brief La fonction teste pour tous les Joueurs de la Partie s'ils possedent un Personnage sur la Case en entree. + * Si c'est le cas, le Personnage sur la Case est retourne. + * + * \param La Partie p en cours, la Case a tester. + * \return Un pointeur vers le Personnage sur la Case, NULL s'il n'y a pas de Personnage sur la Case. + */ +Personnage * coordonneesValidesPersonnage(Partie * p, Case * c){ + int i; + Personnage * resP = NULL; + Joueur * tempJ = NULL; + tempJ = getCurrentJoueur(getListJoueur(p)); + setOnFirstJoueur(getListJoueur(p)); + while(outOfJoueurList(getListJoueur(p))){ + for(i=0;i<TAILLE_MAX_GROUPE;i++){ + if(estSurLaCase(getPersonnage(getCurrentJoueur(getListJoueur(p)),i),c)){ + resP = getPersonnage(getCurrentJoueur(getListJoueur(p)),i); + } + } + } + for(i=0;i<TAILLE_MAX_GROUPE;i++){ + if(estSurLaCase(getPersonnage(getCurrentJoueur(getListJoueur(p)),i),c)){ + resP = getPersonnage(getCurrentJoueur(getListJoueur(p)),i); + } + } + setOnJoueur(getListJoueur(p),tempJ); + return resP; +} + + /*! + * \fn void personnageSelectionne(Partie * p) + * \brief La fonction fait l'interface entre le moteur du jeu et l'affichage pour l'affichage des caracteristiques d'un Personnage. + * + * \param La Partie p en cours. + */ +void personnageSelectionne(Partie * p, Personnage * personnageSel){ + char * nP = getNomPersonnage(personnageSel); + char * nC = getNomClasse(getClasse(personnageSel)); + char * nJ = getNomJoueur(appartientJoueur(personnageSel,p)); + int etat[6]={ + get_PV(personnageSel), + getPVMax(getClasse(personnageSel)), + get_mana(personnageSel), + getManaMax(getClasse(personnageSel)), + get_PD(personnageSel), + getPDMax(getClasse(personnageSel)) + }; + afficheCaracteristiquesPersonnage(nJ,nP,nC,etat); +} diff --git a/src/controleur.h b/src/controleur.h index c98b3a8..af3126d 100644 --- a/src/controleur.h +++ b/src/controleur.h @@ -10,7 +10,9 @@ int choixPrincipal(Partie * p); Case * entrerCoordonnees(Partie * p); -void actionPersonnage(Partie * p); +Personnage * coordonneesValidesPersonnage(Partie * p, Case * c); +int choixActionPersonnage(Partie * p); +void personnageSelectionne(Partie * p, Personnage * personnageSel); #endif // CONTROLEUR_H diff --git a/src/mainPartieConsole.c b/src/mainPartieConsole.c index 4aed0c5..d391ed1 100644 --- a/src/mainPartieConsole.c +++ b/src/mainPartieConsole.c @@ -3,14 +3,58 @@ #include "structures.h" #include "controleur.h" #include "partie.h" +#include "personnage.h" +#include "joueurList.h" +#include "joueur.h" +#include "affichageConsole2.h" int mainPartieConsole(){ Partie * partieEnCours=initPartie(); + Case * caseSel = NULL; + Personnage * persSel = NULL; while(!victoire(partieEnCours)){ - if(choixPrincipal(partieEnCours)==1){ - entrerCoordonnees(partieEnCours); - + switch(choixPrincipal(partieEnCours)){ + case 1:{ + caseSel = entrerCoordonnees(partieEnCours); + if(caseSel!=NULL){ + persSel = coordonneesValidesPersonnage(partieEnCours,caseSel); + if(persSel!=NULL){ + personnageSelectionne(partieEnCours,persSel); + if((isTurn(partieEnCours, appartientJoueur(persSel, partieEnCours)))){ + switch (choixActionPersonnage(partieEnCours)){ + case 1:{ + //Attaque + } + case 2:{ + //Deplacement + } + case 3:{ + //Retour choix Principal + } + case 4:{ + //fin du tour + } + default:{ + afficherChoixImpossible(); + } + } + } + } + else{ + afficherChoixImpossible(); + } + } + else{ + afficherChoixImpossible(); + } + } + case 2:{ + finTour(partieEnCours); + afficheFinTour(getNomJoueur(getCurrentJoueur(getListJoueur(partieEnCours)))); + } + default:{ + afficherChoixImpossible(); + } } } - return 1; } diff --git a/src/partie.c b/src/partie.c index cbd31e0..242f75b 100644 --- a/src/partie.c +++ b/src/partie.c @@ -193,5 +193,28 @@ void finPartie(Partie * p){ deletePartie(p); } +/*! + * \fn Joueur * appartientJoueur(Personnage * p, Partie * partieEnCours) + * \brief La fonction teste l'appartenance d'un Personnage a un Joueur. + * \param Un pointeur vers le Personnage a tester et la partie en cours. + * \return Un pointeur vers le Joueur auquel appartient le Personnage + */ +Joueur * appartientJoueur(Personnage * p, Partie * partieEnCours){ + Joueur * tempJ = NULL; + Joueur * resJ = NULL; + tempJ = getCurrentJoueur(getListJoueur(partieEnCours)); + setOnFirstJoueur(getListJoueur(partieEnCours)); + while(outOfJoueurList(getListJoueur(partieEnCours))){ + if(isInGroupe(getCurrentJoueur(getListJoueur(partieEnCours)), p)){ + resJ = getCurrentJoueur(getListJoueur(partieEnCours)); + } + } + if(isInGroupe(getCurrentJoueur(getListJoueur(partieEnCours)),p)){ + resJ = getCurrentJoueur(getListJoueur(partieEnCours)); + } + setOnJoueur(getListJoueur(partieEnCours),tempJ); + return resJ; +} + diff --git a/src/partie.h b/src/partie.h index 89a06d4..4c151e1 100644 --- a/src/partie.h +++ b/src/partie.h @@ -24,6 +24,7 @@ int finTour(Partie * p); int isTurn(Partie * p, Joueur * j); Personnage * jouerPersonnage(Partie * p, Joueur * j, Personnage * perso); +Joueur * appartientJoueur(Personnage * p, Partie * partieEnCours); int victoire(Partie * p); diff --git a/src/personnage.c b/src/personnage.c index d96e108..582da4e 100644 --- a/src/personnage.c +++ b/src/personnage.c @@ -49,4 +49,29 @@ int deplacer_personnage (Personnage *perso, Case *destination){ /*d return 1; } + /*! + * \fn int estSurLaCase(Personnage * p, Case * c) + * \brief La fonction teste si un Personnage est sur une Case. + * + * \param Le Personnage et la Case a tester. + * \return 1 si le Personnage est sur la Case, 0 sinon. + */ +int estSurLaCase(Personnage * p, Case * c){ + return c==getPosition(p); +} + + /*! + * \fn char * getNomPersonnage(Personnage * p) + * \brief La fonction renvoie le nom d'un Personnage. + * + * \param Le Personnage a tester. + * \return un pointeur vers la chaine de caractere representant le nom du Personnage, NULL si l'entree est NULL. + */ +char * getNomPersonnage(Personnage * p){ + if(p!=NULL){ + return p->nomPersonnage; + } + return NULL; +} + diff --git a/src/personnage.h b/src/personnage.h index f861acf..70c6416 100644 --- a/src/personnage.h +++ b/src/personnage.h @@ -11,8 +11,14 @@ int get_PD(Personnage *p); int get_mana(Personnage *p); +Classe * getClasse(Personnage *p); + +char * getNomPersonnage(Personnage * p); + boolean est_paralyse(Personnage *p); int deplacer_personnage (Personnage *perso, Case *destination); +int estSurLaCase(Personnage * p, Case * c); + #endif diff --git a/src/structures.h b/src/structures.h index 1fb6a28..a08517b 100644 --- a/src/structures.h +++ b/src/structures.h @@ -99,7 +99,7 @@ typedef struct Classe{ * \brief Definition de la structure Personnage. */ typedef struct Personnage{ - char nom[TAILLE_NOMS];/*!< Nom du personnage de taille TAILLE_NOMS*/ + char nomPersonnage[TAILLE_NOMS];/*!< Nom du personnage de taille TAILLE_NOMS*/ Classe* classe; /*!< La classe dont depend le personnage */ unsigned short int points_deplacement; /*!< Les PD actuels du personnage*/ unsigned short int PV; /*!< Les PV actuels du personnage*/ -- GitLab