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

List:       kde-commits
Subject:    playground/games/ksudoku/src
From:       Johannes Bergmeier <Johannes.Bergmeier () gmx ! net>
Date:       2007-05-03 13:02:14
Message-ID: 1178197334.151302.10811.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 660698 by joselb:

* Improved speed for row/column/box highlighting
* Enabled empty puzzles (which can be filled completly by user)
(There is a bug in the solver for Samurai puzzles)


 M  +51 -2     gui/gamevariants.cpp  
 M  +12 -0     gui/gamevariants.h  
 M  +17 -7     gui/views/ksudokuview.cpp  
 M  +2 -0      gui/views/ksudokuview.h  
 M  +8 -0      gui/views/qsudokubutton.cpp  
 M  +12 -6     gui/welcomescreen.cpp  
 M  +1 -1      gui/welcomescreen.h  
 M  +7 -7      gui/welcomescreen.ui  
 M  +1 -1      logic/puzzle.cpp  


--- trunk/playground/games/ksudoku/src/gui/gamevariants.cpp #660697:660698
@@ -78,10 +78,26 @@
 }
 
 bool SudokuGame::configure() {
-	KMessageBox::information(0, "", i18n("Configuration not yet implemented"));
+	KMessageBox::information(0, i18n("Configuration not yet implemented"), "");
 	return false;
 }
 
