remove old files add new sources
[mancala] / src / GameController.h
1 /*
2 Mancala - A Historical Board Game
3 Copyright (C) 2009-2010 A.H.M.Mahfuzur Rahman 65mahfuz90@gmail.com
4 Copyright (c) 2010 Reto Zingg g.d0b3rm4n@gmail.com
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef GAMECONTROLLER_H
21 #define GAMECONTROLLER_H
22
23 #include <QPair>
24 #include <QList>
25
26 // #include <kxmlguiwindow.h>
27
28 #include <QSignalMapper>
29 #include <QThread>
30
31 #include "GameInfo.h"
32
33
34 class Board;
35 class Score;
36 class MoveGenerator;
37
38 class GameController : public QThread{
39
40     Q_OBJECT
41 public:
42     enum Side{UPPER,LOWER};
43     enum Difficulty{EASY,MEDIUM,HARD};
44
45     GameController(GameInfo*);
46
47     void setBoardItem(Board* board);
48     void initializeGameController();
49     int humanKalahIndex(){ return m_humanKalah; }
50     QPair< bool,QList<int> > logicalMoveController(QList<int>board,int cupIndex,bool turn);
51
52 signals:
53     void signalShowScore(int,bool);   //score,whose
54     void signalShowTurn(bool);
55     void signalMessage(const QString);
56     void signalGameOver();
57     void timeout(int);
58     void timeout(const QString&);
59     void signalSowMaker(int index);
60     void signalAfterSow(int index);
61     void signalComputerMove();
62
63     void signalNewGame(int);
64     void signalRestartGame();
65
66 public slots:
67     void slotMouseClicked(int);
68     void slotGameOverForNewGame(int );
69     void slotGameOverForRestartGame();
70     void newGameEmitter(int);
71     void restartGameEmitter();
72
73     void makeHumanMove(int);
74     void makeComputerMove();
75     void crossCapture(const QString&);
76     void countCapture(const QString&);
77     void slotGameDifficulty(GameController::Difficulty difficulty);
78     void sowMaker(int index);
79     void sowController();
80     void afterSow(int index);
81
82 private:
83     QSignalMapper *signalMapper;
84
85     int m_index;
86     int m_rotationInfo;
87     bool m_multipleLapDelay;
88
89     Difficulty m_gameDifficulty;
90     Board* m_board;
91     GameInfo* m_gameInfo;
92     Score* m_humanScore;
93     Score* m_computerScore;
94     Side m_humanSide;
95     MoveGenerator *m_moveGenerator;
96
97     int m_humanKalah;
98     bool m_humanTurn;
99     bool m_gamePaused;
100     bool m_gameOver;
101     bool m_physicalMoveAllowed; //Will be used to check invalid move
102     int m_cupIndexClicked;
103
104     //totalStone - first 2*cupPerRow(0,..) will be cupInfo, next 2 KalahInfo(left,right)
105     QList<int> m_logicalBoard;
106     QList<int> m_physicalBoard;
107     QList<QPair< GameInfo::Side,QList<int> > > m_captureInfo;
108     QList<int>m_humanSideCups;
109
110     void setPhysicalBoard(QList<int> board);
111     void setLogicalBoard(QList<int> board);
112     QList<int> physicalBoard();
113     QList<int> logicalBoard();
114
115     void initializeBoard();
116     void setHumanSideCups();
117
118     bool isHumanCup(int index);
119     bool isHumanKalah(int index);
120     bool isGameOver(QList<int>& board);
121
122     void handleCrossCapture(int,QList<int>& board);
123     int handleCountNSeriesCapture(int,QList<int>& board);
124     int nextIndex(int index,int seriesCaptureIndex);
125     bool stoneNumberMatched(int index,int countCaptureIndex,QList<int>& board);
126
127     void changeTurn();
128     void showBoard(QList<int>&);
129     void changeScore(int amount,bool human);
130
131     bool isHumanSideEmpty(QList<int>& board);
132     bool isComputerSideEmpty(QList<int>& board);
133     void computerHasNoMove();
134     void humanHasNoMove();
135     void finalCapture(QList<int>& board);
136     void sowingAnimation(int index,int multiplier);
137     int singleSow(int index);
138
139     bool physicalMoveController(int index);
140     bool isEndOfLap(int index,QList<int>& board);
141
142 };
143
144
145 #endif // GAMECONTROLLER_H