1 /* ColorCode, a free MasterMind clone with built in solver 2 * Copyright (C) 2009 Dirk Laebisch 3 * http://www.laebisch.com/ 4 * 5 * ColorCode is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * ColorCode is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with ColorCode. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef COLORCODE_H 20 #define COLORCODE_H 21 22 #include <iostream> 23 #include <QMainWindow> 24 25 struct PegType 26 { 27 int ix; 28 char let; 29 QRadialGradient* grad; 30 QColor pencolor; 31 }; 32 33 class QAction; 34 class QActionGroup; 35 class QComboBox; 36 class QLabel; 37 class QGraphicsItem; 38 class QGraphicsTextItem; 39 class QGraphicsScene; 40 class QGraphicsView; 41 class PrefDialog; 42 class Settings; 43 class CCSolver; 44 class ColorPeg; 45 class PegRow; 46 class RowHint; 47 class Msg; 48 class BackGround; 49 class SolutionRow; 50 class GraphicsBtn; 51 class PegFactory; 52 class CCGame; 53 class GameNoDisplay; 54 class TimeDisplay; 55 class TimeDisplayBg; 56 class HighScore; 57 class GameTablesDialog; 58 59 class ColorCode : public QMainWindow 60 { 61 Q_OBJECT 62 63 public: 64 ColorCode(); 65 ~ColorCode(); 66 67 static ColorCode* INSTANCE; 68 69 static const QString VERSION; 70 static QString GAME_TITLE; 71 72 static const int STATE_NONE; 73 static const int STATE_RUNNING; 74 static const int STATE_PAUSED; 75 static const int STATE_WON; 76 static const int STATE_LOST; 77 static const int STATE_GAVE_UP; 78 static const int STATE_ERROR; 79 80 static const int LAYER_BG; 81 static const int LAYER_ROWS; 82 static const int LAYER_HINTS; 83 static const int LAYER_SOL; 84 static const int LAYER_MSG; 85 static const int LAYER_PEGS; 86 static const int LAYER_BTNS; 87 static const int LAYER_DRAG; 88 89 static const int MODE_HVM; 90 static const int MODE_MVH; 91 92 static const int MAX_COLOR_CNT; 93 static const int MIN_COLOR_CNT; 94 static const int SOLUTION_ROW_IX; 95 96 static const int LEVEL_SETTINGS[5][3]; 97 98 static int mMaxRowCnt; 99 static int mRowY0; 100 static int mColorCnt; 101 102 Settings* mSettings; 103 GameTablesDialog* mGameTablesDialog; 104 QGraphicsScene* mScene; 105 QGraphicsView* mView; 106 107 int GetGameState() const; 108 int GetGameModeInput() const; 109 int GetDoublesInput() const; 110 int GetColorCntInput() const; 111 int GetPegCntInput() const; 112 CCSolver* GetCCSolver() const; 113 114 public slots: 115 void SnapPegSlot(ColorPeg *cp); 116 void RowSolutionSlot(int ix); 117 void HintPressedSlot(int ix); 118 void ShowMsgSlot(QString msg); 119 120 void DoneBtnPressSlot(GraphicsBtn* btn = NULL); 121 void SetSolverGuessSlot(); 122 123 void ApplyPreferencesSlot(); 124 125 signals: 126 void NewHighScoreSignal(CCGame* g); 127 128 protected : 129 void resizeEvent(QResizeEvent* e); 130 void contextMenuEvent(QContextMenuEvent* e); 131 void keyPressEvent(QKeyEvent *e); 132 133 private slots: 134 void InitRows(); 135 void NewGameSlot(); 136 void NewGameInputSlot(CCGame* g); 137 void SavePrevGameSlot(); 138 void NewGame(); 139 void RestartGameSlot(); 140 void GiveInSlot(); 141 void PauseGameSlot(GraphicsBtn* = NULL); 142 void ResetRows(); 143 void OnlineHelpSlot(); 144 void AboutSlot(); 145 void AboutQtSlot(); 146 void OpenPreferencesSlot(); 147 void ApplySettingsSlot(); 148 void ShowToolbarSlot(); 149 void ShowMenubarSlot(); 150 void ShowStatusbarSlot(); 151 void ShowTimerSlot(); 152 void ShowGameNoSlot(); 153 void CloseHighScoreDialogSlot(); 154 void SetIndicatorsSlot(); 155 void DoublesChangedSlot(bool checked); 156 void SetDoublesSlot(bool checked); 157 void AutoCloseSlot(); 158 void AutoHintsSlot(); 159 void SetLevelSlot(); 160 void SetGameModeSlot(); 161 void CopyGameNoSlot(); 162 163 void RandRowSlot(); 164 void PrevRowSlot(); 165 void ClearRowSlot(); 166 167 void ColorCntChangedSlot(); 168 void PegCntChangedSlot(); 169 170 void UpdateRowMenuSlot(); 171 172 void SetGuessSlot(); 173 void SetHintsSlot(); 174 void SetAutoHintsSlot(); 175 176 void TestSlot(); 177 178 private: 179 static int mGameMode; 180 static int mLevel; 181 static int mPegCnt; 182 static int mDoubles; 183 static int mMaxZ; 184 static int mXOffs; 185 186 volatile static bool mNoAct; 187 volatile static bool mIgnoreGuess; 188 189 int mGameState; 190 int mGameId; 191 int mGuessCnt; 192 int mHintsCnt; 193 int mGameCnt; 194 int mSolverStrength; 195 196 std::vector<int> mSolution; 197 198 QSize* mOrigSize; 199 200 CCSolver* mSolver; 201 PegFactory* mPegFactory; 202 Msg* mMsg; 203 BackGround* mBg; 204 GraphicsBtn* mDoneBtn; 205 GraphicsBtn* mOkBtn; 206 GraphicsBtn* mTimerBtn; 207 GraphicsBtn* mSolutionRowBg; 208 PrefDialog* mPrefDialog; 209 210 PegRow* mCurRow; 211 SolutionRow* mSolutionRow; 212 PegRow* mPegRows[10]; 213 RowHint* mHintBtns[10]; 214 215 QTimer* mHintsDelayTimer; 216 TimeDisplay* mGameTimer; 217 TimeDisplayBg* mGameTimerBg; 218 GameNoDisplay* mGameNoDisplay; 219 220 CCGame* mGameInput; 221 CCGame* mFinishedGameInput; 222 HighScore* mHighScore; 223 224 void Init(); 225 void InitSolution(); 226 void InitActions(); 227 void InitMenus(); 228 void InitToolBars(); 229 void CreatePrefDialog(); 230 void ShowTimer(); 231 void UpdateGameNoDisplay(); 232 CCGame* GetCurrentGameInput() const; 233 bool NeedsRestart() const; 234 void TryNewGame(); 235 236 void SetGameMode(); 237 void UpdateActions(); 238 void SetPegCnt(); 239 void SetColorCnt(); 240 241 void ApplyGameMode(); 242 void ApplyPegCnt(); 243 void ApplySolverStrength(); 244 245 void CheckLevel(); 246 void CheckDoublesSetting(); 247 void SetState(const int s); 248 void ResetGame(); 249 void SetSolution(); 250 void GetSolution(); 251 void ShowSolution(); 252 void NextRow(); 253 void SetCurRow(PegRow* const &row); 254 void ResolveRow(); 255 std::vector<int> RateSol2Guess(const std::vector<int> sol, const std::vector<int> guess); 256 void ResolveHints(); 257 void ResolveGame(); 258 void WaitForSolver(); 259 bool ForceRepaint(); 260 bool GamesRunning(); 261 void Scale(); 262 263 CCGame* GetRandGameInput(); 264 265 QMenu* mMenuGame; 266 QMenu* mMenuRow; 267 QMenu* mMenuRowContext; 268 QMenu* mMenuSettings; 269 QMenu* mMenuModes; 270 QMenu* mMenuLevels; 271 QMenu* mMenuGames; 272 QMenu* mMenuHelp; 273 274 QMenuBar* mMenuBar; 275 QToolBar* mGameToolbar; 276 QToolBar* mLevelToolbar; 277 278 QComboBox* mColorCntCmb; 279 QComboBox* mPegCntCmb; 280 QLabel* mStatusLabel; 281 282 QActionGroup* mActGroupLevels; 283 QActionGroup* mActGroupModes; 284 285 QAction* mActNewGame; 286 QAction* mActSelectGame; 287 QAction* mActCopyGameNo; 288 QAction* mActRestartGame; 289 QAction* mActGiveIn; 290 QAction* mActSaveGame; 291 QAction* mActPauseGame; 292 QAction* mActShowHighScores; 293 QAction* mActShowPrevGames; 294 QAction* mActShowSavedGames; 295 QAction* mActExit; 296 QAction* mActShowToolbar; 297 QAction* mActShowMenubar; 298 QAction* mActShowStatusbar; 299 QAction* mActShowTimer; 300 QAction* mActShowGameNo; 301 QAction* mActDoubles; 302 QAction* mActResetColorsOrder; 303 QAction* mActShowIndicators; 304 QAction* mActDoublesIcon; 305 QAction* mActAutoClose; 306 QAction* mActAutoHints; 307 QAction* mActPreferences; 308 QAction* mActAbout; 309 QAction* mActAboutQt; 310 311 QAction* mActSetPegCnt; 312 313 QAction* mActModeHvM; 314 QAction* mActModeMvH; 315 316 QAction* mActLevelEasy; 317 QAction* mActLevelClassic; 318 QAction* mActLevelMedium; 319 QAction* mActLevelChallenging; 320 QAction* mActLevelHard; 321 QAction* mLaunchHelpAction; 322 323 QAction* mActRandRow; 324 QAction* mActPrevRow; 325 QAction* mActClearRow; 326 327 QAction* mActSetGuess; 328 QAction* mActSetHints; 329 }; 330 331 #endif // COLORCODE_H 332