00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _GAME_H_
00022 #define _GAME_H_
00023
00024 #include <string>
00025 #include <vector>
00026 #include <iostream>
00027 #include "bag.h"
00028 #include "board.h"
00029 #include "history.h"
00030
00031 class Player;
00032 class PlayedRack;
00033 class Round;
00034 class Rack;
00035 class Turn;
00036 typedef struct _Dictionary * Dictionary;
00037
00038 using namespace std;
00039
00040
00041
00042
00043
00044 #define IDENT_STRING "Eliot"
00045
00046
00047
00048
00049
00050
00051 class Game
00052 {
00053 public:
00054 Game(const Dictionary &iDic);
00055 virtual ~Game();
00056
00057
00058 enum GameMode
00059 {
00060 kTRAINING,
00061 kFREEGAME,
00062 kDUPLICATE
00063 };
00064 virtual GameMode getMode() const = 0;
00065 virtual string getModeAsString() const = 0;
00066
00067
00068 enum GameVariant
00069 {
00070 kNONE,
00071 kJOKER
00072 };
00073
00074
00075
00076
00077
00078
00079 void setVariant(GameVariant iVariant) { m_variant = iVariant; }
00080 GameVariant getVariant() const { return m_variant; }
00081
00082
00083
00084
00085
00086 const Dictionary & getDic() const { return *m_dic; }
00087 void setDic(const Dictionary &iDic) { m_dic = &iDic; }
00088
00089 const Board& getBoard() const { return m_board; }
00090 const Bag& getBag() const { return m_bag; }
00091 const Player& getPlayer(int iNum) const;
00092 const Turn& getTurn(int iNum) const;
00093 const Player& getCurrentPlayer() const { return getPlayer(currPlayer()); };
00094
00095
00096
00097
00098 typedef enum {
00099 FILE_FORMAT_STANDARD,
00100 FILE_FORMAT_ADVANCED
00101 } game_file_format;
00102
00103
00104
00105
00106
00107
00108
00109
00110 static Game * load(FILE *fin, const Dictionary &iDic);
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 void save(ostream &out, game_file_format format=FILE_FORMAT_STANDARD) const;
00121
00122
00123
00124
00125
00126 int back(int);
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 static const int RACK_SIZE;
00145 enum set_rack_mode {RACK_ALL, RACK_NEW, RACK_MANUAL};
00146 int setRack(int player, set_rack_mode mode, bool check, const string& str);
00147 string getPlayerRack(int, PlayedRack::display_mode mode = PlayedRack::RACK_SIMPLE) const;
00148
00149
00150
00151
00152
00153 const History& getHistory() const { return m_history; }
00154
00155
00156
00157
00158
00159 int getNPlayers() const { return m_players.size(); }
00160 int getNHumanPlayers() const;
00161 virtual void addHumanPlayer();
00162
00163 virtual void addAIPlayer();
00164 int currPlayer() const { return m_currPlayer; }
00165
00166
00167
00168
00169 virtual int start() = 0;
00170 virtual int play(const string &iCoord, const string &iWord) = 0;
00171 virtual int endTurn() = 0;
00172
00173 protected:
00174
00175 vector<Player*> m_players;
00176
00177 int m_currPlayer;
00178
00179
00180
00181
00182
00183 GameVariant m_variant;
00184
00185
00186 const Dictionary * m_dic;
00187
00188
00189 Bag m_bag;
00190
00191
00192 Board m_board;
00193
00194
00195
00196
00197
00198 History m_history;
00199
00200 int m_points;
00201
00202 bool m_finished;
00203
00204
00205
00206
00207
00208 int helperPlayRound(const Round &iRound);
00209 int helperSetRackRandom(int p, bool iCheck, set_rack_mode mode);
00210 int helperSetRackManual(int p, bool iCheck, const string &iLetters);
00211
00212 void prevPlayer();
00213 void nextPlayer();
00214 bool rackInBag(const Rack &iRack, const Bag &iBag) const;
00215 void realBag(Bag &iBag) const;
00216 int checkPlayedWord(const string &iCoord,
00217 const string &iWord, Round &oRound);
00218
00219
00220
00221
00222
00223 static Game* gameLoadFormat_14(FILE *fin, const Dictionary& iDic);
00224
00225
00226
00227
00228
00229 static Game* gameLoadFormat_15(FILE *fin, const Dictionary& iDic);
00230
00231
00232
00233
00234 void Game::gameSaveFormat_14(ostream &out) const;
00235
00236
00237
00238
00239 void Game::gameSaveFormat_15(ostream &out) const;
00240
00241 };
00242
00243 #endif
00244
00245
00246
00247
00248
00249
00250