kwin4doc.h

Go to the documentation of this file.
00001 #ifndef KWIN4DOC_H
00002 #define KWIN4DOC_H
00003 /*
00004    This file is part of the KDE games kwin4 program
00005    Copyright (c) 2006 Martin Heni <kde@heni-online.de>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.
00021 */
00022 
00023 // Qt Includes
00024 #include <QList>
00025 
00026 // KDE includes
00027 #include <kgame.h>
00028 #include <kgameio.h>
00029 #include <kgamepropertyarray.h>
00030 #include <kconfig.h>
00031 
00032 // Local includes
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     // The view
00389     KWin4View *pView;
00390 
00391     // Last x position moved to
00392     KGamePropertyInt mLastColumn;  
00393 
00394     // Colour of last move
00395     KGamePropertyInt mLastColour;  
00396     
00397     // Amount of info in history
00398     KGamePropertyInt mHistoryCnt; 
00399 
00400     // 42 pieces construct the game board
00401     KGamePropertyArray<int> mField;
00402 
00403     // Player who started game
00404     KGamePropertyInt mStartPlayer;  
00405 
00406     // Player's to move
00407     KGamePropertyInt mAmzug; 
00408 
00409     // Maximal move made in a game before undo
00410     KGamePropertyInt mMaxMove; 
00411 
00412     // Current move number in the game
00413     KGamePropertyInt mCurrentMove; 
00414 
00415     // To what height is a column filled
00416     KGamePropertyArray<int> mFieldFilled; 
00417 
00418     // Position of last hint given
00419     KGamePropertyInt mLastHint;
00420 
00421     // Computer score value (position estimation)
00422     KGamePropertyInt mScore;  
00423 
00424     // History of all moves (x positions)
00425     KGamePropertyArray<int> mHistory; 
00426 
00427     // Input device of players
00428     KGameIO::IOMode mPlayedBy[2];
00429 
00430     // Process AI for hints
00431     KGameProcessIO *mHintProcess;
00432 
00433     // Score and status storage to communicate with view
00434     Score* mStatus; 
00435 };
00436 
00437 #endif // KWIN4DOC_H
00438 

Generated on Sun Mar 4 10:56:43 2007 for KWin4 by  doxygen 1.4.6