mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2025-01-28 19:58:35 +01:00
- Removed Game::format*
- Added Game::getPlayer
This commit is contained in:
parent
12894e00e2
commit
5b682ef9b8
11 changed files with 47 additions and 81 deletions
|
@ -27,6 +27,7 @@
|
|||
#include <string>
|
||||
#include "coord.h"
|
||||
#include "board.h" // for BOARD_MIN and BOARD_MAX (TODO: remove this include)
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
Coord::Coord(int iRow, int iCol, Direction iDir)
|
||||
|
@ -86,19 +87,20 @@ void Coord::setFromString(const string &iStr)
|
|||
|
||||
string Coord::toString() const
|
||||
{
|
||||
string rs;
|
||||
ASSERT(isValid(), "Invalid coordinates");
|
||||
|
||||
string res;
|
||||
char s[5];
|
||||
sprintf(s, "%d", m_col);
|
||||
if (getDir() == HORIZONTAL)
|
||||
{
|
||||
rs = string(1, m_row + 'A' - 1) + s;
|
||||
res = string(1, m_row + 'A' - 1) + s;
|
||||
}
|
||||
else
|
||||
{
|
||||
rs = s + string(1, m_row + 'A' - 1);
|
||||
res = s + string(1, m_row + 'A' - 1);
|
||||
}
|
||||
return rs;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -63,6 +63,13 @@ Game::~Game()
|
|||
}
|
||||
|
||||
|
||||
const Player& Game::getPlayer(int num) const
|
||||
{
|
||||
ASSERT(0 <= num && num < (int)m_players.size(), "Wrong player number");
|
||||
return *(m_players[num]);
|
||||
}
|
||||
|
||||
|
||||
Game * Game::load(FILE *fin, const Dictionary &iDic)
|
||||
{
|
||||
char buff[4096];
|
||||
|
@ -319,7 +326,7 @@ void Game::save(ostream &out) const
|
|||
out << endl;
|
||||
for (int i = 0; i < getNPlayers(); i++)
|
||||
{
|
||||
string rack = formatPlayedRack(m_players[i]->getCurrentRack());
|
||||
string rack = m_players[i]->getCurrentRack().toString();
|
||||
out << "Rack " << i << ": " << rack << endl;
|
||||
}
|
||||
}
|
||||
|
@ -703,42 +710,13 @@ int Game::helperSetRackManual(int p, bool iCheck, const string &iLetters)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*********************************************************
|
||||
*********************************************************/
|
||||
|
||||
string Game::formatCoords(const Round &iRound) const
|
||||
{
|
||||
ASSERT(iRound.getCoord().isValid(), "Invalid coordinates");
|
||||
return iRound.getCoord().toString();
|
||||
}
|
||||
|
||||
|
||||
string Game::formatPlayedRack(const PlayedRack &iRack, bool showExtraSigns) const
|
||||
{
|
||||
vector<Tile> tiles;
|
||||
unsigned int i;
|
||||
string s;
|
||||
|
||||
iRack.getOldTiles(tiles);
|
||||
for (i = 0; i < tiles.size(); i++)
|
||||
s += tiles[i].toChar();
|
||||
|
||||
iRack.getNewTiles(tiles);
|
||||
if (showExtraSigns && i > 0 && tiles.size())
|
||||
s += '+';
|
||||
|
||||
for (i = 0; i < tiles.size(); i++)
|
||||
s += tiles[i].toChar();
|
||||
return s;
|
||||
}
|
||||
|
||||
/*********************************************************
|
||||
*********************************************************/
|
||||
|
||||
string Game::getPlayedRack(int num) const
|
||||
{
|
||||
ASSERT(0 <= num && num < getNRounds(), "Wrong turn number");
|
||||
return formatPlayedRack(*m_rackHistory[num]);
|
||||
return m_rackHistory[num]->toString();
|
||||
}
|
||||
|
||||
|
||||
|
@ -762,7 +740,7 @@ string Game::getPlayedWord(int num) const
|
|||
string Game::getPlayedCoords(int num) const
|
||||
{
|
||||
ASSERT(0 <= num && num < getNRounds(), "Wrong turn number");
|
||||
return formatCoords(*m_roundHistory[num]);
|
||||
return m_roundHistory[num]->getCoord().toString();
|
||||
}
|
||||
|
||||
|
||||
|
@ -789,17 +767,9 @@ int Game::getPlayedPlayer(int num) const
|
|||
/*********************************************************
|
||||
*********************************************************/
|
||||
|
||||
int Game::getPlayerPoints(int num) const
|
||||
string Game::getPlayerRack(int num, bool iShowExtraSigns) const
|
||||
{
|
||||
ASSERT(0 <= num && num < getNPlayers(), "Wrong player number");
|
||||
return m_players[num]->getPoints();
|
||||
}
|
||||
|
||||
|
||||
string Game::getPlayerRack(int num, bool showExtraSigns) const
|
||||
{
|
||||
ASSERT(0 <= num && num < getNPlayers(), "Wrong player number");
|
||||
return formatPlayedRack(m_players[num]->getCurrentRack(), showExtraSigns);
|
||||
return getPlayer(num).getCurrentRack().toString(iShowExtraSigns);
|
||||
}
|
||||
|
||||
|
||||
|
|
11
game/game.h
11
game/game.h
|
@ -69,9 +69,6 @@ public:
|
|||
kJOKER // Joker game
|
||||
};
|
||||
|
||||
const Board& getBoard() const { return m_board; }
|
||||
const Bag& getBag() const { return m_bag; }
|
||||
|
||||
/**
|
||||
* Accessors for the variant of the game.
|
||||
* The variant can be changed during a game without any problem
|
||||
|
@ -87,6 +84,10 @@ public:
|
|||
const Dictionary & getDic() const { return *m_dic; }
|
||||
void setDic(const Dictionary &iDic) { m_dic = &iDic; }
|
||||
|
||||
const Board& getBoard() const { return m_board; }
|
||||
const Bag& getBag() const { return m_bag; }
|
||||
const Player& getPlayer(int iIndex) const;
|
||||
|
||||
/**
|
||||
* Saved games handling.
|
||||
*
|
||||
|
@ -143,7 +144,6 @@ public:
|
|||
virtual void addHumanPlayer();
|
||||
// TODO: Ability to specify which kind of AI player is wanted
|
||||
virtual void addAIPlayer();
|
||||
int getPlayerPoints(int) const;
|
||||
string getPlayerRack(int, bool = false) const;
|
||||
|
||||
int currPlayer() const { return m_currPlayer; }
|
||||
|
@ -200,9 +200,6 @@ protected:
|
|||
int helperSetRackRandom(int p, bool iCheck, set_rack_mode mode);
|
||||
int helperSetRackManual(int p, bool iCheck, const string &iLetters);
|
||||
|
||||
string formatCoords(const Round &iRound) const;
|
||||
string formatPlayedRack(const PlayedRack &iRack,
|
||||
bool showExtraSigns = true) const;
|
||||
void prevPlayer();
|
||||
void nextPlayer();
|
||||
bool rackInBag(const Rack &iRack, const Bag &iBag) const;
|
||||
|
|
|
@ -163,22 +163,19 @@ void PlayedRack::operator=(const PlayedRack &iOther)
|
|||
}
|
||||
|
||||
|
||||
void PlayedRack::toString(string& s) const
|
||||
string PlayedRack::toString(bool iShowExtraSigns) const
|
||||
{
|
||||
vector<Tile>::const_iterator it;
|
||||
s = "";
|
||||
if (nOld() > 0)
|
||||
{
|
||||
for (it = m_oldTiles.begin(); it != m_oldTiles.end(); it++)
|
||||
s += it->toChar();
|
||||
}
|
||||
if (nOld() > 0 && nNew() > 0)
|
||||
{
|
||||
string s;
|
||||
|
||||
for (it = m_oldTiles.begin(); it != m_oldTiles.end(); it++)
|
||||
s += it->toChar();
|
||||
|
||||
if (iShowExtraSigns && nOld() > 0 && nNew() > 0)
|
||||
s += "+";
|
||||
}
|
||||
if (nNew() > 0)
|
||||
{
|
||||
for (it = m_newTiles.begin(); it != m_newTiles.end(); it++)
|
||||
s += it->toChar();
|
||||
}
|
||||
|
||||
for (it = m_newTiles.begin(); it != m_newTiles.end(); it++)
|
||||
s += it->toChar();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#define _PLAYEDRACK_H_
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "tile.h"
|
||||
|
||||
class Rack;
|
||||
|
@ -64,7 +65,7 @@ public:
|
|||
bool checkRack(int iMin) const;
|
||||
|
||||
void operator=(const PlayedRack &iOther);
|
||||
void toString(string&) const;
|
||||
string toString(bool iShowExtraSigns = true) const;
|
||||
|
||||
private:
|
||||
vector<Tile> m_oldTiles;
|
||||
|
|
|
@ -41,8 +41,7 @@ struct less_points : public binary_function<const Round&,
|
|||
|
||||
const Round & Results::get(int i) const
|
||||
{
|
||||
ASSERT(0 <= i && i < size(),
|
||||
"Results index out of bounds");
|
||||
ASSERT(0 <= i && i < size(), "Results index out of bounds");
|
||||
return m_rounds[i];
|
||||
}
|
||||
|
||||
|
|
|
@ -193,28 +193,24 @@ string Training::getSearchedWord(int num) const
|
|||
|
||||
string Training::getSearchedCoords(int num) const
|
||||
{
|
||||
ASSERT(0 <= num && num < m_results.size(), "Wrong result number");
|
||||
return formatCoords(m_results.get(num));
|
||||
return m_results.get(num).getCoord().toString();
|
||||
}
|
||||
|
||||
|
||||
int Training::getSearchedPoints(int num) const
|
||||
{
|
||||
ASSERT(0 <= num && num < m_results.size(), "Wrong result number");
|
||||
return m_results.get(num).getPoints();
|
||||
}
|
||||
|
||||
|
||||
int Training::getSearchedBonus(int num) const
|
||||
{
|
||||
ASSERT(0 <= num && num < m_results.size(), "Wrong result number");
|
||||
return m_results.get(num).getBonus();
|
||||
}
|
||||
|
||||
|
||||
void Training::testPlay(int num)
|
||||
{
|
||||
ASSERT(0 <= num && num < m_results.size(), "Wrong result number");
|
||||
m_board.testRound(m_results.get(num));
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "game_io.h"
|
||||
#include "game.h"
|
||||
#include "training.h"
|
||||
#include "player.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -202,7 +203,7 @@ void GameIO::printSearchResults(ostream &out, const Training &iGame, int num)
|
|||
|
||||
void GameIO::printPoints(ostream &out, const Game &iGame)
|
||||
{
|
||||
out << iGame.getPlayerPoints(0) << endl;
|
||||
out << iGame.getPlayer(0).getPoints() << endl;
|
||||
}
|
||||
|
||||
|
||||
|
@ -211,7 +212,7 @@ void GameIO::printAllPoints(ostream &out, const Game &iGame)
|
|||
for (int i = 0; i < iGame.getNPlayers(); i++)
|
||||
{
|
||||
out << "Joueur " << i << ": "
|
||||
<< setw(4) << iGame.getPlayerPoints(i) << endl;
|
||||
<< setw(4) << iGame.getPlayer(i).getPoints() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "training.h"
|
||||
#include "duplicate.h"
|
||||
#include "freegame.h"
|
||||
#include "player.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -185,7 +186,7 @@ void CursesIntf::drawScoresRacks(WINDOW *win, int y, int x) const
|
|||
if (m_game->getMode() != Game::kTRAINING && i == m_game->currPlayer())
|
||||
attron(A_BOLD);
|
||||
mvwprintw(win, y + i + 1, x + 2,
|
||||
_("Player %d: %d"), i, m_game->getPlayerPoints(i));
|
||||
_("Player %d: %d"), i, m_game->getPlayer(i).getPoints());
|
||||
if (m_game->getMode() != Game::kTRAINING && i == m_game->currPlayer())
|
||||
attroff(A_BOLD);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ using namespace std;
|
|||
#include "dic.h"
|
||||
#include "game.h"
|
||||
#include "game_factory.h"
|
||||
#include "player.h"
|
||||
|
||||
#include "configdb.h"
|
||||
#include "confdimdlg.h"
|
||||
|
@ -349,7 +350,7 @@ MainFrame::UpdateStatusBar()
|
|||
{
|
||||
text << wxT("coup:") << (m_game->getNRounds() + 1)
|
||||
<< wxT(" ")
|
||||
<< wxT("points:") << m_game->getPlayerPoints(0);
|
||||
<< wxT("points:") << m_game->getPlayer(0).getPoints();
|
||||
}
|
||||
if (statusbar)
|
||||
statusbar->SetStatusText(text, 1);
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include "dic.h"
|
||||
#include "game.h"
|
||||
#include "player.h"
|
||||
|
||||
#include "configdb.h"
|
||||
#include "printout.h"
|
||||
|
@ -186,7 +187,7 @@ GamePrintout::DrawTextLine(wxDC *dc, int numline, long basey, long heightT, floa
|
|||
// total points
|
||||
if (numline == m_game.getNRounds() + 1)
|
||||
{
|
||||
str << m_game.getPlayerPoints(0);
|
||||
str << m_game.getPlayer(0).getPoints();
|
||||
DRW(4);
|
||||
}
|
||||
#undef DIM
|
||||
|
|
Loading…
Add table
Reference in a new issue