Bug fixes
authortimoph <timop.harkonen@gmail.com>
Sun, 9 May 2010 13:28:37 +0000 (13:28 +0000)
committertimoph <timop.harkonen@gmail.com>
Sun, 9 May 2010 13:28:37 +0000 (13:28 +0000)
git-svn-id: file:///svnroot/impuzzle/trunk@22 e6bec12f-0854-4cc4-ad26-6875f1509f77

debian/changelog
src/defines.h
src/gameview.cpp
src/mainwindow.cpp
src/settingsdialog.cpp

index c219e17..6ca051a 100644 (file)
@@ -1,3 +1,11 @@
+impuzzle (0.6-1maemo0) unstable; urgency=low
+
+  * Fixes: Move counter not resetted when starting new game
+  * Fixes: Improved shuffle algorithm to make puzzle always solvable, for real this time :)
+  * Use random image by default
+
+ -- Timo Härkönen <timop.harkonen@gmail.com>  Sun, 09 May 2010 15:18:00 +0200
+
 impuzzle (0.5-3maemo0) unstable; urgency=low
 
   * Added application icon
index 716c393..6007ebf 100644 (file)
@@ -23,8 +23,6 @@
 
 #define IMAGE_HEIGHT 400
 
-#define GAME_VERSION 0.3
-
 #define EASY_PIECE_COUNT 9
 #define EASY_HORIZONTAL_COUNT 3
 #define HARD_PIECE_COUNT 16
@@ -37,6 +35,6 @@
 #define RESTORE_FILE "impuzzle.dat"
 #define HOME_DIRECTORY ".impuzzle"
 
-#define IMPUZZLE_VERSION "0.5"
+#define IMPUZZLE_VERSION "0.6"
 
 #endif // DEFINES_H
index 3223602..cf19475 100644 (file)
@@ -150,6 +150,7 @@ void GameView::setPieces(const QList<PuzzleItem *> pieces, bool shuffle)
     }
 }
 
