Retour au sujet

Avatar de NickOmouc NickOmouc
#ifndef DEF_ARMURE
#define DEF_ARMURE

#include <iostream>
#include <string>

class Armure
{
public:

Armure();
Armure(std::string nom, int protection);
void changer(std::string nom, int protection);

void afficher();
int getProtection() const;



private:
std::string m_nom;
int m_protect;
};

#endif



using namespace std;

Armure::Armure() : m_nom("Gilet Jaune "), m_protect(-10)
{

}

Armure::Armure(string nom, int protection) : m_nom(nom), m_protect(protection)
{

}
// j ai construis ligne 49 en me basant sur ça
//int Arme::getDegats() const
//{
// return m_degats;
//}


int Armure::getProtection() const
{
return m_protect;
}
void Armure::afficher()
{
cout << "Armor : " << m_nom << " (Protection : " << m_protect << ")" << endl;
}
//CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES
//CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES
//CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES //CLASSE ARME: PROTOTYPES

#ifndef DEF_ARME
#define DEF_ARME

#include <iostream>
#include <string>

class Arme
{
public:

Arme();
Arme(std::string nom, int degats);
void changer(std::string nom, int degats);
void afficher();
int getDegats() const;

private:

std::string m_nom;
int m_degats;
};

#endif
// CLASSE ARMES : FONCTION // CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION
// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION
// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION// CLASSE ARMES : FONCTION




// j enleve ça , ça parasite : #include "Arme.h"

using namespace std;

Arme::Arme() : m_nom("Broadsword"), m_degats(10)
{

}

Arme::Arme(string nom, int degats) : m_nom(nom), m_degats(degats)
{

}

void Arme::changer(string nom, int degats)
{
m_nom = nom;
m_degats = degats;
}

void Arme::afficher()
{
cout << "Weapon : " << m_nom << " (Damage : " << m_degats << ")" << endl;
}

int Arme::getDegats() const
{
return m_degats;
}




// Le compilateur lit de haut en bas donc d abord je declare ma classe

//PERSONNAGE PROTOTYPES//PERSONNAGE PROTOTYPES//PERSONNAGE PROTOTYPES//PERSONNAGE PROTOTYPES//PERSONNAGE PROTOTYPES//PERSONNAGE PROTOTYPES//PERSONNAGE PROTOTYPES//PERSONNAGE PROTOTYPES
//PERSONNAGE PROTOTYPES//PERSONNAGE PROTOTYPES//PERSONNAGE PROTOTYPES//PERSONNAGE PROTOTYPES//PERSONNAGE PROTOTYPES//PERSONNAGE PROTOTYPES//PERSONNAGE PROTOTYPES
//PERSONNAGE PROTOTYPES//PERSONNAGE PROTOTYPES//PERSONNAGE PROTOTYPES//PERSONNAGE PROTOTYPES//PERSONNAGE PROTOTYPES//PERSONNAGE PROTOTYPES

//#ifndef DEF_PERSONNAGE
#define DEF_PERSONNAGE

#include <iostream>
#include <string>
//#include "Arme.h"

class Personnage
{
public:

Personnage();
Personnage(std::string nomArme, int degatsArme,std::string nomArmure,int protectionArmure);
~Personnage();
void recevoirDegats(int nbDegats);//int defense);
void absorberDegats(int nbDegats,int defense );
void recevoirProtection(int nbDegats);
void attaquer(Personnage &cible);

void boirePotionDeVie(int quantitePotion);
void changerArme(std::string nomNouvelleArme, int degatsNouvelleArme);

void changerArmure(std::string nomNouvelleArmure, int protectionNouveauNiveau);
bool estVivant();
void afficherEtat();

private:

int m_vie;std :: string m_nomArmure;int m_protectionArmure;Armure m_armure;
int m_mana;std :: string m_nomArme;int m_degatsArme;
Arme m_arme;// c est genial j ai pu le rajouter juste en mettant
// en premier le bloc de lignes de code armes prototypes et arme fonction!Avant ca marchait pas!
// effectivement le compilateur lit de haut en bas et il faut bien s en rappeler quant on code!!



};

//#endif

// maintenant je mets les fonctions correspondantes aux prototypes :

// PERSONNAGE FONCTION VERSION SIMPLIFIEE // PERSONNAGE FONCTION VERSION SIMPLIFIEE// PERSONNAGE FONCTION VERSION SIMPLIFIEE// PERSONNAGE FONCTION VERSION SIMPLIFIEE// PERSONNAGE FONCTION VERSION SIMPLIFIEE// PERSONNAGE FONCTION VERSION SIMPLIFIEE// PERSONNAGE FONCTION VERSION SIMPLIFIEE
// PERSONNAGE FONCTION VERSION SIMPLIFIEE// PERSONNAGE FONCTION VERSION SIMPLIFIEE// PERSONNAGE FONCTION VERSION SIMPLIFIEE// PERSONNAGE FONCTION VERSION SIMPLIFIEE// PERSONNAGE FONCTION VERSION SIMPLIFIEE
// PERSONNAGE FONCTION VERSION SIMPLIFIEE// PERSONNAGE FONCTION VERSION SIMPLIFIEE// PERSONNAGE FONCTION VERSION SIMPLIFIEE// PERSONNAGE FONCTION VERSION SIMPLIFIEE// PERSONNAGE FONCTION VERSION SIMPLIFIEE


// j ai enlever ça #include "Personnage.h"


using namespace std;


