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 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
|
/* ColorCode, a free MasterMind clone with built in solver
* Copyright (C) 2009 Dirk Laebisch
* http://www.laebisch.com/
*
* ColorCode 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 3 of the License, or
* (at your option) any later version.
*
* ColorCode 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 ColorCode. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef COLORCODE_H
#define COLORCODE_H
#include <iostream>
#include <QMainWindow>
struct PegType
{
int ix;
char let;
QRadialGradient* grad;
QColor pencolor;
};
class QAction;
class QActionGroup;
class QComboBox;
class QLabel;
class QGraphicsItem;
class QGraphicsTextItem;
class QGraphicsScene;
class QGraphicsView;
class PrefDialog;
class Settings;
class CCSolver;
class ColorPeg;
class PegRow;
class RowHint;
class Msg;
class BackGround;
class SolutionRow;
class GraphicsBtn;
class PegFactory;
class CCGame;
class GameNoDisplay;
class TimeDisplay;
class TimeDisplayBg;
class HighScore;
class GameTablesDialog;
class ColorCode : public QMainWindow
{
Q_OBJECT
public:
ColorCode();
~ColorCode();
static ColorCode* INSTANCE;
static const QString VERSION;
static QString GAME_TITLE;
static const int STATE_NONE;
static const int STATE_RUNNING;
static const int STATE_PAUSED;
static const int STATE_WON;
static const int STATE_LOST;
static const int STATE_GAVE_UP;
static const int STATE_ERROR;
static const int LAYER_BG;
static const int LAYER_ROWS;
static const int LAYER_HINTS;
static const int LAYER_SOL;
static const int LAYER_MSG;
static const int LAYER_PEGS;
static const int LAYER_BTNS;
static const int LAYER_DRAG;
static const int MODE_HVM;
static const int MODE_MVH;
static const int MAX_COLOR_CNT;
static const int MIN_COLOR_CNT;
static const int SOLUTION_ROW_IX;
static const int LEVEL_SETTINGS[5][3];
static int mMaxRowCnt;
static int mRowY0;
static int mColorCnt;
Settings* mSettings;
GameTablesDialog* mGameTablesDialog;
QGraphicsScene* mScene;
QGraphicsView* mView;
int GetGameState() const;
int GetGameModeInput() const;
int GetDoublesInput() const;
int GetColorCntInput() const;
int GetPegCntInput() const;
CCSolver* GetCCSolver() const;
public slots:
void SnapPegSlot(ColorPeg *cp);
void RowSolutionSlot(int ix);
void HintPressedSlot(int ix);
void ShowMsgSlot(QString msg);
void DoneBtnPressSlot(GraphicsBtn* btn = NULL);
void SetSolverGuessSlot();
void ApplyPreferencesSlot();
signals:
void NewHighScoreSignal(CCGame* g);
protected :
void resizeEvent(QResizeEvent* e);
void contextMenuEvent(QContextMenuEvent* e);
void keyPressEvent(QKeyEvent *e);
private slots:
void InitRows();
void NewGameSlot();
void NewGameInputSlot(CCGame* g);
void SavePrevGameSlot();
void NewGame();
void RestartGameSlot();
void GiveInSlot();
void PauseGameSlot(GraphicsBtn* = NULL);
void ResetRows();
void OnlineHelpSlot();
void AboutSlot();
void AboutQtSlot();
void OpenPreferencesSlot();
void ApplySettingsSlot();
void ShowToolbarSlot();
void ShowMenubarSlot();
void ShowStatusbarSlot();
void ShowTimerSlot();
void ShowGameNoSlot();
void CloseHighScoreDialogSlot();
void SetIndicatorsSlot();
void DoublesChangedSlot(bool checked);
void SetDoublesSlot(bool checked);
void AutoCloseSlot();
void AutoHintsSlot();
void SetLevelSlot();
void SetGameModeSlot();
void CopyGameNoSlot();
void RandRowSlot();
void PrevRowSlot();
void ClearRowSlot();
void ColorCntChangedSlot();
void PegCntChangedSlot();
void UpdateRowMenuSlot();
void SetGuessSlot();
void SetHintsSlot();
void SetAutoHintsSlot();
void TestSlot();
private:
static int mGameMode;
static int mLevel;
static int mPegCnt;
static int mDoubles;
static int mMaxZ;
static int mXOffs;
volatile static bool mNoAct;
volatile static bool mIgnoreGuess;
int mGameState;
int mGameId;
int mGuessCnt;
int mHintsCnt;
int mGameCnt;
int mSolverStrength;
std::vector<int> mSolution;
QSize* mOrigSize;
CCSolver* mSolver;
PegFactory* mPegFactory;
Msg* mMsg;
BackGround* mBg;
GraphicsBtn* mDoneBtn;
GraphicsBtn* mOkBtn;
GraphicsBtn* mTimerBtn;
GraphicsBtn* mSolutionRowBg;
PrefDialog* mPrefDialog;
PegRow* mCurRow;
SolutionRow* mSolutionRow;
PegRow* mPegRows[10];
RowHint* mHintBtns[10];
QTimer* mHintsDelayTimer;
TimeDisplay* mGameTimer;
TimeDisplayBg* mGameTimerBg;
GameNoDisplay* mGameNoDisplay;
CCGame* mGameInput;
CCGame* mFinishedGameInput;
HighScore* mHighScore;
void Init();
void InitSolution();
void InitActions();
void InitMenus();
void InitToolBars();
void CreatePrefDialog();
void ShowTimer();
void UpdateGameNoDisplay();
CCGame* GetCurrentGameInput() const;
bool NeedsRestart() const;
void TryNewGame();
void SetGameMode();
void UpdateActions();
void SetPegCnt();
void SetColorCnt();
void ApplyGameMode();
void ApplyPegCnt();
void ApplySolverStrength();
void CheckLevel();
void CheckDoublesSetting();
void SetState(const int s);
void ResetGame();
void SetSolution();
void GetSolution();
void ShowSolution();
void NextRow();
void SetCurRow(PegRow* const &row);
void ResolveRow();
std::vector<int> RateSol2Guess(const std::vector<int> sol, const std::vector<int> guess);
void ResolveHints();
void ResolveGame();
void WaitForSolver();
bool ForceRepaint();
bool GamesRunning();
void Scale();
CCGame* GetRandGameInput();
QMenu* mMenuGame;
QMenu* mMenuRow;
QMenu* mMenuRowContext;
QMenu* mMenuSettings;
QMenu* mMenuModes;
QMenu* mMenuLevels;
QMenu* mMenuGames;
QMenu* mMenuHelp;
QMenuBar* mMenuBar;
QToolBar* mGameToolbar;
QToolBar* mLevelToolbar;
QComboBox* mColorCntCmb;
QComboBox* mPegCntCmb;
QLabel* mStatusLabel;
QActionGroup* mActGroupLevels;
QActionGroup* mActGroupModes;
QAction* mActNewGame;
QAction* mActSelectGame;
QAction* mActCopyGameNo;
QAction* mActRestartGame;
QAction* mActGiveIn;
QAction* mActSaveGame;
QAction* mActPauseGame;
QAction* mActShowHighScores;
QAction* mActShowPrevGames;
QAction* mActShowSavedGames;
QAction* mActExit;
QAction* mActShowToolbar;
QAction* mActShowMenubar;
QAction* mActShowStatusbar;
QAction* mActShowTimer;
QAction* mActShowGameNo;
QAction* mActDoubles;
QAction* mActResetColorsOrder;
QAction* mActShowIndicators;
QAction* mActDoublesIcon;
QAction* mActAutoClose;
QAction* mActAutoHints;
QAction* mActPreferences;
QAction* mActAbout;
QAction* mActAboutQt;
QAction* mActSetPegCnt;
QAction* mActModeHvM;
QAction* mActModeMvH;
QAction* mActLevelEasy;
QAction* mActLevelClassic;
QAction* mActLevelMedium;
QAction* mActLevelChallenging;
QAction* mActLevelHard;
QAction* mLaunchHelpAction;
QAction* mActRandRow;
QAction* mActPrevRow;
QAction* mActClearRow;
QAction* mActSetGuess;
QAction* mActSetHints;
};
#endif // COLORCODE_H
|