cs_Hades5k
Messages postés
12
Date d'inscription
mercredi 10 juillet 2002
Statut
Membre
Dernière intervention
1 décembre 2005
17 nov. 2005 à 06:18
Euh ok... désolé, j'ai pas mis de rar... j'ai pas trouvé comment... je paste le contenu du code ...
// MAIN.CPP
#include <string>
#include
#include "CComponent.h"
#include "CPlayer.h"
using namespace std;
int main()
{
cout << "Part 1 ------------------" << endl;
CComponent c;
c.use();
c.drop();
cout << "\nEnd Part 1...\n\n";
cout << "Part 2 ------------------" << endl;
CComponent c2("Sulfur");
c2.use();
c2.drop();
cout << "\nEnd Part 2...\n\n";
CComponent c3("Blue Meteor", 300, 2, POINT2D(3,4));
c3.use();
c3.drop();
cout << "\nFini #2...\n\n";
cout << "******************************************\n\n";
CPlayer *player = new CPlayer("Chris", BLUEMAGE, ELF, 560);
player->listInventory();
cout << "******************************************\n\n";
return 0;
}
// FULLINCLUDE.H
struct POINT2D
{
POINT2D() : width(0), height(0) {};
POINT2D(int x, int y) : width(x), height(y) {};
int width;
int height;
};
enum MageType { BLUEMAGE, REDMAGE, GREENMAGE, WHITEMAGE, BLACKMAGE };
enum RaceType { HUMAN, HALFELF, ELF, DARKELF, HALFDARKELF, ORC };
// CITEM.H
#ifndef _CITEM_
#define _CITEM_
#include <string>
#include "FullInclude.h"
using namespace std;
class CItem
{
public:
virtual bool use(void) = 0;
virtual bool drop(void) = 0;
};
#endif
// CCOMPONENT.H
#ifndef _CCOMPONENT_
#define _CCOMPONENT_
#include <string>
#include "CItem.h"
using namespace std;
class CComponent : public CItem
{
private:
string name;
int weight;
long value;
POINT2D size;
static int nbItem;
public:
CComponent();
CComponent(string pName);
CComponent(string pName, int pValue, int pWeight, POINT2D pSize);
~CComponent();
bool use(void);
bool drop(void);
void reveal(void);
};
#endif
// CPLAYER.H
#ifndef _CPLAYER_
#define _CPLAYER_
#include <string>
#include <vector>
#include "CComponent.h"
using namespace std;
class CPlayer
{
private:
string name;
MageType magetype;
RaceType racetype;
long kyna;
vector<CComponent> inventory;
public:
CPlayer();
CPlayer(string pName, MageType pMagetype, RaceType pRacetype, long pKyna);
~CPlayer();
void listInventory(void);
//void useItem(CItem &item);
};
#endif
// CCOMPONENT.CPP
#include <string>
#include
#include "CComponent.h"
using namespace std;
int CComponent::nbItem = 0;
// Default constructor
CComponent::CComponent() {
cout << "CComponent created...\n";
CComponent::nbItem++;
cout << "nbItem : " << CComponent::nbItem << endl;
}
// Constructor which names the component
CComponent::CComponent(string pName) {
name = pName;
cout << "CComponent created (" << name << ")...\n";
CComponent::nbItem++;
cout << "nbItem : " << CComponent::nbItem << endl;
}
// Full constructor
CComponent::CComponent(string pName, int pValue, int pWeight, POINT2D pSize) {
name = pName;
value = pValue;
weight = pWeight;
size = pSize;
cout << "CComponent created (" << name << ", " << value << ", " << weight << ", W:" << size.width << ", H" << size.height << ")...\n";
CComponent::nbItem++;
cout << "nbItem : " << CComponent::nbItem << endl;
}
// Destructor
CComponent::~CComponent()
{
CComponent::nbItem--;
}
// This function is called whenever the player wants to use a component
bool CComponent::use(void)
{
cout << "Component used...\n";
return true;
}
// When the component is dropped
bool CComponent::drop(void)
{
cout << "Component dropped...\n";
return true;
}
void CComponent::reveal(void)
{
cout << name;
}
// CPLAYER.CPP
#include <string>
#include
#include "CPlayer.h"
using namespace std;
CPlayer::CPlayer()
{
name = "Default Player Name";
magetype = BLUEMAGE;
racetype = HUMAN;
kyna = 0;
}
CPlayer::CPlayer(string pName, MageType pMagetype, RaceType pRacetype, long pKyna)
{
name = pName;
magetype = pMagetype;
racetype = pRacetype;
kyna = pKyna;
// loop to generate temporary "inventory"
for(int i = 0; i < 10; i++)
{
CComponent c("Component#" + i);
inventory.push_back(c);
}
}
CPlayer::~CPlayer()
{
cout << "I am destroyed...\n";
}
void CPlayer::listInventory(void)
{
vector<CComponent>::iterator iter;
for(iter = inventory.begin(); iter != inventory.end(); iter++)
{
CComponent tmpC = *(iter);
tmpC.reveal();
}
}
Quand le CComponent est crée... il affiche son nom... et celui-ci est toujours tronqué de plus en plus...