+bool SudokuGame::canStartEmpty() const {
+	return true;
+}
+
+Game SudokuGame::startEmpty() const {
+	if(!m_solver) {
+		m_solver = new SKSolver(m_order, false);
+		m_solver->init();
+	}
+	
+	Puzzle* puzzle = new Puzzle(m_solver, false);
+	puzzle->init();
+	
+	return Game(puzzle);
+}
+
 Game SudokuGame::createGame(int difficulty) const {
 	if(!m_solver) {
 		m_solver = new SKSolver(m_order, false);
@@ -115,10 +131,26 @@
 }
 
 bool RoxdokuGame::configure() {
-	KMessageBox::information(0, "", i18n("Configuration not yet implemented"));
+	KMessageBox::information(0, i18n("Configuration not yet implemented"), "");
 	return false;
 }
 
+bool RoxdokuGame::canStartEmpty() const {
+	return true;
+}
+
+Game RoxdokuGame::startEmpty() const {
+	if(!m_solver) {
+		m_solver = new SKSolver(m_order, true);
+		m_solver->init();
+	}
+	
+	Puzzle* puzzle = new Puzzle(m_solver, false);
+	puzzle->init();
+	
+	return Game(puzzle);
+}
+
 Game RoxdokuGame::createGame(int difficulty) const {
 	if(!m_solver) {
 		m_solver = new SKSolver(m_order, true);
@@ -153,6 +185,23 @@
 	return false;
 }
 
+bool CustomGame::canStartEmpty() const {
+	return true;
+}
+
+Game CustomGame::startEmpty() const {
+	if(!m_solver) {
+		m_solver = ksudoku::Serializer::loadCustomShape(m_url, 0, 0);
+		
+		if(!m_solver) return Game();
+	}
+	
+	Puzzle* puzzle = new Puzzle(m_solver, false);
+	puzzle->init();
+	
+	return Game(puzzle);
+}
+
 Game CustomGame::createGame(int difficulty) const {
 	if(!m_solver) {
 		m_solver = ksudoku::Serializer::loadCustomShape(m_url, 0, 0);
--- trunk/playground/games/ksudoku/src/gui/gamevariants.h #660697:660698
@@ -44,6 +44,12 @@
 	/// Shows a configure dialog and changes the settings
 	virtual bool configure() = 0;
 	
+	/// Whether this variant can be started without any values in the grid
+	virtual bool canStartEmpty() const = 0;
+	
+	/// Creates a game without a puzzle but with an empty grid
+	virtual Game startEmpty() const = 0;
+	
 	/// Creates a instance of this game variant
 	virtual Game createGame(int difficulty) const = 0;
 	
@@ -80,6 +86,8 @@
 public:
 	bool canConfigure() const;
 	bool configure();
+	bool canStartEmpty() const;
+	Game startEmpty() const;
 	Game createGame(int difficulty) const;
 	KsView* createView(const Game& game) const;
 	
@@ -97,6 +105,8 @@
 public:
 	bool canConfigure() const;
 	bool configure();
+	bool canStartEmpty() const;
+	Game startEmpty() const;
 	Game createGame(int difficulty) const;
 	KsView* createView(const Game& game) const;
 	
@@ -114,6 +124,8 @@
 public:
 	bool canConfigure() const;
 	bool configure();
+	bool canStartEmpty() const;
+	Game startEmpty() const;
 	Game createGame(int difficulty) const;
 	KsView* createView(const Game& game) const;
 	
--- trunk/playground/games/ksudoku/src/gui/views/ksudokuview.cpp #660697:660698
@@ -135,8 +135,12 @@
 
 	isWaitingForNumber = -1;
 
+	if(m_highlightUpdate.size() != m_game.size())
+		m_highlightUpdate.resize(m_game.size());
+	
 	for(int i = 0; i < m_game.size(); ++i) {
-		m_buttons[i]->setHighlight(HighlightBaseMask, HighlightNone);
+// 		m_buttons[i]->setHighlight(HighlightBaseMask, HighlightNone);
+		m_highlightUpdate[i] = HighlightNone;
 	}
 	
 
@@ -147,11 +151,14 @@
 		{
 	// 		uint base = m_game.userPuzzle()->base;
 			int base = static_cast<int>(sqrt(m_game.puzzle()->order()));
-			m_buttons[m_game.index(i, y)]->setHighlight(HighlightRow);
-			m_buttons[m_game.index(x, i)]->setHighlight(HighlightColumn);
+// 			m_buttons[m_game.index(i, y)]->setHighlight(HighlightRow);
+// 			m_buttons[m_game.index(x, i)]->setHighlight(HighlightColumn);
+			m_highlightUpdate[m_game.index(i, y)] |= HighlightRow;
+			m_highlightUpdate[m_game.index(x, i)] |= HighlightColumn;
 			int sx = (x/base) * base;
 			int sy = (y/base) * base;
-			m_buttons[m_game.index(i/base+sx, sy+(i%base))]->setHighlight(HighlightClique);
+// 			m_buttons[m_game.index(i/base+sx, \
sy+(i%base))]->setHighlight(HighlightClique); \
+			m_highlightUpdate[m_game.index(i/base+sx,i%base+sy)] |= HighlightClique;  }
 	}
 	else
@@ -191,7 +198,8 @@
 					}
 					for(int k=0; k<g->cliques[i].size(); k++)
 					{
-						m_buttons[g->cliques[i][k]]->setHighlight(mask);
+// 						m_buttons[g->cliques[i][k]]->setHighlight(mask);
+						m_highlightUpdate[g->cliques[i][k]] |= mask;
 					}
 					count = (count+1)%3;
 					break;
@@ -199,8 +207,10 @@
 			}
 		}
 	}
-	for(int i = 0; i < m_game.size(); ++i)
-		m_buttons[i]->update();
+	
+	for(int i = 0; i < m_game.size(); ++i) {
+		m_buttons[i]->setHighlight(HighlightBaseMask, m_highlightUpdate[i]);
+	}
 }
 
 
--- trunk/playground/games/ksudoku/src/gui/views/ksudokuview.h #660697:660698
@@ -108,6 +108,8 @@
 	void setGame(const Game& game);
 	
 	QVector<QSudokuButton*> m_buttons;
+	
+	QVector<int> m_highlightUpdate;
 
 	bool puzzle_mark_wrong;
 	int  highlighted;