+//TODO: fixme!
 void GameView::shufflePieces()
 {
     if(pieces_.isEmpty()) {
@@ -164,7 +165,12 @@ void GameView::shufflePieces()
     QPointF topLeft = pieces_.at(0)->correctPlace();
     QPointF bottomRight = pieces_.last()->correctPlace();
 
-    for(int i = 0; i < pieces_.count() * 10; ++i) {
+    int moveCount = pieces_.count() * 10;
+    int movesMade = 0;
+
+    PuzzleItem *item = 0;
+
+    for(int i = 0; i < moveCount; ++i) {
         int rand = qrand() % 4;
 
         switch(rand) {
@@ -172,40 +178,90 @@ void GameView::shufflePieces()
         case 0:
             if(pieces_.at(hiddenIndex_)->currentPlace().y() > topLeft.y()) {
                 QPointF tmp = pieces_.at(hiddenIndex_)->currentPlace();
-                PuzzleItem *item = dynamic_cast<PuzzleItem *>(scene()->itemAt(tmp + QPointF(0, -verticalStep_)));
-                emptyPlace_ = item->currentPlace();
-                pieces_.at(hiddenIndex_)->setCurrentPlace(item->currentPlace());
-                item->setCurrentPlace(tmp);
+                item = dynamic_cast<PuzzleItem *>(scene()->itemAt(tmp + QPointF(0, -verticalStep_)));
+                if(item->movable()) {
+                    emptyPlace_ = item->currentPlace();
+                    pieces_.at(hiddenIndex_)->setCurrentPlace(item->currentPlace());
+                    pieces_.at(hiddenIndex_)->setPos(item->currentPlace());
+                    item->setCurrentPlace(tmp);
+                    item->setPos(tmp);
+                    invalidateScene();
+                    scene()->update();
+                    setMovingPieces();
+                    movesMade++;
+                }
+                else {
+                    qDebug() << "Item right of hidden piece not movable";
+                }
+            }
+            else {
+                --i;
             }
             break;
         // down
         case 1:
             if(pieces_.at(hiddenIndex_)->currentPlace().y() < bottomRight.y()) {
                 QPointF tmp = pieces_.at(hiddenIndex_)->currentPlace();
-                PuzzleItem *item = dynamic_cast<PuzzleItem *>(scene()->itemAt(tmp + QPointF(0, verticalStep_)));
+                item = dynamic_cast<PuzzleItem *>(scene()->itemAt(tmp + QPointF(0, verticalStep_)));
+                if(item->movable()) {
                 emptyPlace_ = item->currentPlace();
-                pieces_.at(hiddenIndex_)->setCurrentPlace(item->currentPlace());
-                item->setCurrentPlace(tmp);
+                    pieces_.at(hiddenIndex_)->setCurrentPlace(item->currentPlace());
+                    pieces_.at(hiddenIndex_)->setPos(item->currentPlace());
+                    item->setCurrentPlace(tmp);
+                    item->setPos(tmp);
+                    setMovingPieces();
+                    movesMade++;
+                }
+                else {
+                    qDebug() << "Item down of hidden piece not movable";
+                }
+            }
+            else {
+                --i;
             }
             break;
         // left
         case 2:
             if(pieces_.at(hiddenIndex_)->currentPlace().x() > topLeft.x()) {
                 QPointF tmp = pieces_.at(hiddenIndex_)->currentPlace();
-                PuzzleItem *item = dynamic_cast<PuzzleItem *>(scene()->itemAt(tmp + QPointF(-horizontalStep_, 0)));
-                emptyPlace_ = item->currentPlace();
-                pieces_.at(hiddenIndex_)->setCurrentPlace(item->currentPlace());
-                item->setCurrentPlace(tmp);
+                item = dynamic_cast<PuzzleItem *>(scene()->itemAt(tmp + QPointF(-horizontalStep_, 0)));
+                if(item->movable()) {
+                    emptyPlace_ = item->currentPlace();
+                    pieces_.at(hiddenIndex_)->setCurrentPlace(item->currentPlace());
+                    pieces_.at(hiddenIndex_)->setPos(item->currentPlace());
+                    item->setCurrentPlace(tmp);
+                    item->setPos(tmp);
+                    setMovingPieces();
+                    movesMade++;
+                }
+                else {
+                    qDebug() << "Item left of hidden piece not movable";
+                }
+            }
+            else {
+                --i;
             }
             break;
         // right
         case 3:
             if(pieces_.at(hiddenIndex_)->currentPlace().x() < bottomRight.x()) {
                 QPointF tmp = pieces_.at(hiddenIndex_)->currentPlace();
-                PuzzleItem *item = dynamic_cast<PuzzleItem *>(scene()->itemAt(tmp + QPointF(horizontalStep_, 0)));
-                emptyPlace_ = item->currentPlace();
-                pieces_.at(hiddenIndex_)->setCurrentPlace(item->currentPlace());
-                item->setCurrentPlace(tmp);
+                item = dynamic_cast<PuzzleItem *>(scene()->itemAt(tmp + QPointF(horizontalStep_, 0)));
+                if(item->movable()) {
+                    emptyPlace_ = item->currentPlace();
+                    pieces_.at(hiddenIndex_)->setCurrentPlace(item->currentPlace());
+                    pieces_.at(hiddenIndex_)->setPos(item->currentPlace());
+                    item->setCurrentPlace(tmp);
+                    item->setPos(tmp);
+                    setMovingPieces();
+                    movesMade++;
+                }
+                else {
+                    qDebug() << "Item up of hidden piece not movable";
+                }
+            }
+            else {
+                --i;
             }
             break;
         default:
@@ -214,6 +270,8 @@ void GameView::shufflePieces()
         }
     }
 
+    qDebug() << QString("Shuffle moves: %1/%2").arg(movesMade).arg(moveCount);
+
     QParallelAnimationGroup *animationGroup = new QParallelAnimationGroup(this);
     for(int i = 0; i < pieces_.count(); ++i) {
         QPropertyAnimation *animation = new QPropertyAnimation(pieces_.at(i), "pos");
index fea49c2..46a74c8 100644 (file)
@@ -94,6 +94,7 @@ void MainWindow::newGameClicked()
 
     GameView::instance()->setPieces(ImageImporter::instance()->newPieces(Settings::instance()->image(), Settings::instance()->pieceCount()));
     enableSaving();
+    PuzzleItem::setMoveCount(0);
 }
 
 void MainWindow::aboutClicked()
index be783dc..58d4ca0 100644 (file)
@@ -53,6 +53,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
 
     imageCombo_ = new QComboBox;
     imageCombo_->addItems(items);
+    imageCombo_->setCurrentIndex(1);
 
     selectedImageLabel_ = new QLabel(tr("n/a"));
 
@@ -66,7 +67,8 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
     setLayout(mainLayout_);
 
     connect(easyButton_, SIGNAL(toggled(bool)), this, SLOT(difficultySelectionChanged(bool)));
-    connect(imageCombo_, SIGNAL(currentIndexChanged(QString)), this, SLOT(imageSelectionChanged(QString)));
+    //connect(imageCombo_, SIGNAL(currentIndexChanged(QString)), this, SLOT(imageSelectionChanged(QString)));
+    connect(imageCombo_, SIGNAL(activated(QString)), this, SLOT(imageSelectionChanged(QString)));
 }
 
 int SettingsDialog::exec()