[Kde-games-devel] KDE/kdegames/kapman

Stefan Majewsky majewsky at gmx.net
Wed Mar 7 20:57:23 UTC 2012


SVN commit 1284133 by majewsky:

Port Kapman from KGameDifficulty to KgDifficulty (singleton).

Since no maintainer is known according to Techbase:
CCMAIL: kde-games-devel at kde.org

 M  +9 -6      character.cpp  
 M  +10 -12    game.cpp  
 M  +1 -3      game.h  
 M  +9 -6      ghost.cpp  
 M  +12 -9     kapman.cpp  
 M  +0 -4      kapman.kcfg  
 M  +9 -4      kapmanitem.cpp  
 M  +22 -14    kapmanmainwindow.cpp  
 M  +0 -4      kapmanmainwindow.h  


--- trunk/KDE/kdegames/kapman/character.cpp #1284132:1284133
@@ -18,7 +18,7 @@
 
 #include "character.h"
 
-#include <KGameDifficulty>
+#include <KgDifficulty>
 
 const qreal Character::LOW_SPEED = 3.75;
 const qreal Character::MEDIUM_SPEED = 4.5;
@@ -82,14 +82,17 @@
 
 void Character::initSpeed() {
 	// Kapman speed increase when level up
-	if(KGameDifficulty::level() == KGameDifficulty::Easy) {
+	switch ((int) Kg::difficultyLevel())
+	{
+		case KgDifficultyLevel::Easy:
 		m_normalSpeed = Character::LOW_SPEED;
-	}
-	if(KGameDifficulty::level() == KGameDifficulty::Medium) {
+			break;
+		case KgDifficultyLevel::Medium:
 		m_normalSpeed = Character::MEDIUM_SPEED;
-	}
-	if(KGameDifficulty::level() == KGameDifficulty::Hard) {
+			break;
+		case KgDifficultyLevel::Hard:
 		m_normalSpeed = Character::HIGH_SPEED;
+			break;
 	}
 	m_speed = m_normalSpeed;
 }
--- trunk/KDE/kdegames/kapman/game.cpp #1284132:1284133
@@ -22,18 +22,16 @@
 #include "settings.h"
 
 #include <KStandardDirs>
+#include <KgDifficulty>
 
 const int Game::FPS = 40;
 int Game::s_bonusDuration;
 int Game::s_preyStateDuration;
 qreal Game::s_durationRatio;
 
-Game::Game(KGameDifficulty::standardLevel p_difficulty) : m_isCheater(false), m_lives(3), m_points(0), m_level(1), m_nbEatenGhosts(0), m_media1(0), m_media2(0) {
+Game::Game() : m_isCheater(false), m_lives(3), m_points(0), m_level(1), m_nbEatenGhosts(0), m_media1(0), m_media2(0) {
 	// Initialize the sound state
 	setSoundsEnabled(Settings::sounds());
-	// Initialize the game difficulty
-    	Settings::setGameDifficulty((int) p_difficulty);
-	Settings::self()->writeConfig();
 
 	// Timers for medium difficulty
 	s_bonusDuration = 7000;
@@ -41,8 +39,8 @@
 	// Difference ratio between low/high and medium speed
 	s_durationRatio = 1.0;
 
-	// Tells the KGameDifficulty singleton that the game is not running
-	KGameDifficulty::setRunning(false);
+	// Tells the KgDifficulty singleton that the game is not running
+	Kg::difficulty()->setGameRunning(false);
 
 	// Create the Maze instance
 	m_maze = new Maze();
@@ -65,15 +63,15 @@
 	
 
 	// Initialize the characters speed timers duration considering the difficulty level
-	switch (p_difficulty) {
-		case KGameDifficulty::Easy:
+	switch (Kg::difficultyLevel()) {
+		case KgDifficultyLevel::Easy:
 			// Ratio low/medium speed
 			s_durationRatio = Character::MEDIUM_SPEED / Character::LOW_SPEED;
 			break;
-		case KGameDifficulty::Medium:
+		case KgDifficultyLevel::Medium:
 			s_durationRatio = 1;
 			break;
-		case KGameDifficulty::Hard:
+		case KgDifficultyLevel::Hard:
 			// Ratio high/medium speed
 			s_durationRatio = Character::MEDIUM_SPEED / Character::HIGH_SPEED;
 			break;
@@ -321,8 +319,8 @@
 			m_timer->start();
 			emit(gameStarted());
 		}
-		// Tells the KGameDifficulty singleton that the game now runs
-		KGameDifficulty::setRunning(true);
+		// Tells the KgDifficulty singleton that the game now runs
+		Kg::difficulty()->setGameRunning(true);
 	}
 	// Behaviour when the game has begun
 	switch (p_event->key()) {
--- trunk/KDE/kdegames/kapman/game.h #1284132:1284133
@@ -27,7 +27,6 @@
 #include <QPointF>
 #include <QTimer>
 #include <QKeyEvent>
-#include <KGameDifficulty>
 #include <Phonon/MediaObject>
 
 /**
@@ -110,9 +109,8 @@
 
 		/**
 		 * Creates a new Game instance.
-		 * @param p_difficulty the KGameDifficulty level of the Game
 		 */
-		Game(KGameDifficulty::standardLevel p_difficulty = KGameDifficulty::Medium);
+		Game();
 
 		/**
 		 * Deletes the Game instance.
--- trunk/KDE/kdegames/kapman/ghost.cpp #1284132:1284133
@@ -20,7 +20,7 @@
 #include "time.h"
 
 #include <QPointF>
-#include <KGameDifficulty>
+#include <KgDifficulty>
 #include <cstdlib>
 
 const qreal Ghost::MAX_SPEED_RATIO = 2.0;
@@ -223,14 +223,17 @@
 
 void Ghost::initSpeedInc() {
 	// Ghosts speed increase when level up
-	if(KGameDifficulty::level() == KGameDifficulty::Easy) {
+	switch ((int) Kg::difficultyLevel())
+	{
+		case KgDifficultyLevel::Easy:
 		m_speedIncrease = Character::LOW_SPEED_INC;
-	}
-	if(KGameDifficulty::level() == KGameDifficulty::Medium) {
+			break;
+		case KgDifficultyLevel::Medium:
 		m_speedIncrease = Character::MEDIUM_SPEED_INC;
-	}
-	if(KGameDifficulty::level() == KGameDifficulty::Hard) {
+			break;
+		case KgDifficultyLevel::Hard:
 		m_speedIncrease = Character::HIGH_SPEED_INC;
+			break;
 	}
 }
 
--- trunk/KDE/kdegames/kapman/kapman.cpp #1284132:1284133
@@ -18,7 +18,7 @@
 
 #include "kapman.h"
 
-#include <KGameDifficulty>
+#include <KgDifficulty>
 
 const qreal Kapman::MAX_SPEED_RATIO = 1.5;
 
@@ -183,14 +183,17 @@
 
 void Kapman::initSpeedInc() {
 	// Kapman speed increase when level up
-	if(KGameDifficulty::level() == KGameDifficulty::Easy) {
-		m_speedIncrease = (Character::LOW_SPEED_INC / 2);
+	switch ((int) Kg::difficultyLevel())
+	{
+		case KgDifficultyLevel::Easy:
+			m_speedIncrease = Character::LOW_SPEED_INC / 2;
+			break;
+		case KgDifficultyLevel::Medium:
+			m_speedIncrease = Character::MEDIUM_SPEED_INC / 2;
+			break;
+		case KgDifficultyLevel::Hard:
+			m_speedIncrease = Character::HIGH_SPEED_INC / 2;
+			break;
 	}
-	if(KGameDifficulty::level() == KGameDifficulty::Medium) {
-		m_speedIncrease = (Character::MEDIUM_SPEED_INC / 2);
 	}
-	if(KGameDifficulty::level() == KGameDifficulty::Hard) {
-		m_speedIncrease = (Character::HIGH_SPEED_INC / 2);
-	}
-}
 
--- trunk/KDE/kdegames/kapman/kapman.kcfg #1284132:1284133
@@ -5,10 +5,6 @@
       http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
   <kcfgfile name="kapmanrc"/>
   <group name="General">
-    <entry name="GameDifficulty" type="Int" key="GameDifficulty">
-      <label>Game difficulty level.</label>
-      <default>40</default>
-    </entry>
     <entry name="Theme" type="String" key="Theme">
       <label>The graphical theme to be used.</label>
       <default>themes/mummies_crypt.desktop</default>
--- trunk/KDE/kdegames/kapman/kapmanitem.cpp #1284132:1284133
@@ -23,7 +23,7 @@
 #include "settings.h"
 
 #include <QGraphicsScene>
-#include <KGameDifficulty>
+#include <KgDifficulty>
 
 const int KapmanItem::NB_FRAMES = 32;
 const int KapmanItem::ANIM_LOW_SPEED = 500;
@@ -41,12 +41,17 @@
 	m_animationTimer->setLoopCount(0);
 	m_animationTimer->setFrameRange(0, NB_FRAMES - 1);
 	// Animation speed
-	if (KGameDifficulty::level() == KGameDifficulty::Easy) {
+	switch ((int) Kg::difficultyLevel())
+	{
+		case KgDifficultyLevel::Easy:
 		m_animationTimer->setDuration(KapmanItem::ANIM_LOW_SPEED);
-	} else if (KGameDifficulty::level() == KGameDifficulty::Medium) {
+			break;
+		case KgDifficultyLevel::Medium:
 		m_animationTimer->setDuration(KapmanItem::ANIM_MEDIUM_SPEED);
-	} else if (KGameDifficulty::level() == KGameDifficulty::Hard) {
+			break;
+		case KgDifficultyLevel::Hard:
 		m_animationTimer->setDuration(KapmanItem::ANIM_HIGH_SPEED);
+			break;
 	}
 	connect(m_animationTimer, SIGNAL(frameChanged(int)), this, SLOT(setFrame(int)));
 
--- trunk/KDE/kdegames/kapman/kapmanmainwindow.cpp #1284132:1284133
@@ -20,6 +20,7 @@
 #include "gamescene.h"
 #include "settings.h"
 
+#include <QPointer>
 #include <KActionCollection>
 #include <KStandardGameAction>
 #include <KToggleAction>
@@ -29,6 +30,8 @@
 #include <KInputDialog>
 #include <KLocale>
 #include <KStatusBar>
+#include <KgDifficulty>
+#include <KScoreDialog>
 
 KapmanMainWindow::KapmanMainWindow() {
 	// Initialize the game
@@ -53,29 +56,29 @@
 	m_statusBar->insertItem(i18nc("Used to tell the user how many lives they have left", "Lives: %1", 3), 4, 1);
 
 	
-	// Initialize the KGameDifficulty singleton
-	KGameDifficulty::init(this, this, SLOT(initGame()));
- 	KGameDifficulty::addStandardLevel(KGameDifficulty::Easy);
- 	KGameDifficulty::addStandardLevel(KGameDifficulty::Medium);
- 	KGameDifficulty::addStandardLevel(KGameDifficulty::Hard);
-    	KGameDifficulty::setLevel(KGameDifficulty::standardLevel(Settings::gameDifficulty()));
-	// KScoreDialog
-	m_kScoreDialog = new KScoreDialog(KScoreDialog::Name | KScoreDialog::Score | KScoreDialog::Level, this);
+	// Initialize the KgDifficulty singleton
+	Kg::difficulty()->addStandardLevelRange(
+		KgDifficultyLevel::Easy, KgDifficultyLevel::Hard, //range
+		KgDifficultyLevel::Medium //default
+	);
+	KgDifficultyGUI::init(this);
+	connect(Kg::difficulty(), SIGNAL(currentLevelChanged(const KgDifficultyLevel*)), SLOT(initGame()));
 	// Setup the window
 	setupGUI();
+
+	initGame();
 }
 
 KapmanMainWindow::~KapmanMainWindow() {
 	delete m_statusBar;
 	delete m_game;
 	delete m_view;
-	delete m_kScoreDialog;
 }
 
 void KapmanMainWindow::initGame() {
 	// Create a new Game instance
 	delete m_game;
-	m_game = new Game(KGameDifficulty::level());
+	m_game = new Game();
 	connect(m_game, SIGNAL(gameOver(bool)), this, SLOT(newGame(bool)));		// TODO Remove the useless bool parameter from gameOver()
 	connect(m_game, SIGNAL(levelChanged(uint)), this, SLOT(displayLevel(uint)));
 	connect(m_game, SIGNAL(scoreChanged(uint)), this, SLOT(displayScore(uint)));
@@ -122,19 +125,21 @@
 		// Display the score information
 		KMessageBox::information(this, i18np("Your score is %1 point.", "Your score is %1 points.", m_game->getScore()), i18n("Game Over"));
 		// Add the score to the highscores table
-		m_kScoreDialog->setConfigGroup(KGameDifficulty::localizedLevelString());
+		QPointer<KScoreDialog> dialog = new KScoreDialog(KScoreDialog::Name | KScoreDialog::Score | KScoreDialog::Level, this);
+		dialog->initFromDifficulty(Kg::difficulty());
 		KScoreDialog::FieldInfo scoreInfo;
 		scoreInfo[KScoreDialog::Level].setNum(m_game->getLevel());
 		scoreInfo[KScoreDialog::Score].setNum(m_game->getScore());
 		// If the new score is a highscore then display the highscore dialog
-		if (m_kScoreDialog->addScore(scoreInfo)) {
+		if (dialog->addScore(scoreInfo)) {
 			// If the payer did not cheat, manage Highscores
 			if (!m_game->isCheater()) {
-				m_kScoreDialog->exec();
+				dialog->exec();
 			} else {		// else, warn the player not to cheat again :)
 				KMessageBox::information(this, i18n("You cheated, no Highscore for you ;)"), i18n("Cheater!"));	
 			}
 		}
+		delete dialog;
 		
 		// Start a new game
 		initGame();
@@ -149,7 +154,10 @@
 }
 
 void KapmanMainWindow::showHighscores() {
- 	m_kScoreDialog->exec();
+	QPointer<KScoreDialog> dialog = new KScoreDialog(KScoreDialog::Name | KScoreDialog::Score | KScoreDialog::Level, this);
+	dialog->initFromDifficulty(Kg::difficulty());
+	dialog->exec();
+	delete dialog;
 }
 
 void KapmanMainWindow::setSoundsEnabled(bool p_enabled) {
--- trunk/KDE/kdegames/kapman/kapmanmainwindow.h #1284132:1284133
@@ -24,7 +24,6 @@
 
 #include <KXmlGuiWindow>
 #include <QGraphicsView>
-#include <KScoreDialog>
 
 class KStatusBar;
 
@@ -43,9 +42,6 @@
 		/** The Game instance that manages the main loop and events */
 		Game* m_game;
 
-		/** The highscores dialog */
-		KScoreDialog* m_kScoreDialog;
-
 		KStatusBar* m_statusBar;
 		
 	public:


More information about the kde-games-devel mailing list