--- trunk/playground/games/ksudoku/src/gui/views/qsudokubutton.cpp #660697:660698
@@ -425,11 +425,19 @@
 }
 
 void QSudokuButton::setHighlight(int value) {
+	int oldValue = m_highlights;
 	m_highlights |= value;
+	
+	if(highlightColors[m_highlights & HighlightMask] != highlightColors[oldValue & \
HighlightMask]) +		update();
 }
 
 void QSudokuButton::setHighlight(int mask, int value) {
+	int oldValue = m_highlights;
 	m_highlights = m_highlights & (HighlightMask ^ mask) | value;
+
+	if(highlightColors[m_highlights & HighlightMask] != highlightColors[oldValue & \
HighlightMask]) +		update();
 }
 
 
--- trunk/playground/games/ksudoku/src/gui/welcomescreen.cpp #660697:660698
@@ -36,8 +36,8 @@
 	
 	setupUi(this);
 	connect(getNewGameButton, SIGNAL(clicked(bool)), this, SLOT(getNewVariant()));
-	connect(createNewGameButton, SIGNAL(clicked(bool)), this, \
SLOT(createNewVariant()));  connect(configureGameButton, SIGNAL(clicked(bool)), this, \
SLOT(configureVariant())); +	connect(startEmptyButton, SIGNAL(clicked(bool)), this, \
SLOT(startEmptyGame()));  connect(playGameButton, SIGNAL(clicked(bool)), this, \
SLOT(playVariant()));  
 	connect(gameListWidget, \
SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, \
SLOT(onCurrentVariantChange())); @@ -71,17 +71,14 @@
 	}
 	
 	configureGameButton->setEnabled(variant->canConfigure());
+	startEmptyButton->setEnabled(variant->canStartEmpty());
 	playGameButton->setEnabled(true);
 }
 
 void WelcomeScreen::getNewVariant() {
-	KMessageBox::information(this, "", i18n("GetNewVariant not implemented"));
+	KMessageBox::information(this, i18n("GetNewVariant not implemented"), "");
 }
 
-void WelcomeScreen::createNewVariant() {
-	KMessageBox::information(this, "", i18n("CreateNewVariant not implemented"));
-}
-
 void WelcomeScreen::configureVariant() {
 	GameVariant* variant = selectedVariant();
 	if(!variant) return;
@@ -89,6 +86,15 @@
 	variant->configure();
 }
 
+void WelcomeScreen::startEmptyGame() {
+	GameVariant* variant = selectedVariant();
+	if(!variant) return;
+	
+	Game game = variant->startEmpty();
+	
+	emit newGameStarted(game, variant);
+}
+
 void WelcomeScreen::playVariant() {
 	GameVariant* variant = selectedVariant();
 	if(!variant) return;
--- trunk/playground/games/ksudoku/src/gui/welcomescreen.h #660697:660698
@@ -44,8 +44,8 @@
 	void onCurrentVariantChange();
 	
 	void getNewVariant();
-	void createNewVariant();
 	void configureVariant();
+	void startEmptyGame();
 	void playVariant();
 	
 signals:
--- trunk/playground/games/ksudoku/src/gui/welcomescreen.ui #660697:660698
@@ -32,13 +32,6 @@
          </widget>
         </item>
         <item>
-         <widget class="QPushButton" name="createNewGameButton" >
-          <property name="text" >
-           <string>New</string>
-          </property>
-         </widget>
-        </item>
-        <item>
          <spacer>
           <property name="orientation" >
            <enum>Qt::Horizontal</enum>
@@ -59,6 +52,13 @@
          </widget>
         </item>
         <item>
+         <widget class="QPushButton" name="startEmptyButton" >
+          <property name="text" >
+           <string>Start Empty</string>
+          </property>
+         </widget>
+        </item>
+        <item>
          <widget class="QPushButton" name="playGameButton" >
           <property name="text" >
            <string>Play</string>
--- trunk/playground/games/ksudoku/src/logic/puzzle.cpp #660697:660698
@@ -52,7 +52,7 @@
 	if(m_withSolution)
 		return false;
 
-	m_puzzle = new SKPuzzle(m_solver->g->order, m_solver->g->type);
+	m_puzzle = new SKPuzzle(m_solver->g->order, m_solver->g->type, m_solver->g->size);
 
 	for(int i = 0; i < m_puzzle->size; ++i)
 		m_puzzle->numbers[i] = 0;


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

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