diff --git a/ElderInternalIgnition/ElderInternalIgnition.cbp b/ElderInternalIgnition/ElderInternalIgnition.cbp index 8895fd2ad73f51c97b61f651ef2e21d455880910..753729e9d2d5b4f214c567d5fc9eff0831732846 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 d029bd873a2f05ff5b3641839fdf60897955f837..e0099b50858a684eb21fc2d28caeeb8ccf318ce8 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 94555992fa08cffea0be491ff73cb24eab5b9029..9b35f7f04331c628e48c440e4f3014000ee57e09 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 0000000000000000000000000000000000000000..b223f34faa7035098cae3e82b60f7755fecfd024 --- /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 0000000000000000000000000000000000000000..d78801726e90e3fc03e2f69c653fb8df0e1e37ab --- /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 6592a8c643e848a71a8cb52de25445ba914c49a6..26a3bdb461c3ceb60a9041157c42e5cfdd036f4e 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 fe44797202c78c6cab95af386ebbe3fec76dab2d..8d1a6437dd9f5f8b35a8fa2e952d92c11e2a2476 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 0000000000000000000000000000000000000000..b73413eb4fbd196e176bb036820bd182b482abc1 --- /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 0000000000000000000000000000000000000000..c98b3a8a8f7abaa187e79308f70a99539d32226d --- /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 0000000000000000000000000000000000000000..8b137891791fe96927ad78e64b0aad7bded08bdc --- /dev/null +++ b/src/controlleur.c @@ -0,0 +1 @@ + diff --git a/src/mainPartieConsole.c b/src/mainPartieConsole.c new file mode 100644 index 0000000000000000000000000000000000000000..4aed0c5d5bdc647bdd02eeba05f0a3cc6ce48a29 --- /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 c0b8a4e46ebcf4491443b97f01627f438c6fbc1d..cbd31e0c1b5a229ab971e98946f29e81b96c6fde 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 f8f497471a0f28060f3142931cbc2576ad9a7217..89a06d4e0b3d1804e36fff57e5309834a66061fb 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 fa3f0239ced66158a08d204e0454ee279115846a..1fb6a28264a4dfd35bd4a3adaf31d2ae4ea0ae7c 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