The constuctors of the players now take as argument the ID of the player

This commit is contained in:
Olivier Teulière 2005-11-06 17:13:45 +00:00
parent 9e5b6e8ebf
commit 777a6a5e8c
8 changed files with 25 additions and 22 deletions

View file

@ -26,8 +26,8 @@
#include "ai_percent.h"
AIPercent::AIPercent(float iPercent)
: m_percent(iPercent)
AIPercent::AIPercent(int iId, float iPercent)
: AIPlayer(iId), m_percent(iPercent)
{
// Ensure the decimal value of the percentage is between 0 and 1
if (m_percent < 0)

View file

@ -38,7 +38,7 @@ class AIPercent: public AIPlayer
{
public:
/// Constructor, taking the percentage (0.0 <= iPercent <= 1.0)
AIPercent(float iPercent);
AIPercent(int iId, float iPercent);
virtual ~AIPercent() {}
/**

View file

@ -84,7 +84,7 @@ public:
protected:
/// This class is a pure interface, forbid any direct instanciation
AIPlayer() {}
AIPlayer(int iId): Player(iId) {}
};
#endif

View file

@ -781,13 +781,14 @@ int Game::getNHumanPlayers() const
void Game::addHumanPlayer()
{
m_players.push_back(new HumanPlayer());
// The ID of the player is its position in the m_players vector
m_players.push_back(new HumanPlayer(getNPlayers()));
}
void Game::addAIPlayer()
{
m_players.push_back(new AIPercent(0));
m_players.push_back(new AIPercent(getNPlayers(), 0));
}

View file

@ -29,8 +29,9 @@
#include "debug.h"
Player::Player()
Player::Player(int iId)
{
m_id = iId;
m_score = 0;
}
@ -73,8 +74,7 @@ const Round & Player::getLastRound() const
*/
void Player::endTurn(const Round &iRound, int iTurn)
{
// FIXME: the number of the player is wrong here!
m_history.push_back(new Turn(iTurn, iTurn, m_pldrack, iRound));
m_history.push_back(new Turn(iTurn, m_id, m_pldrack, iRound));
Rack rack;
m_pldrack.getRack(rack);

View file

@ -33,7 +33,7 @@ class Turn;
class Player
{
public:
Player();
Player(int iId);
virtual ~Player();
// Pseudo RTTI
@ -64,6 +64,9 @@ public:
void endTurn(const Round &iRound, int iTurn);
private:
/// ID of the player
int m_id;
/// Score of the player
int m_score;
@ -84,7 +87,7 @@ private:
class HumanPlayer: public Player
{
public:
HumanPlayer() {}
HumanPlayer(int iId): Player(iId) {}
virtual ~HumanPlayer() {}
// Pseudo RTTI

View file

@ -30,9 +30,9 @@
#include "turn.h"
Turn::Turn(int iNum, int iPlayer,
Turn::Turn(int iNum, int iPlayerId,
const PlayedRack& iPldRack, const Round& iRound)
: m_num(iNum), m_player(iPlayer), m_pldrack(iPldRack), m_round(iRound)
: m_num(iNum), m_playerId(iPlayerId), m_pldrack(iPldRack), m_round(iRound)
{
}
@ -44,12 +44,10 @@ void Turn::operator=(const Turn &iOther)
pldrack = iOther.pldrack;
round = iOther.round;
}
#endif
string Turn::toString(bool iShowExtraSigns) const
{
#if 0
string rs = "";
if (iShowExtraSigns)
{
@ -57,8 +55,8 @@ string Turn::toString(bool iShowExtraSigns) const
}
rs = rs + m_pldrack.toString() + " " + m_round.toString();
return rs;
#endif
}
#endif
/// Local Variables:

View file

@ -30,29 +30,30 @@
class Turn
{
public:
// Turn();
Turn(int iNum, int iPlayer,
Turn(int iNum, int iPlayerId,
const PlayedRack& iPldRack, const Round& iRound);
virtual ~Turn() {};
#if 0
void setNum(int iNum) { m_num = iNum; }
void setPlayer(int iPldRack) { m_player = iPldRack; }
void setPlayer(int iPlayerId) { m_playerId = iPlayerId; }
void setPlayedRack(const PlayedRack& iPldRack) { m_pldrack = iPldRack; }
void setRound(const Round& iRound) { m_round = iRound; }
#endif
int getNum() const { return m_num; }
int getPlayer() const { return m_player; }
int getPlayer() const { return m_playerId; }
const PlayedRack& getPlayedRack() const { return m_pldrack; }
const Round& getRound() const { return m_round; }
// void operator=(const Turn &iOther);
#if 0
void operator=(const Turn &iOther);
string toString(bool iShowExtraSigns = false) const;
#endif
private:
int m_num;
int m_player;
int m_playerId;
PlayedRack m_pldrack;
Round m_round;