mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2025-01-28 19:58:35 +01:00
Minor API enhancements
This commit is contained in:
parent
104335e6aa
commit
d41530c496
9 changed files with 48 additions and 35 deletions
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2005 Eliot
|
||||
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
|
||||
*
|
||||
* $Id: duplicate.cpp,v 1.1 2005/02/05 11:14:56 ipkiss Exp $
|
||||
* $Id: duplicate.cpp,v 1.2 2005/02/09 22:33:56 ipkiss Exp $
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -116,13 +116,13 @@ int Duplicate::start()
|
|||
return 1;
|
||||
}
|
||||
|
||||
PlayedRack &pld = m_players[m_currPlayer]->getPlayedRack();
|
||||
PlayedRack pld = m_players[m_currPlayer]->getCurrentRack();
|
||||
/* All the players have the same rack */
|
||||
for (i = 0; i < getNPlayers(); i++)
|
||||
{
|
||||
if (i != m_currPlayer)
|
||||
{
|
||||
m_players[i]->getPlayedRack() = pld;
|
||||
m_players[i]->setCurrentRack(pld);
|
||||
}
|
||||
/* Nobody has played yet in this round */
|
||||
m_players[i]->setStatus(Player::TO_PLAY);
|
||||
|
@ -234,13 +234,13 @@ int Duplicate::endTurnForReal()
|
|||
return 1;
|
||||
}
|
||||
|
||||
PlayedRack &pld = m_players[imax]->getPlayedRack();
|
||||
PlayedRack pld = m_players[imax]->getCurrentRack();
|
||||
/* All the players have the same rack */
|
||||
for (i = 0; i < getNPlayers(); i++)
|
||||
{
|
||||
if (i != imax)
|
||||
{
|
||||
m_players[i]->getPlayedRack() = pld;
|
||||
m_players[i]->setCurrentRack(pld);
|
||||
}
|
||||
/* Nobody has played yet in this round */
|
||||
m_players[i]->setStatus(Player::TO_PLAY);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2005 Eliot
|
||||
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
|
||||
*
|
||||
* $Id: duplicate.h,v 1.1 2005/02/05 11:14:56 ipkiss Exp $
|
||||
* $Id: duplicate.h,v 1.2 2005/02/09 22:33:56 ipkiss Exp $
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -41,6 +41,7 @@ public:
|
|||
virtual ~Duplicate();
|
||||
|
||||
virtual GameMode getMode() const { return kDUPLICATE; }
|
||||
virtual string getModeAsString() const { return "Duplicate"; }
|
||||
|
||||
/*************************
|
||||
* Game handling
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2005 Eliot
|
||||
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
|
||||
*
|
||||
* $Id: freegame.cpp,v 1.1 2005/02/05 11:14:56 ipkiss Exp $
|
||||
* $Id: freegame.cpp,v 1.2 2005/02/09 22:33:56 ipkiss Exp $
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -175,7 +175,7 @@ void FreeGame::end()
|
|||
{
|
||||
if (i != m_currPlayer)
|
||||
{
|
||||
PlayedRack &pld = m_players[i]->getPlayedRack();
|
||||
const PlayedRack &pld = m_players[i]->getCurrentRack();
|
||||
pld.getAllTiles(tiles);
|
||||
for (unsigned int j = 0; j < tiles.size(); j++)
|
||||
{
|
||||
|
@ -205,7 +205,7 @@ int FreeGame::pass(const string &iToChange, int n)
|
|||
return 1;
|
||||
}
|
||||
|
||||
PlayedRack &pld = player->getPlayedRack();
|
||||
PlayedRack pld = player->getCurrentRack();
|
||||
Rack rack;
|
||||
pld.getRack(rack);
|
||||
|
||||
|
@ -227,6 +227,8 @@ int FreeGame::pass(const string &iToChange, int n)
|
|||
pld.reset();
|
||||
pld.setOld(rack);
|
||||
|
||||
player->setCurrentRack(pld);
|
||||
|
||||
// FIXME: the letters to change should not be in the bag while generating
|
||||
// the new rack!
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2005 Eliot
|
||||
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
|
||||
*
|
||||
* $Id: freegame.h,v 1.1 2005/02/05 11:14:56 ipkiss Exp $
|
||||
* $Id: freegame.h,v 1.2 2005/02/09 22:33:56 ipkiss Exp $
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -41,6 +41,7 @@ public:
|
|||
virtual ~FreeGame();
|
||||
|
||||
virtual GameMode getMode() const { return kFREEGAME; }
|
||||
virtual string getModeAsString() const { return "Free game"; }
|
||||
|
||||
/*************************
|
||||
* Game handling
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Authors: Antoine Fraboulet <antoine.fraboulet@free.fr>
|
||||
* Olivier Teuliere <ipkiss@via.ecp.fr>
|
||||
*
|
||||
* $Id: game.cpp,v 1.1 2005/02/05 11:14:56 ipkiss Exp $
|
||||
* $Id: game.cpp,v 1.2 2005/02/09 22:33:56 ipkiss Exp $
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -171,7 +171,7 @@ Game * Game::load(FILE *fin, const Dictionary &iDic)
|
|||
}
|
||||
|
||||
// Give the rack to the player
|
||||
pGame->m_players[nb]->getPlayedRack() = pldrack;
|
||||
pGame->m_players[nb]->setCurrentRack(pldrack);
|
||||
}
|
||||
// Read next line
|
||||
continue;
|
||||
|
@ -273,7 +273,7 @@ Game * Game::load(FILE *fin, const Dictionary &iDic)
|
|||
|
||||
pGame->m_currPlayer = player;
|
||||
// Update the rack for the player
|
||||
pGame->m_players[player]->getPlayedRack() = pldrack;
|
||||
pGame->m_players[player]->setCurrentRack(pldrack);
|
||||
// End the turn for the current player (this creates a new rack)
|
||||
pGame->m_players[player]->endTurn(round, num - 1);
|
||||
// Add the points
|
||||
|
@ -299,13 +299,7 @@ void Game::save(ostream &out) const
|
|||
const string decal = " ";
|
||||
// "Header" of the game
|
||||
out << IDENT_STRING << endl << endl;
|
||||
out << "Game type: ";
|
||||
if (getMode() == kTRAINING)
|
||||
out << "Training" << endl;
|
||||
else if (getMode() == kDUPLICATE)
|
||||
out << "Duplicate" << endl;
|
||||
else
|
||||
out << "Free game" << endl;
|
||||
out << "Game type: " << getModeAsString();
|
||||
for (int i = 0; i < getNPlayers(); i++)
|
||||
{
|
||||
out << "Player " << i << ": ";
|
||||
|
@ -340,7 +334,7 @@ void Game::save(ostream &out) const
|
|||
out << endl;
|
||||
for (int i = 0; i < getNPlayers(); i++)
|
||||
{
|
||||
string rack = formatPlayedRack(m_players[i]->getPlayedRack());
|
||||
string rack = formatPlayedRack(m_players[i]->getCurrentRack());
|
||||
out << "Rack " << i << ": " << rack << endl;
|
||||
}
|
||||
}
|
||||
|
@ -494,7 +488,7 @@ void Game::realBag(Bag &ioBag) const
|
|||
/* In freegame mode, replace the letters from all the racks */
|
||||
for (int i = 0; i < getNPlayers(); i++)
|
||||
{
|
||||
PlayedRack &pld = m_players[i]->getPlayedRack();
|
||||
PlayedRack pld = m_players[i]->getCurrentRack();
|
||||
pld.getAllTiles(tiles);
|
||||
for (unsigned int j = 0; j < tiles.size(); j++)
|
||||
{
|
||||
|
@ -506,7 +500,7 @@ void Game::realBag(Bag &ioBag) const
|
|||
{
|
||||
/* In training or duplicate mode, replace the rack of the current
|
||||
* player only */
|
||||
PlayedRack &pld = m_players[m_currPlayer]->getPlayedRack();
|
||||
PlayedRack pld = m_players[m_currPlayer]->getCurrentRack();
|
||||
pld.getAllTiles(tiles);
|
||||
for (int j = 0; j < pld.nTiles(); j++)
|
||||
{
|
||||
|
@ -537,7 +531,7 @@ int Game::helperSetRackRandom(int p, bool iCheck, set_rack_mode mode)
|
|||
|
||||
PDEBUG(p < 0 || p >= getNPlayers(), "GAME: wrong player number\n");
|
||||
|
||||
PlayedRack &pld = m_players[p]->getPlayedRack();
|
||||
PlayedRack pld = m_players[p]->getCurrentRack();
|
||||
nold = pld.nOld();
|
||||
|
||||
/* Create a copy of the bag in which we can do everything we want */
|
||||
|
@ -617,6 +611,8 @@ int Game::helperSetRackRandom(int p, bool iCheck, set_rack_mode mode)
|
|||
if (iCheck && !pld.checkRack(min))
|
||||
return 2;
|
||||
|
||||
m_players[p]->setCurrentRack(pld);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -626,7 +622,7 @@ int Game::helperSetRackManual(int p, bool iCheck, const string &iLetters)
|
|||
unsigned int i;
|
||||
int min;
|
||||
|
||||
PlayedRack &pld = m_players[p]->getPlayedRack();
|
||||
PlayedRack pld = m_players[p]->getCurrentRack();
|
||||
m_players[p]->clearResults();
|
||||
pld.reset();
|
||||
|
||||
|
@ -673,9 +669,12 @@ int Game::helperSetRackManual(int p, bool iCheck, const string &iLetters)
|
|||
min = 2;
|
||||
else
|
||||
min = 1;
|
||||
return pld.checkRack(min) ? 0 : 2;
|
||||
if (!pld.checkRack(min))
|
||||
return 2;
|
||||
}
|
||||
|
||||
m_players[p]->setCurrentRack(pld);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -852,7 +851,7 @@ string Game::getPlayerRack(int num) const
|
|||
{
|
||||
if (num < 0 || num >= getNPlayers())
|
||||
return "";
|
||||
return formatPlayedRack(m_players[num]->getPlayedRack(), false);
|
||||
return formatPlayedRack(m_players[num]->getCurrentRack(), false);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1003,7 +1002,7 @@ int Game::checkPlayedWord(const string &iCoord,
|
|||
* one by one */
|
||||
Rack rack;
|
||||
Player *player = m_players[m_currPlayer];
|
||||
player->getPlayedRack().getRack(rack);
|
||||
player->getCurrentRack().getRack(rack);
|
||||
|
||||
for (int i = 0; i < oRound.getWordLen(); i++)
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Authors: Antoine Fraboulet <antoine.fraboulet@free.fr>
|
||||
* Olivier Teuliere <ipkiss@via.ecp.fr>
|
||||
*
|
||||
* $Id: game.h,v 1.3 2005/02/05 11:14:56 ipkiss Exp $
|
||||
* $Id: game.h,v 1.4 2005/02/09 22:33:56 ipkiss Exp $
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -83,6 +83,7 @@ public:
|
|||
kDUPLICATE
|
||||
};
|
||||
virtual GameMode getMode() const = 0;
|
||||
virtual string getModeAsString() const = 0;
|
||||
|
||||
/*************************
|
||||
* handling games
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (C) 1999-2005 Eliot
|
||||
* Copyright (C) 2004-2005 Eliot
|
||||
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
|
||||
*
|
||||
* $Id: player.cpp,v 1.1 2005/02/05 11:14:56 ipkiss Exp $
|
||||
* $Id: player.cpp,v 1.2 2005/02/09 22:33:56 ipkiss Exp $
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -48,12 +48,18 @@ Player::~Player()
|
|||
}
|
||||
|
||||
|
||||
PlayedRack & Player::getPlayedRack() const
|
||||
const PlayedRack & Player::getCurrentRack() const
|
||||
{
|
||||
return *m_playedRacks.back();
|
||||
}
|
||||
|
||||
|
||||
void Player::setCurrentRack(const PlayedRack &iPld)
|
||||
{
|
||||
*m_playedRacks.back() = iPld;
|
||||
}
|
||||
|
||||
|
||||
const PlayedRack & Player::getLastRack() const
|
||||
{
|
||||
return *m_playedRacks[m_playedRacks.size() - 2];
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2004-2005 Eliot
|
||||
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
|
||||
*
|
||||
* $Id: player.h,v 1.2 2005/02/05 11:14:56 ipkiss Exp $
|
||||
* $Id: player.h,v 1.3 2005/02/09 22:33:56 ipkiss Exp $
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -40,10 +40,12 @@ public:
|
|||
* General getters
|
||||
**************************/
|
||||
// FIXME: we should have a const getter!
|
||||
PlayedRack & getPlayedRack() const;
|
||||
const PlayedRack & getCurrentRack() const;
|
||||
const PlayedRack & getLastRack() const;
|
||||
const Round & getLastRound() const;
|
||||
|
||||
void setCurrentRack(const PlayedRack &iPld);
|
||||
|
||||
/**************************
|
||||
* Add (or remove, if the given value is negative) points
|
||||
* to the player's score.
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Authors: Antoine Fraboulet <antoine.fraboulet@free.fr>
|
||||
* Olivier Teuliere <ipkiss@via.ecp.fr>
|
||||
*
|
||||
* $Id: training.h,v 1.1 2005/02/05 11:14:56 ipkiss Exp $
|
||||
* $Id: training.h,v 1.2 2005/02/09 22:33:56 ipkiss Exp $
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -42,6 +42,7 @@ public:
|
|||
virtual ~Training();
|
||||
|
||||
virtual GameMode getMode() const { return kTRAINING; }
|
||||
virtual string getModeAsString() const { return "Training"; }
|
||||
|
||||
/*************************
|
||||
* Game handling
|
||||
|
|
Loading…
Add table
Reference in a new issue