mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-11-17 07:48:27 +01:00
- player now use History class for turn storage
This commit is contained in:
parent
74900ca592
commit
1fb948cba9
2 changed files with 18 additions and 38 deletions
|
@ -25,6 +25,7 @@
|
|||
#include "board.h"
|
||||
#include "player.h"
|
||||
#include "turn.h"
|
||||
#include "history.h"
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
|
@ -38,61 +39,43 @@ Player::Player(int iId)
|
|||
|
||||
Player::~Player()
|
||||
{
|
||||
for (unsigned int i = 0; i < m_history.size(); i++)
|
||||
delete m_history[i];
|
||||
}
|
||||
|
||||
|
||||
const PlayedRack & Player::getCurrentRack() const
|
||||
{
|
||||
return m_pldrack;
|
||||
return m_history.getCurrentRack();
|
||||
}
|
||||
|
||||
|
||||
void Player::setCurrentRack(const PlayedRack &iPld)
|
||||
{
|
||||
m_pldrack = iPld;
|
||||
m_history.setCurrentRack(iPld);
|
||||
}
|
||||
|
||||
|
||||
const PlayedRack & Player::getLastRack() const
|
||||
{
|
||||
return m_history.back()->getPlayedRack();
|
||||
return m_history.getPreviousTurn().getPlayedRack();
|
||||
}
|
||||
|
||||
|
||||
const Round & Player::getLastRound() const
|
||||
{
|
||||
return m_history.back()->getRound();
|
||||
return m_history.getPreviousTurn().getRound();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This function increments the number of racks, and fills the new rack
|
||||
* with the unplayed tiles from the previous one.
|
||||
* 03 sept 2000 : We have to sort the tiles according to the new rules
|
||||
*/
|
||||
void Player::endTurn(const Round &iRound, int iTurn)
|
||||
{
|
||||
m_history.push_back(new Turn(iTurn, m_id, m_pldrack, iRound));
|
||||
|
||||
Rack rack;
|
||||
m_pldrack.getRack(rack);
|
||||
|
||||
// We remove the played tiles from the rack
|
||||
for (int i = 0; i < iRound.getWordLen(); i++)
|
||||
{
|
||||
if (iRound.isPlayedFromRack(i))
|
||||
{
|
||||
if (iRound.isJoker(i))
|
||||
rack.remove(Tile::Joker());
|
||||
else
|
||||
rack.remove(iRound.getTile(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Now reinitialize the current rack with the remaining tiles
|
||||
m_pldrack = PlayedRack();
|
||||
m_pldrack.setOld(rack);
|
||||
m_history.playRound(m_id,iTurn,iRound);
|
||||
}
|
||||
|
||||
/****************************************************************/
|
||||
/****************************************************************/
|
||||
|
||||
/// Local Variables:
|
||||
/// mode: c++
|
||||
/// mode: hs-minor
|
||||
/// c-basic-offset: 4
|
||||
/// End:
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <vector>
|
||||
#include "pldrack.h"
|
||||
#include "history.h"
|
||||
|
||||
class Turn;
|
||||
|
||||
|
@ -51,6 +52,8 @@ public:
|
|||
|
||||
void setCurrentRack(const PlayedRack &iPld);
|
||||
|
||||
const History& getHistory() const { return m_history; }
|
||||
|
||||
/**************************
|
||||
* Acessors for the score of the player
|
||||
**************************/
|
||||
|
@ -70,14 +73,8 @@ private:
|
|||
/// Score of the player
|
||||
int m_score;
|
||||
|
||||
/// Current played rack of the player
|
||||
PlayedRack m_pldrack;
|
||||
|
||||
/// History of the racks and rounds for the player
|
||||
// vector<PlayedRack *> m_playedRacks;
|
||||
// vector<Round *> m_rounds;
|
||||
// vector<int> m_turns;
|
||||
vector<Turn*> m_history;
|
||||
History m_history;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue