+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
impuzzle (0.5-3maemo0) unstable; urgency=low
* Added application icon
-#define GAME_VERSION 0.3
-
#define EASY_PIECE_COUNT 9
#define EASY_HORIZONTAL_COUNT 3
#define HARD_PIECE_COUNT 16
#define EASY_PIECE_COUNT 9
#define EASY_HORIZONTAL_COUNT 3
#define HARD_PIECE_COUNT 16
#define RESTORE_FILE "impuzzle.dat"
#define HOME_DIRECTORY ".impuzzle"
#define RESTORE_FILE "impuzzle.dat"
#define HOME_DIRECTORY ".impuzzle"
-#define IMPUZZLE_VERSION "0.5"
+#define IMPUZZLE_VERSION "0.6"
void GameView::shufflePieces()
{
if(pieces_.isEmpty()) {
void GameView::shufflePieces()
{
if(pieces_.isEmpty()) {
QPointF topLeft = pieces_.at(0)->correctPlace();
QPointF bottomRight = pieces_.last()->correctPlace();
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) {
int rand = qrand() % 4;
switch(rand) {
case 0:
if(pieces_.at(hiddenIndex_)->currentPlace().y() > topLeft.y()) {
QPointF tmp = pieces_.at(hiddenIndex_)->currentPlace();
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();
}
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();
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();
}
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();
}
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;
+ 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");
QParallelAnimationGroup *animationGroup = new QParallelAnimationGroup(this);
for(int i = 0; i < pieces_.count(); ++i) {
QPropertyAnimation *animation = new QPropertyAnimation(pieces_.at(i), "pos");
GameView::instance()->setPieces(ImageImporter::instance()->newPieces(Settings::instance()->image(), Settings::instance()->pieceCount()));
enableSaving();
GameView::instance()->setPieces(ImageImporter::instance()->newPieces(Settings::instance()->image(), Settings::instance()->pieceCount()));
enableSaving();
+ PuzzleItem::setMoveCount(0);
}
void MainWindow::aboutClicked()
}
void MainWindow::aboutClicked()
imageCombo_ = new QComboBox;
imageCombo_->addItems(items);
imageCombo_ = new QComboBox;
imageCombo_->addItems(items);
+ imageCombo_->setCurrentIndex(1);
selectedImageLabel_ = new QLabel(tr("n/a"));
selectedImageLabel_ = new QLabel(tr("n/a"));
setLayout(mainLayout_);
connect(easyButton_, SIGNAL(toggled(bool)), this, SLOT(difficultySelectionChanged(bool)));
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()
}
int SettingsDialog::exec()