1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
| //Personnage.h
#ifndef PERSONNAGE_H_INCLUDED
#define PERSONNAGE_H_INCLUDED
#include "arme.h"
#include "Coordonnee.h"
#include "InvArme.h"
#include <vector>
//déclaration de la classe et de ses méthodes et attributs
class Personnage
{
public:
Personnage(std::string m_nomPersonnage, Coordonnee const & c, int equipe); //constructeur
Personnage(std::string m_nomPersonnage, std::string nomArme, int degatsArme,
int porteeArme, int m_vie, int m_mana,int ini, Coordonnee const & c, int equipe, int gold);
~Personnage(); //destructeur
//actions
std::string tour();
void attaquer(Personnage* &cible);
void deplacer(Coordonnee const & c);
void nefaisrien();
void changerArme();
void utiliserConsommable();
std::vector<PE> comptePE();
//changements d'etat
void recevoirDegats(int nbDegats);
void gagnerVie(int quantite);
void devientActif();
void devientInactif();
void gagneArme(Arme armeAj, int quantite);
//accesseurs
bool estVivant() const;
bool estActif() const;
void afficherEtat() const;
std::string getName() const;
Coordonnee const & coordonnee();
int getVie() const;
int getVieMax() const;
int getIni() const;
int getGold() const;
int getEquipe() const;
int x() const;
int y() const;
int portee() const ;
private:
std::vector<std::string> m_menuTour;
std::string m_nomPersonnage;
int m_vie;
unsigned int m_mana;
unsigned int m_viemax;
unsigned int m_ini;
unsigned int m_gold;
int m_equipe;
bool m_estActif;
Coordonnee m_coord;
InvArme m_invarme;
//equipement utilisé
Arme* m_arme; //pointeurs : & donne la valeur dans l'adresse et * donne l'adresse du pointeur
//caracteristiques
unsigned int m_for;
unsigned int m_dex;
unsigned int m_con;
unsigned int m_pui;
unsigned int m_pot;
unsigned int m_lvl;
};
#endif // PERSONNAGE_H_INCLUDED
//Personnage.ccp
#include <string>
#include "Personnage.h"
using namespace std;
Personnage::Personnage(string nomPersonnage, Coordonnee const & c, int equipe) : m_nomPersonnage(nomPersonnage), m_vie(100), m_mana(100),
m_viemax(m_vie),m_estActif(true),m_coord(c), m_equipe(equipe), m_arme(0),
m_lvl(1), m_for(10), m_dex(10), m_con(10), m_pui(10), m_pot(10), m_ini(20),m_gold(100)
{
m_menuTour.push_back("deplacer");
m_menuTour.push_back("attaquer");
m_menuTour.push_back("armes");
m_menuTour.push_back("objets");
m_menuTour.push_back("rien");
}
Personnage::Personnage(string nomPersonnage, string nomArme, int degatsArme, int porteeArme,
int vie, int mana, int ini, Coordonnee const & c, int equipe,int gold) :
m_nomPersonnage(nomPersonnage), m_vie(vie), m_mana(mana), m_viemax(m_vie),m_estActif(true), m_coord(c), m_equipe(equipe), m_arme(0),
m_lvl(1), m_for(10), m_dex(10), m_con(10), m_pui(10), m_pot(10), m_ini(ini),m_gold(gold)
{
m_invarme.ajouteItem(Arme(nomArme, degatsArme, porteeArme), 1);
m_menuTour.push_back("deplacer");
m_menuTour.push_back("attaquer");
m_menuTour.push_back("armes");
m_menuTour.push_back("objets");
m_menuTour.push_back("rien");
}
Personnage::~Personnage() //destructeur
{
}
//-------------------------------- ACTIONS -----------------------------------------------------
string Personnage::tour()
{
for (int i=0;i<m_menuTour.size();i++)
{
cout << i+1 << " = " << m_menuTour[i] << " ";
}
cout << endl;
int choix;
cout << "Indiquez le numero de l'action a effectuer :";
cin >> choix;
return m_menuTour[choix-1];
}
void Personnage::attaquer(Personnage* &cible)
{
cout << m_nomPersonnage << " attaque " << cible->getName() << "." << endl;
cible->recevoirDegats(10);
cout << endl;
m_estActif=false;
}
void Personnage::changerArme()
{
vector<Arme> const& tableau(m_invarme.renvoi());
// tableau=m_invarme.renvoi();
for (int i=0;i<tableau.size();i++)
{
cout << i+1 << " = " << tableau[i].getName() << " ";
}
int choix;
string util;
cout << "Indiquez le numero de l'objet a utiliser :";
cin >> choix;
m_arme = m_invarme.renvoiCase(choix-1);
cout << m_nomPersonnage << " change d'arme et prends " << m_arme->getName() << "." << endl;
m_estActif=false;
}
void Personnage::nefaisrien()
{
m_estActif=false;
cout << m_nomPersonnage << " ne fais rien." << endl;
}
void Personnage::deplacer(Coordonnee const & c) {m_coord=c;}
/*
void Personnage::utiliserConsommable()
{
vector<Objet> tableau;
tableau=m_inventaire.itemParType("Consommable");
for (int i=0;i<tableau.size();i++)
{
cout << i+1 << " = " << tableau[i].getName() << " ";
}
int choix;
string util;
cout << "Indiquez le numero de l'objet a utiliser :";
cin >> choix;
}
*/
vector<PE> Personnage::comptePE()
{
vector<PE> PEtot;
vector<PE> PEarme(m_arme->comptePE());
for (int i=0;i<PEarme.size();i++)
{
PEtot.push_back(PEarme[i]);
}
return PEtot;
}
//------------------------------ CHANGEMENTS D'ETAT --------------------------------------------
void Personnage::recevoirDegats(int nbDegats)
{
m_vie -= nbDegats;
//On enlève le nombre de dégâts reçus à la vie du personnage
if (m_vie < 0) //Pour éviter d'avoir une vie négative
{
m_vie = 0; //On met la vie à 0 (cela veut dire mort)
cout << m_nomPersonnage << " recoit " << nbDegats << " points de degats et meurt." << endl;
}
else
{
cout << m_nomPersonnage << " recoit " << nbDegats << " points de degats." << endl;
}
}
void Personnage::gagnerVie(int quantite)
{
m_vie += quantite;
if (m_vie > m_viemax) {m_vie = m_viemax;}
}
void Personnage::gagneArme(Arme armeAj, int quantite) {m_invarme.ajouteItem(armeAj, quantite);}
void Personnage::devientActif() {m_estActif=true;}
void Personnage::devientInactif() {m_estActif=false;}
//--------------------------- ACCESSEURS --------------------------------
bool Personnage::estVivant() const
{
if (m_vie > 0) {return true;}
else {return false;}
cout << endl;
}
void Personnage::afficherEtat() const
{
cout << m_nomPersonnage << ", equipe : " << m_equipe << endl;
cout << "Vie : " << m_vie << "/" << m_viemax << endl;
cout << "Coordonnees : x=" << m_coord.x() << " y=" << m_coord.y() << endl;
if (m_arme==0) {cout << m_nomPersonnage << " n'a pas d'arme";}
else {m_arme->afficher();}
}
bool Personnage::estActif() const
{
if (m_estActif == true) {return true;}
else {return false;}
}
string Personnage::getName() const {return m_nomPersonnage;}
const Coordonnee& Personnage::coordonnee() {return m_coord;}
int Personnage::getVie() const {return m_vie;}
int Personnage::getVieMax() const {return m_viemax;}
int Personnage::getIni() const {return m_ini;}
int Personnage::getGold() const {return m_gold;}
int Personnage::getEquipe() const {return m_equipe;}
int Personnage::x() const {return m_coord.x();}
int Personnage::y() const{return m_coord.y();}
int Personnage::portee() const {return m_arme->getPortee();} |
Partager