Personnage::Personnage() : m_vie(150), m_mana(150)
{

}

Personnage::Personnage(string nomArme, int degatsArme,string nomArmure,int protectionArmure) :
m_vie(150), m_mana(150),
m_arme(nomArme, degatsArme),
m_armure(nomArmure,protectionArmure)
// la aussi
//je pense que " m_arme(nomArme, degatsArme) " a pu marcher ( il ne marchait pas avant ) juste parce que
// j ai foutu les dfinitions de armes ( fonctions et prototypes ) au début
{

}

Personnage::~Personnage()
{

}


void Personnage::absorberDegats(int nbDegats,int defense )
{

m_vie+= defense;

}
void Personnage::recevoirDegats(int nbDegats)//int defense )
{
m_vie-= nbDegats;
//m_vie+= defense;
if (m_vie < 0)
{
m_vie = 0;
}
}

//void Personnage::recevoirProtection(int nbDegats)
//{
// m_protect-= nbDegats;


//}


//void Personnage::attaquerArmure(Personnage &cible)
//{
// cible.recevoirProtection(m_arme.getDegats());
// On inflige à la cible les dégâts que cause notre arme
//}

//void Personnage::attaquer(Personnage &cible)
//{
// cible.recevoirDegats(m_armure.getProtection());
//On inflige à la cible les dégâts que cause notre arme
//}





void Personnage::attaquer(Personnage &cible)
{
cible.recevoirDegats(m_arme.getDegats());
//m_armure.getProtection());//TRES IMPORTANT , ce qu il y a entre parenthèse ICI
//correspond à ce qu'il y a entre parenthèse ligne 204
//On inflige à la cible les dégâts que cause notre arme
cible.absorberDegats(m_arme.getDegats(),cible.m_armure.getProtection());
}
//"void Personnage::attaquer(Personnage &cible)"
//"{ cible.recevoirDegats(m_nomArme.recevoirDegats());}" ce truc ne marche pas
// mais les lignes de code en haut marchent. Très curieux

void Personnage::boirePotionDeVie(int quantitePotion)
{
m_vie += quantitePotion;

if (m_vie > 100)
{
m_vie = 100;
}
}

void Personnage::changerArme(string nomNouvelleArme, int degatsNouvelleArme)
{
m_arme.changer(nomNouvelleArme, degatsNouvelleArme);
}
// ces 4 dernieres lignes ne marchaient pas avant je crois. Là encore en mettant en premier
// les blocs Armes prototypes et Armes fonctions je pense que ça a résolu le problème
bool Personnage::estVivant()
{
if (m_vie > 0)
{
return true;
}
else
{
return false;
}
}

void Personnage::afficherEtat()
{
cout << "Vie : " << m_vie << endl;
cout << "Mana : " << m_mana << endl;m_armure.afficher();
m_arme.afficher();// ca marche apres avoir deplacé les blocs de Armes fonctions et Prototypes au dessus !
}




// MAIN VERSION SIMPLIFIEE // // MAIN VERSION SIMPLIFIEE // // MAIN VERSION SIMPLIFIEE // // MAIN VERSION SIMPLIFIEE // // MAIN VERSION SIMPLIFIEE // // MAIN VERSION SIMPLIFIEE // // MAIN VERSION SIMPLIFIEE // // MAIN VERSION SIMPLIFIEE //
// MAIN VERSION SIMPLIFIEE // // MAIN VERSION SIMPLIFIEE // // MAIN VERSION SIMPLIFIEE // // MAIN VERSION SIMPLIFIEE // // MAIN VERSION SIMPLIFIEE // // MAIN VERSION SIMPLIFIEE // // MAIN VERSION SIMPLIFIEE //
// MAIN VERSION SIMPLIFIEE // // MAIN VERSION SIMPLIFIEE // // MAIN VERSION SIMPLIFIEE // // MAIN VERSION SIMPLIFIEE // // MAIN VERSION SIMPLIFIEE // // MAIN VERSION SIMPLIFIEE //


#include <iostream>
#include <string>
// j ai enlever ça #include "Personnage.h"

using namespace std;


int main()
{
// Création des personnages
Personnage david("Nunchaku",2,"Bronze Helmet",17),
goliath("Excalibur",67,"Shield",12),jerome("Nunchaku",2,"Banana Helmet",-1),vincent ;//J aienlever ça :"("Epée aiguisée", 20)"
// chez Goliath , que j ai pu rajouter quand j ai mis les fonctions et les prototypes de armes en haut
// on peut changer "épée aiguisée" par n importe quel autre nomj ai testé

//cout << "David" << endl;
// david.afficherEtat();
// Au combat !

//david.boirePotionDeVie(20);
goliath.attaquer(david);
// david.attaquer(goliath);
// J ai enlever cette ligne
// goliath.changerArme("MorningStar", 40);// que j ai pu rajouter
// tranquillement apres avoir mis les fonctions et prototypes de armes en haut
// se rappeler : lecompilateur lit de haut en bas
// Note : tu peux remplacer le nom "MorningStar" par ce que tu veux
// goliath.attaquer(david); goliath.attaquer(david);
// goliath.attaquer(david);
// Temps mort ! Voyons voir la vie de chacun...
cout << "David" << endl;
david.afficherEtat();
cout << endl << "Goliath" << endl;
goliath.afficherEtat();
cout << endl << "Vincent" << endl;
vincent.afficherEtat();
cout << endl << "Jerome" << endl;
jerome.afficherEtat();


return 0;
}