forked from KDE/kpat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dealer.h
292 lines (219 loc) · 8.38 KB
/
dealer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*
* Copyright (C) 1995 Paul Olav Tvete <[email protected]>
* Copyright (C) 2000-2009 Stephan Kulow <[email protected]>
* Copyright (C) 2009-2010 Parker Coates <[email protected]>
*
* License of original code:
* -------------------------------------------------------------------------
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation.
*
* This file is provided AS IS with no warranties of any kind. The author
* shall have no liability with respect to the infringement of copyrights,
* trade secrets or any patents by this file or any part thereof. In no
* event will the author be liable for any lost revenue or profits or
* other special, indirect and consequential damages.
* -------------------------------------------------------------------------
*
* License of modifications/additions made after 2009-01-01:
* -------------------------------------------------------------------------
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
*/
#ifndef DEALER_H
#define DEALER_H
class CardDiff;
class DealerInfo;
#include "gamestate.h"
class MessageBox;
class MoveHint;
#include "patpile.h"
class Solver;
class SolverThread;
#include "speeds.h"
#include "view.h"
#include "patsolve/patsolve.h"
#include "KCardDeck"
#include "KCardScene"
class QAction;
#include <QMap>
#include <QStack>
#include <QTimer>
class QDomDocument;
class DealerScene : public KCardScene
{
Q_OBJECT
public:
enum { None = 0, Hint = 1, Demo = 2, Draw = 4, Deal = 8, Redeal = 16 } Actions;
explicit DealerScene( const DealerInfo * di );
~DealerScene();
virtual void initialize() = 0;
void relayoutScene() Q_DECL_OVERRIDE;
void updateWonItem();
void addPatPile( PatPile * pile );
void removePatPile( PatPile * pile );
QList<PatPile*> patPiles() const;
void setAutoDropEnabled( bool enabled );
bool autoDropEnabled() const;
int gameNumber() const;
int gameId() const;
void setActions( int actions );
int actions() const;
virtual QList<QAction*> configActions() const;
void startHint();
void stopHint();
bool isHintActive() const;
void startDrop();
void stopDrop();
bool isDropActive() const;
void startDemo();
void stopDemo();
bool isDemoActive() const;
void setSolverEnabled( bool enabled );
Solver * solver() const;
void startSolver();
virtual bool isGameLost() const;
virtual bool isGameWon() const;
bool allowedToStartNewGame();
int moveCount() const;
void saveFile( QIODevice * io );
bool loadFile( QIODevice * io );
void saveLegacyFile( QIODevice * io );
bool loadLegacyFile( QIODevice * io );
virtual void mapOldId(int id);
virtual int oldId() const;
void recordGameStatistics();
QImage createDump() const;
signals:
void undoPossible(bool poss);
void redoPossible(bool poss);
void newCardsPossible(bool poss);
void gameInProgress(bool inProgress);
void demoActive(bool active);
void hintActive(bool active);
void dropActive(bool active);
void updateMoves(int moves);
void solverStateChanged(QString text);
void cardsPickedUp();
void cardsPutDown();
public slots:
void startNew( int dealNumber = -1 );
void undo();
void redo();
void stop();
void drawDealRowOrRedeal();
virtual bool tryAutomaticMove( KCard * card );
protected:
bool allowedToAdd(const KCardPile * pile, const QList<KCard*> & cards) const Q_DECL_OVERRIDE;
bool allowedToRemove(const KCardPile * pile, const KCard * card) const Q_DECL_OVERRIDE;
virtual bool checkAdd( const PatPile * pile, const QList<KCard*> & oldCards, const QList<KCard*> & newCards ) const;
virtual bool checkRemove( const PatPile * pile, const QList<KCard*> & cards ) const;
virtual bool checkPrefering( const PatPile * pile, const QList<KCard*> & oldCards, const QList<KCard*> & newCards ) const;
void cardsMoved( const QList<KCard*> & cards, KCardPile * oldPile, KCardPile * newPile ) Q_DECL_OVERRIDE;
void mouseDoubleClickEvent( QGraphicsSceneMouseEvent * mouseEvent ) Q_DECL_OVERRIDE;
void mousePressEvent( QGraphicsSceneMouseEvent * mouseEvent ) Q_DECL_OVERRIDE;
void mouseReleaseEvent( QGraphicsSceneMouseEvent * mouseEvent ) Q_DECL_OVERRIDE;
virtual void restart( const QList<KCard*> & cards ) = 0;
void setSolver( Solver * solver );
virtual QList<MoveHint> getHints();
// reimplement these to store and load game-specific information in the state structure
virtual QString getGameState() const;
virtual void setGameState( const QString & state );
// reimplement these to store and load game-specific options in the saved game file
virtual QString getGameOptions() const;
virtual void setGameOptions( const QString & options );
void addCardForDeal( KCardPile * pile, KCard * card, bool faceUp, QPointF startPos );
void startDealAnimation();
void setNeededFutureMoves( int moves );
int neededFutureMoves() const;
void setDeckContents( int copies = 1,
const QList<KCardDeck::Suit> & suits = KCardDeck::standardSuits() );
void multiStepMove( const QList<KCard*> & cards,
KCardPile * pile,
const QList<KCardPile*> & freePiles,
const QList<KCardPile*> & freeCells,
int duration );
QList<MoveHint> getSolverHints();
protected slots:
void takeState();
virtual void animationDone();
virtual bool newCards();
virtual bool drop();
private slots:
void stopAndRestartSolver();
void slotSolverEnded();
void slotSolverFinished( int result );
void demo();
void showWonMessage();
private:
void undoOrRedo( bool undo );
void resetInternals();
MoveHint chooseHint();
void won();
int speedUpTime( int delay ) const;
void multiStepSubMove( QList<KCard*> cards,
KCardPile * pile,
QList<KCardPile*> freePiles,
const QList<KCardPile*> & freeCells );
void continueMultiStepMove();
const DealerInfo * const m_di;
Solver * m_solver;
SolverThread * m_solverThread;
QList<MOVE> m_winningMoves;
KCard * m_peekedCard;
MessageBox * m_wonItem;
QTimer m_solverUpdateTimer;
QTimer m_demoTimer;
QTimer m_dropTimer;
int m_dealNumber;
int m_loadedMoveCount;
int m_neededFutureMoves;
int m_supportedActions;
bool m_autoDropEnabled;
bool m_solverEnabled;
bool m_dealStarted;
bool m_dealWasEverWinnable;
bool m_dealHasBeenWon;
bool m_dealWasJustSaved;
bool m_statisticsRecorded;
bool m_playerReceivedHelp;
// We need a flag to avoid telling someone the game is lost
// just because the winning animation moved the cards away
bool m_toldAboutWonGame;
bool m_toldAboutLostGame;
QSet<KCard*> m_cardsRemovedFromFoundations;
qreal m_dropSpeedFactor;
bool m_interruptAutoDrop;
bool m_dealInProgress;
bool m_hintInProgress;
bool m_demoInProgress;
bool m_dropInProgress;
bool m_hintQueued;
bool m_demoQueued;
bool m_dropQueued;
bool m_newCardsQueued;
bool m_takeStateQueued;
QStack<GameState*> m_undoStack;
GameState * m_currentState;
QStack<GameState*> m_redoStack;
QHash<KCard*,CardState> m_lastKnownCardStates;
QList<QPair<KCard*,KCardPile*> > m_multiStepMoves;
int m_multiStepDuration;
QList<PatPile*> m_patPiles;
QMap<KCard*,QPointF> m_initDealPositions;
};
#endif