SVN commit 1284131 by majewsky: Use Kg::difficulty() singleton in KDiamond and Bovo. M +10 -9 bovo/gui/mainwindow.cc M +0 -2 bovo/gui/mainwindow.h M +5 -3 kdiamond/src/board.cpp M +2 -3 kdiamond/src/board.h M +2 -2 kdiamond/src/game.cpp M +1 -2 kdiamond/src/game.h M +6 -0 kdiamond/src/main.cpp M +5 -7 kdiamond/src/mainwindow.cpp M +0 -2 kdiamond/src/mainwindow.h --- trunk/KDE/kdegames/bovo/gui/mainwindow.cc #1284130:1284131 @@ -71,14 +71,15 @@ statusBar()->insertPermanentItem(i18n("Losses: %1", m_losses), 2, 1); m_aiFactory = new AiFactory(); - m_difficulty.addStandardLevelRange( + KgDifficulty* diff = Kg::difficulty(); + diff->addStandardLevelRange( KgDifficultyLevel::RidiculouslyEasy, KgDifficultyLevel::Impossible, KgDifficultyLevel::Medium //default level ); - connect(&m_difficulty, SIGNAL(currentLevelChanged(const KgDifficultyLevel*)), SLOT(changeSkill())); - KgDifficultyGUI::init(&m_difficulty, this); - m_difficulty.setGameRunning(true); + connect(diff, SIGNAL(currentLevelChanged(const KgDifficultyLevel*)), SLOT(changeSkill())); + KgDifficultyGUI::init(this); + diff->setGameRunning(true); setupThemes(); readConfig(); @@ -270,11 +271,11 @@ QString tmp = m_lastGame.first(); m_computerStarts = tmp.startsWith('2') ? true : false; } - m_game = new Game(dimension, m_lastGame, m_difficulty.currentLevel()->standardLevel(), + m_game = new Game(dimension, m_lastGame, Kg::difficultyLevel(), m_playbackSpeed, m_aiFactory); } else { m_game = new Game(dimension, m_computerStarts ? O : X, - m_difficulty.currentLevel()->standardLevel(), NotDemo, m_playbackSpeed, + Kg::difficultyLevel(), NotDemo, m_playbackSpeed, m_aiFactory); } m_demoAi = m_aiFactory->createAi(dimension, KgDifficultyLevel::Easy, m_game->player(), Demo); @@ -313,9 +314,9 @@ m_demoAi = 0; } Dimension dimension(NUMCOLS, NUMCOLS); - m_game = new Game(dimension, O, m_difficulty.currentLevel()->standardLevel(), Demo, m_playbackSpeed, + m_game = new Game(dimension, O, Kg::difficultyLevel(), Demo, m_playbackSpeed, m_aiFactory); - m_demoAi = m_aiFactory->createAi(dimension, m_difficulty.currentLevel()->standardLevel(), X, Demo); + m_demoAi = m_aiFactory->createAi(dimension, Kg::difficultyLevel(), X, Demo); m_scene->setGame(m_game); connect(m_game, SIGNAL(boardChanged(const Move&)), m_demoAi, SLOT(changeBoard(const Move&))); @@ -436,7 +437,7 @@ void MainWindow::changeSkill() { if (m_game!=0) - m_game->setSkill(m_difficulty.currentLevel()->standardLevel()); + m_game->setSkill(Kg::difficultyLevel()); } void MainWindow::changeTheme(int themeId) { --- trunk/KDE/kdegames/bovo/gui/mainwindow.h #1284130:1284131 @@ -26,7 +26,6 @@ #include #include -#include #include "common.h" #include "theme.h" @@ -102,7 +101,6 @@ QStringList m_lastGame; bool m_animate; bool m_demoMode; - KgDifficulty m_difficulty; }; } /* namespace gui */ --- trunk/KDE/kdegames/kdiamond/src/board.cpp #1284130:1284131 @@ -20,6 +20,7 @@ #include "diamond.h" #include +#include const int KDiamond::Board::MoveDuration = 100; //duration of a move animation (per coordinate unit) in milliseconds const int KDiamond::Board::RemoveDuration = 200; //duration of a move animation in milliseconds @@ -28,9 +29,10 @@ static int boardSizes[] = { 12, 10, 8, 8, 8 }; static int boardColorCounts[] = { 5, 5, 5, 6, 7 }; -KDiamond::Board::Board(KGameRenderer* renderer, KgDifficultyLevel::StandardLevel difficulty) - : m_size(boardSizes[difficulty / 10 - 2]) - , m_colorCount(boardColorCounts[difficulty / 10 - 2]) +KDiamond::Board::Board(KGameRenderer* renderer) + : m_difficultyIndex(Kg::difficultyLevel() / 10 - 2) + , m_size(boardSizes[m_difficultyIndex]) + , m_colorCount(boardColorCounts[m_difficultyIndex]) , m_paused(false) , m_renderer(renderer) , m_diamonds(m_size * m_size, 0) --- trunk/KDE/kdegames/kdiamond/src/board.h #1284130:1284131 @@ -23,7 +23,6 @@ class QAbstractAnimation; #include -#include class KGameRenderer; namespace KDiamond @@ -32,7 +31,7 @@ { Q_OBJECT public: - Board(KGameRenderer* renderer, KgDifficultyLevel::StandardLevel difficulty); + Board(KGameRenderer* renderer); int gridSize() const; Diamond* diamond(const QPoint& point) const; @@ -73,7 +72,7 @@ static const int MoveDuration; static const int RemoveDuration; - int m_size, m_colorCount; + int m_difficultyIndex, m_size, m_colorCount; QList m_selections; bool m_paused; --- trunk/KDE/kdegames/kdiamond/src/game.cpp #1284130:1284131 @@ -56,9 +56,9 @@ const int UpdateInterval = 40; -Game::Game(KDiamond::GameState* state, KgDifficultyLevel::StandardLevel difficulty) +Game::Game(KDiamond::GameState* state) : m_timerId(-1) - , m_board(new KDiamond::Board(g_renderer, difficulty)) + , m_board(new KDiamond::Board(g_renderer)) , m_gameState(state) , m_messenger(new KGamePopupItem) { --- trunk/KDE/kdegames/kdiamond/src/game.h #1284130:1284131 @@ -24,7 +24,6 @@ class QAbstractAnimation; #include -#include class KGamePopupItem; class KGameRenderer; @@ -49,7 +48,7 @@ { Q_OBJECT public: - Game(KDiamond::GameState* state, KgDifficultyLevel::StandardLevel difficulty); + Game(KDiamond::GameState* state); public Q_SLOTS: void updateGraphics(); --- trunk/KDE/kdegames/kdiamond/src/main.cpp #1284130:1284131 @@ -26,6 +26,7 @@ #include #include #include +#include static const char description[] = I18N_NOOP("KDiamond, a three-in-a-row game."); static const char version[] = "1.4"; @@ -47,6 +48,11 @@ //resource directory for KNewStuff2 (this call causes the directory to be created; its existence is necessary for the downloader) KStandardDirs::locateLocal("appdata", "themes/"); + Kg::difficulty()->addStandardLevelRange( + KgDifficultyLevel::VeryEasy, + KgDifficultyLevel::VeryHard + ); + // see if we are starting with session management if (app.isSessionRestored()) { --- trunk/KDE/kdegames/kdiamond/src/mainwindow.cpp #1284130:1284131 @@ -72,10 +72,8 @@ KStandardAction::preferences(this, SLOT(configureSettings()), actionCollection()); KStandardAction::configureNotifications(this, SLOT(configureNotifications()), actionCollection()); //difficulty - m_difficulty = new KgDifficulty(this); - m_difficulty->addStandardLevelRange(KgDifficultyLevel::VeryEasy, KgDifficultyLevel::VeryHard); - KgDifficultyGUI::init(m_difficulty, this); - connect(m_difficulty, SIGNAL(currentLevelChanged(const KgDifficultyLevel*)), SLOT(startGameDispatcher())); + KgDifficultyGUI::init(this); + connect(Kg::difficulty(), SIGNAL(currentLevelChanged(const KgDifficultyLevel*)), SLOT(startGameDispatcher())); //late GUI initialisation setupGUI(QSize(300, 400)); //TODO: find better solution for a minimum size setCaption(i18nc("The application's name", "KDiamond")); @@ -114,7 +112,7 @@ //start new game m_gameState->startNewGame(); m_gameState->setMode(mode); - m_game = new Game(m_gameState, m_difficulty->currentLevel()->standardLevel()); + m_game = new Game(m_gameState); connect(m_gameState, SIGNAL(stateChanged(KDiamond::State)), m_game, SLOT(stateChange(KDiamond::State))); connect(m_gameState, SIGNAL(message(QString)), m_game, SLOT(message(QString))); connect(m_game, SIGNAL(numberMoves(int)), m_infoBar, SLOT(updateMoves(int))); @@ -143,7 +141,7 @@ //report score QPointer dialog = new KScoreDialog(KScoreDialog::Name | KScoreDialog::Score, this); dialog->addField(KScoreDialog::Custom1, i18n("Mode"), "mode"); - dialog->initFromDifficulty(m_difficulty); + dialog->initFromDifficulty(Kg::difficulty()); dialog->addScore(scoreInfo); delete dialog; } @@ -157,7 +155,7 @@ //show dialog QPointer dialog = new KScoreDialog(KScoreDialog::Name | KScoreDialog::Score, this); dialog->addField(KScoreDialog::Custom1, i18n("Mode"), "mode"); - dialog->initFromDifficulty(m_difficulty); + dialog->initFromDifficulty(Kg::difficulty()); dialog->exec(); delete dialog; } --- trunk/KDE/kdegames/kdiamond/src/mainwindow.h #1284130:1284131 @@ -25,7 +25,6 @@ class QTime; class KAction; class KActionMenu; -class KgDifficulty; #include namespace KDiamond @@ -55,7 +54,6 @@ protected Q_SLOTS: void pausedAction(bool paused); private: - KgDifficulty* m_difficulty; KDiamond::GameState* m_gameState; Game* m_game; KDiamond::View* m_view;