00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <iomanip>
00022 #include <string>
00023
00024 #include "game_io.h"
00025 #include "game.h"
00026 #include "training.h"
00027 #include "player.h"
00028
00029 using namespace std;
00030
00031
00032 void GameIO::printBoard(ostream &out, const Game &iGame)
00033 {
00034 int row, col;
00035
00036 out << " ";
00037 for (col = BOARD_MIN; col <= BOARD_MAX; col++)
00038 out << setw(3) << col - BOARD_MIN + 1;
00039 out << endl;
00040 for (row = BOARD_MIN; row <= BOARD_MAX; row++)
00041 {
00042 out << " " << (char)(row - BOARD_MIN + 'A') << " ";
00043 for (col = BOARD_MIN; col <= BOARD_MAX; col++)
00044 {
00045 char l = iGame.getBoard().getChar(row, col);
00046 out << setw(3) << (l ? l : '-');
00047 }
00048 out << endl;
00049 }
00050 }
00051
00052
00053 void GameIO::printBoardJoker(ostream &out, const Game &iGame)
00054 {
00055 int row,col;
00056
00057 out << " ";
00058 for (col = BOARD_MIN; col <= BOARD_MAX; col++)
00059 out << setw(3) << col - BOARD_MIN + 1;
00060 out << endl;
00061
00062 for (row = BOARD_MIN; row <= BOARD_MAX; row++)
00063 {
00064 out << " " << (char)(row - BOARD_MIN + 'A') << " ";
00065 for (col = BOARD_MIN; col <= BOARD_MAX; col++)
00066 {
00067 char l = iGame.getBoard().getChar(row, col);
00068 bool j = (iGame.getBoard().getCharAttr(row, col) & ATTR_JOKER);
00069
00070 out << " " << (j ? '.' : (l ? ' ' : '-'));
00071 out << (l ? l : '-');
00072 }
00073 out << endl;
00074 }
00075 }
00076
00077
00078 void GameIO::printBoardMultipliers(ostream &out, const Game &iGame)
00079 {
00080 int row, col;
00081
00082 out << " ";
00083 for (col = BOARD_MIN; col <= BOARD_MAX; col++)
00084 out << setw(3) << col - BOARD_MIN + 1;
00085 out << endl;
00086
00087 for (row = BOARD_MIN; row <= BOARD_MAX; row++)
00088 {
00089 out << " " << (char)(row - BOARD_MIN + 'A') << " ";
00090 for (col = BOARD_MIN; col <= BOARD_MAX; col++)
00091 {
00092 char l = iGame.getBoard().getChar(row, col);
00093 if (l != 0)
00094 out << " " << l;
00095 else
00096 {
00097 int wm = iGame.getBoard().getWordMultiplier(row, col);
00098 int tm = iGame.getBoard().getLetterMultiplier(row, col);
00099
00100 if (wm > 1)
00101 out << " " << ((wm == 3) ? '@' : '#');
00102 else if (tm > 1)
00103 out << " " << ((tm == 3) ? '*' : '+');
00104 else
00105 out << " -";
00106 }
00107 }
00108 out << endl;
00109 }
00110 }
00111
00112
00113 void GameIO::printBoardMultipliers2(ostream &out, const Game &iGame)
00114 {
00115 int row, col;
00116
00117 out << " ";
00118 for (col = BOARD_MIN; col <= BOARD_MAX; col++)
00119 out << setw(3) << col - BOARD_MIN + 1;
00120 out << endl;
00121
00122 for (row = BOARD_MIN; row <= BOARD_MAX; row++)
00123 {
00124 out << " " << (char)(row - BOARD_MIN + 'A') << " ";
00125 for (col = BOARD_MIN; col <= BOARD_MAX; col++)
00126 {
00127 char l = iGame.getBoard().getChar(row, col);
00128 int wm = iGame.getBoard().getWordMultiplier(row, col);
00129 int tm = iGame.getBoard().getLetterMultiplier(row, col);
00130
00131 if (wm > 1)
00132 out << " " << ((wm == 3) ? '@' : '#');
00133 else if (tm > 1)
00134 out << " " << ((tm == 3) ? '*' : '+');
00135 else
00136 out << " -";
00137 out << (l ? l : '-');
00138 }
00139 out << endl;
00140 }
00141 }
00142
00143
00144 void GameIO::printNonPlayed(ostream &out, const Game &iGame)
00145 {
00146 const list<Tile>& allTiles = Tile::getAllTiles();
00147 list<Tile>::const_iterator it;
00148
00149 for (it = allTiles.begin(); it != allTiles.end(); it++)
00150 {
00151 if (iGame.getBag().in(it->toChar()) > 9)
00152 out << " ";
00153 out << setw(2) << it->toChar();
00154 }
00155 out << endl;
00156
00157 for (it = allTiles.begin(); it != allTiles.end(); it++)
00158 {
00159 out << " " << iGame.getBag().in(it->toChar());
00160 }
00161 out << endl;
00162 }
00163
00164
00165 void GameIO::printPlayedRack(ostream &out, const Game &iGame, int n)
00166 {
00167 out << iGame.getPlayerRack(iGame.currPlayer(),PlayedRack::RACK_SIMPLE) << endl;
00168 }
00169
00170
00171 void GameIO::printAllRacks(ostream &out, const Game &iGame)
00172 {
00173 for (int j = 0; j < iGame.getNPlayers(); j++)
00174 {
00175 out << "Joueur " << j << ": ";
00176 out << iGame.getPlayerRack(j,PlayedRack::RACK_SIMPLE) << endl;
00177 }
00178 }
00179
00180
00181 static void searchResultLine(ostream &out, const Training &iGame, int num)
00182 {
00183 const Results &res = iGame.getResults();
00184 Round r = res.get(num);
00185 string word = r.getWord();
00186 if (word.size() == 0)
00187 return;
00188 out << word << string(16 - word.size(), ' ')
00189 << (r.getBonus() ? '*' : ' ')
00190 << setw(4) << r.getPoints()
00191 << ' ' << r.getCoord().toString();
00192 }
00193
00194
00195 void GameIO::printSearchResults(ostream &out, const Training &iGame, int num)
00196 {
00197 int size = (int) iGame.getResults().size();
00198 for (int i = 0; i < num && i < size; i++)
00199 {
00200 out << setw(3) << i + 1 << ": ";
00201 searchResultLine(out, iGame, i);
00202 out << endl;
00203 }
00204 }
00205
00206
00207 void GameIO::printPoints(ostream &out, const Game &iGame)
00208 {
00209 out << iGame.getPlayer(0).getPoints() << endl;
00210 }
00211
00212
00213 void GameIO::printAllPoints(ostream &out, const Game &iGame)
00214 {
00215 for (int i = 0; i < iGame.getNPlayers(); i++)
00216 {
00217 out << "Joueur " << i << ": "
00218 << setw(4) << iGame.getPlayer(i).getPoints() << endl;
00219 }
00220 }
00221