00001 #ifndef KWIN4DOC_H
00002 #define KWIN4DOC_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <QList>
00025
00026
00027 #include <kgame.h>
00028 #include <kgameio.h>
00029 #include <kgamepropertyarray.h>
00030 #include <kconfig.h>
00031
00032
00033 #include "kwin4global.h"
00034 #include "kwin4player.h"
00035
00036 class KWin4View;
00037 class QGraphicsItem;
00038 class Score;
00039
00040
00044 class KWin4Doc : public KGame
00045 {
00046 Q_OBJECT
00047
00048 public:
00052 KWin4Doc(QWidget *parent);
00053
00056 ~KWin4Doc();
00057
00061 void setView(KWin4View *view);
00062
00065 void initPlayers();
00066
00073 bool loadgame(QDataStream &stream, bool network, bool reset);
00074
00078 void readConfig(KConfig* config);
00079
00083 void writeConfig(KConfig* config);
00084
00085
00089 void endGame(TABLE mode);
00090
00093 void resetStatistic();
00094
00098 bool redoMove();
00099
00103 bool undoMove();
00104
00107 void calculateHint();
00108
00115 int getStatistic(COLOUR col, TABLE mode);
00116
00121 QString getName(COLOUR col);
00122
00127 void setName(COLOUR col, const QString& n);
00128
00133 KGameIO::IOMode playedBy(int col);
00134
00139 void setPlayedBy(int col,KGameIO::IOMode mode);
00140
00145 KWin4Player* getPlayer(COLOUR col);
00146
00150 COLOUR switchStartPlayer();
00151
00155 void setCurrentPlayer(COLOUR no);
00156
00160 COLOUR getCurrentPlayer();
00161
00165 int getCurrentMove();
00166
00170 int getMaxMove();
00171
00175 int getHistoryCnt();
00176
00177
00178 protected:
00184 void createIO(KPlayer* player, KGameIO::IOMode io);
00185
00193 KPlayer* createPlayer(int rtti, int io, bool isvirtual);
00194
00199 KPlayer* nextPlayer(KPlayer* last, bool exclusive=true);
00200
00209 void newPlayersJoin(KGamePlayerList* list, KGamePlayerList* newList, QList<int>& inactive);
00210
00214 void resetGame(bool initview);
00215
00222 MOVESTATUS makeMove(int x,int mode);
00223
00229 bool doMove(int x, int id);
00230
00236 int checkGameOver(KPlayer *player);
00237
00243 int checkGameOver(int x, COLOUR col);
00244
00250 void prepareGameMessage(QDataStream& stream, qint32 pl);
00251
00259 bool playerInput(QDataStream& msg, KPlayer* player);
00260
00263 void recalcIO();
00264
00268 void activateCurrentPlayer();
00269
00273 QString findProcessName();
00274
00278 void setScore(long value);
00279
00285 void setColour(int x,int y,COLOUR c);
00286
00292 COLOUR getColour(int x,int y);
00293
00299 COLOUR getPlayerColour(int player);
00300
00301 public slots:
00306 void moveDone(int mode);
00307
00311 void loadSettings();
00312
00313 protected slots:
00318 void repeatMove();
00319
00325 void processAIHintCommand(QDataStream& in, KGameProcessIO *io);
00326
00332 void processAICommand(QDataStream& in, KGameProcessIO* io);
00333
00340 void clientConnected(quint32 cid, KGame* me);
00341
00349 void prepareAITurn(QDataStream &stream,bool b,KGameIO *input,bool *eatevent);
00350
00356 void networkMessageUpdate(int id, quint32 sender, quint32 receiver);
00357
00363 void playerPropertyChanged(KGamePropertyBase* prop, KPlayer* player);
00364
00370 void gamePropertyChanged(KGamePropertyBase* prop, KGame* me);
00371
00372 signals:
00375 void signalGameRun();
00376
00380 void signalChatChanged(KWin4Player* player);
00381
00385 void signalNextPlayer(int playerNumber);
00386
00387 private:
00388
00389 KWin4View *pView;
00390
00391
00392 KGamePropertyInt mLastColumn;
00393
00394
00395 KGamePropertyInt mLastColour;
00396
00397
00398 KGamePropertyInt mHistoryCnt;
00399
00400
00401 KGamePropertyArray<int> mField;
00402
00403
00404 KGamePropertyInt mStartPlayer;
00405
00406
00407 KGamePropertyInt mAmzug;
00408
00409
00410 KGamePropertyInt mMaxMove;
00411
00412
00413 KGamePropertyInt mCurrentMove;
00414
00415
00416 KGamePropertyArray<int> mFieldFilled;
00417
00418
00419 KGamePropertyInt mLastHint;
00420
00421
00422 KGamePropertyInt mScore;
00423
00424
00425 KGamePropertyArray<int> mHistory;
00426
00427
00428 KGameIO::IOMode mPlayedBy[2];
00429
00430
00431 KGameProcessIO *mHintProcess;
00432
00433
00434 Score* mStatus;
00435 };
00436
00437 #endif // KWIN4DOC_H
00438