[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdegames/ktron
From:       Stefan Majewsky <majewsky () gmx ! net>
Date:       2012-03-07 22:49:00
Message-ID: 20120307224900.6FDC1AC897 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1284147 by majewsky:

Port KTron/KSnake from KGameDifficulty to KgDifficulty (singleton).

CCMAIL: legolas@legolasweb.nl

 M  +7 -9      intelligence.cpp  
 M  +9 -21     ktron.cpp  
 M  +0 -4      ktron.kcfg  
 M  +7 -9      tron.cpp  


--- trunk/KDE/kdegames/ktron/intelligence.cpp #1284146:1284147
@@ -26,7 +26,7 @@
 #include "tron.h"
 #include "settings.h"
 
-#include <KGameDifficulty>
+#include <KgDifficulty>
 
 Intelligence::Intelligence()
 {
@@ -46,19 +46,17 @@
 
 /** retrieves the opponentSkill */
 int Intelligence::opponentSkill() {
-	KGameDifficulty::standardLevel level = KGameDifficulty::level();
-
-	switch (level) {
-		case KGameDifficulty::VeryEasy:
+	switch (Kg::difficultyLevel()) {
+		case KgDifficultyLevel::VeryEasy:
 			return 1;
 		default:
-		case KGameDifficulty::Easy:
+		case KgDifficultyLevel::Easy:
 			return 1;
-		case KGameDifficulty::Medium:
+		case KgDifficultyLevel::Medium:
 			return 2;
-		case KGameDifficulty::Hard:
+		case KgDifficultyLevel::Hard:
 			return 3;
-		case KGameDifficulty::VeryHard:
+		case KgDifficultyLevel::VeryHard:
 			return 3;
 	}
 }
--- trunk/KDE/kdegames/ktron/ktron.cpp #1284146:1284147
@@ -34,7 +34,7 @@
 #include <KStandardGameAction>
 #include <KScoreDialog>
 #include <KGameThemeSelector>
-#include <KGameDifficulty>
+#include <KgDifficulty>
 #include <KShortcutsDialog>
 #include <KStatusBar>
 #include <KToggleAction>
@@ -143,20 +143,12 @@
 	KStandardGameAction::highscores(this, SLOT(showHighscores()), actionCollection());
 
 	//difficulty
-	KGameDifficulty::init(this, m_tron, SLOT(loadSettings()));
-	KGameDifficulty::addStandardLevel(KGameDifficulty::VeryEasy);
-	KGameDifficulty::addStandardLevel(KGameDifficulty::Easy);
-	KGameDifficulty::addStandardLevel(KGameDifficulty::Medium);
-	KGameDifficulty::addStandardLevel(KGameDifficulty::Hard);
-	KGameDifficulty::addStandardLevel(KGameDifficulty::VeryHard);
-	int skill = Settings::difficulty();
-	if (skill < (int)KGameDifficulty::VeryEasy || skill > \
                (int)KGameDifficulty::VeryHard) {
-		KGameDifficulty::setLevel(KGameDifficulty::Easy);
-		Settings::setDifficulty((int) KGameDifficulty::Easy);
-	}
-	else {
-		KGameDifficulty::setLevel((KGameDifficulty::standardLevel) (skill));
-	}
+    Kg::difficulty()->addStandardLevelRange(
+        KgDifficultyLevel::VeryEasy, KgDifficultyLevel::VeryHard,
+        KgDifficultyLevel::Easy //default
+    );
+    KgDifficultyGUI::init(this);
+    connect(Kg::difficulty(), SIGNAL(currentLevelChanged(const KgDifficultyLevel*)), \
m_tron, SLOT(loadSettings()));  
 	setupGUI( KXmlGuiWindow::Keys | StatusBar | Save | Create);
 	loadSettings();
@@ -236,9 +228,7 @@
 	if (Settings::gameType() == Settings::EnumGameType::Snake)
 	{
 		KScoreDialog scoreDialog(KScoreDialog::Score | KScoreDialog::Name, this);
-		scoreDialog.addLocalizedConfigGroupNames(KGameDifficulty::localizedLevelStrings());
                
-		scoreDialog.setConfigGroupWeights(KGameDifficulty::levelWeights());
-		scoreDialog.setConfigGroup(KGameDifficulty::localizedLevelString());
+		scoreDialog.initFromDifficulty(Kg::difficulty());
 
 		KScoreDialog::FieldInfo scoreInfo;
 		scoreInfo[KScoreDialog::Name] = m_tron->getPlayer(0)->getName();
@@ -285,9 +275,7 @@
  */
 void KTron::showHighscores() {
 	KScoreDialog scoreDialog(KScoreDialog::Score | KScoreDialog::Name, this);
-	scoreDialog.addLocalizedConfigGroupNames(KGameDifficulty::localizedLevelStrings());
-	scoreDialog.setConfigGroupWeights(KGameDifficulty::levelWeights());
-	scoreDialog.setConfigGroup( KGameDifficulty::localizedLevelString() );
+	scoreDialog.initFromDifficulty(Kg::difficulty());
 	scoreDialog.exec();
 }
 
--- trunk/KDE/kdegames/ktron/ktron.kcfg #1284146:1284147
@@ -15,10 +15,6 @@
       <label>Whether to disable acceleration.</label>
       <default>false</default>
     </entry>
-    <entry name="Difficulty" type="Int">
-      <label>The difficulty level.</label>
-      <default>30</default>
-    </entry>
     <entry name="NamePlayer1" type="String" key="Name_Pl1">
       <label>The name of player 1.</label>
     </entry>
--- trunk/KDE/kdegames/ktron/tron.cpp #1284146:1284147
@@ -37,7 +37,7 @@
 
 #include <KDebug>
 #include <KLocale>
-#include <KGameDifficulty>
+#include <KgDifficulty>
 
 #include "settings.h"
 #include "renderer.h"
@@ -68,8 +68,6 @@
 }
 
 void Tron::loadSettings(){
-	Settings::setDifficulty((int) KGameDifficulty::level());
-
 	createNewPlayfield();
 	reset();
 
@@ -664,17 +662,17 @@
 
 /** retrieves the line speed */
 int Tron::lineSpeed() {
-	switch (KGameDifficulty::level()) {
-		case KGameDifficulty::VeryEasy:
+	switch (Kg::difficultyLevel()) {
+		case KgDifficultyLevel::VeryEasy:
 			return 2;
 		default:
-		case KGameDifficulty::Easy:
+		case KgDifficultyLevel::Easy:
 			return 3;
-		case KGameDifficulty::Medium:
+		case KgDifficultyLevel::Medium:
 			return 5;
-		case KGameDifficulty::Hard:
+		case KgDifficultyLevel::Hard:
 			return 7;
-		case KGameDifficulty::VeryHard:
+		case KgDifficultyLevel::VeryHard:
 			return 8;
 	}
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic