1 | /* |
2 | Copyright 2003 Russell Steffen <rsteffen@bayarea.net> |
3 | Copyright 2003 Stephan Zehetner <s.zehetner@nevox.org> |
4 | Copyright 2006 Dmitry Suzdalev <dimsuz@gmail.com> |
5 | Copyright 2006 Inge Wallin <inge@lysator.liu.se> |
6 | Copyright 2006 Pierre Ducroquet <pinaraf@gmail.com> |
7 | |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by |
10 | the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
21 | */ |
22 | |
23 | #ifndef GAME_H |
24 | #define GAME_H |
25 | |
26 | #include <QObject> |
27 | #include <QStateMachine> |
28 | #include <QFinalState> |
29 | #include <QState> |
30 | |
31 | #include <krandomsequence.h> |
32 | |
33 | #include "fleet.h" |
34 | #include "players/player.h" |
35 | #include "players/neutralplayer.h" |
36 | #include "map/map.h" |
37 | |
38 | class KLocalizedString; |
39 | |
40 | struct GameOptions |
41 | { |
42 | bool BlindMap, CumulativeProduction, ProductionAfterConquere; |
43 | bool NeutralsShowShips, NeutralsShowStats; |
44 | int NeutralsProduction; |
45 | }; |
46 | |
47 | /** |
48 | * This is the main class of the game. |
49 | * It contains most of the game logic, ie. the finite state machine. |
50 | */ |
51 | class Game : public QObject |
52 | { |
53 | Q_OBJECT |
54 | public: |
55 | explicit Game(QObject *parent = 0); |
56 | |
57 | bool isRunning(); |
58 | |
59 | virtual void start() = 0; |
60 | |
61 | virtual void stop() = 0; |
62 | |
63 | bool attack( Planet *sourcePlanet, Planet *destPlanet, int shipCouna, bool standingOrder = false); |
64 | |
65 | static Coordinate generatePlanetCoordinates (int rows, int cols); |
66 | static double generateKillPercentage(); |
67 | static int generatePlanetProduction(); |
68 | QList<Planet *> planets(); |
69 | |
70 | Map *map() { return m_map; } |
71 | |
72 | Player *currentPlayer() { return m_currentPlayer; } |
73 | |
74 | QList<Player *> players() { return m_players; } |
75 | |
76 | void findWinner(); |
77 | |
78 | GameOptions &options() { return m_options; } |
79 | |
80 | NeutralPlayer *neutral() { return m_neutral; } |
81 | |
82 | void setPlayers (const QList<Player *> &players); |
83 | |
84 | int turnCounter() const { return m_turnCounter; } |
85 | |
86 | bool doFleetArrival (AttackFleet *fleet); |
87 | signals: |
88 | void started(); |
89 | void finished(); |
90 | void waitingForPlayer(Player *player); |
91 | void gameMsg( const KLocalizedString &msg, Player *player = 0, |
92 | Planet *planet = 0, Player *planetPlayer = 0 ); |
93 | |
94 | private: |
95 | static KRandomSequence random; |
96 | |
97 | Player *m_currentPlayer; |
98 | |
99 | void makeKill(Fleet *fleet, Player *player); |
100 | |
101 | public slots: |
102 | |
103 | private slots: |
104 | void newTurn() { m_turnCounter++; } |
105 | |
106 | protected: |
107 | // Points to the Map we're playing on. |
108 | Map *m_map; |
109 | GameOptions m_options; |
110 | |
111 | virtual void buildMachine() = 0; |
112 | QFinalState *m_finalState; |
113 | QStateMachine m_gameMachine; |
114 | NeutralPlayer *m_neutral; |
115 | |
116 | int m_turnCounter; |
117 | |
118 | QList<Player *> m_players; |
119 | |
120 | |
121 | |
122 | void setCurrentPlayer(Player *player); |
123 | |
124 | friend class Player; |
125 | }; |
126 | |
127 | #endif // GAME_H |
128 | |