From 8eee59bbca77eff0b84050a6860d7e1acbe6f9b4 Mon Sep 17 00:00:00 2001 From: paul romanchenko Date: Thu, 23 Sep 2010 09:17:55 +0400 Subject: [PATCH] Fixed showSolution --- fieldview.cpp | 52 ++++++++++++++++++++++++++++------------------------ mainwindow.cpp | 8 ++++++++ mainwindow.h | 1 + mainwindow.ui | 16 ++++++++-------- qexed.pro | 9 ++++++--- 5 files changed, 51 insertions(+), 35 deletions(-) diff --git a/fieldview.cpp b/fieldview.cpp index 5940197..f00c2fa 100644 --- a/fieldview.cpp +++ b/fieldview.cpp @@ -103,11 +103,11 @@ void FieldView::playMove() delete move; } else { - if(playField->checkSolved() && !inSolution) + emit animationEnd(); + if(playField->checkSolved()) { emit solved(playField->moves); } - emit animationEnd(); } } @@ -168,49 +168,53 @@ void FieldView::showSolution() inSolution=true; solutionMove=0; solutionTimer=new QTimer(this); + solutionTimer->setInterval(500); + solutionTimer->setSingleShot(true); + connect(this,SIGNAL(animationEnd()),solutionTimer,SLOT(start())); connect(solutionTimer,SIGNAL(timeout()),this,SLOT(playSolutionMove())); playSolutionMove(); } void FieldView::stop() { - disconnect(this,SIGNAL(animationEnd()),this,SLOT(playSolutionMove())); if(solutionTimer!=0) { + disconnect(this,SIGNAL(animationEnd()),solutionTimer,SLOT(start())); solutionTimer->stop(); delete solutionTimer; solutionTimer=0; } - inSolution=false; } void FieldView::playSolutionMove() { - // drawn from original - char chX=playField->solution.at(solutionMove * 2).toAscii(); - char chY=playField->solution.at(solutionMove * 2 + 1).toAscii(); - - int x=chX-'a'; - int dest_x=x+1; - if( chX<='Z') - { - x = chX-'A'; - dest_x=x-1; - } - - int y=chY-'a'; - if(chY<='Z'){ - y=chY-'A'; - dest_x=x+1; - } - - if(x<0 || x>PF::FIELD_WIDTH || y<0 || y>PF::FIELD_HEIGHT) + if(solutionMove >= playField->solution.size() / 2) { + //disconnect(solutionTimer,SIGNAL(timeout()),this,SLOT(playSolutionMove())); + //connect(solutionTimer,SIGNAL(timeout()),this,SLOT(stop())); + puts("no more. stop"); stop(); } else { + // drawn from original + char chX=playField->solution.at(solutionMove * 2).toAscii(); + char chY=playField->solution.at(solutionMove * 2 + 1).toAscii(); + + int x=chX-'a'; + int dest_x=x+1; + if( chX<='Z') + { + x = chX-'A'; + dest_x=x-1; + } + + int y=chY-'a'; + if(chY<='Z'){ + y=chY-'A'; + dest_x=x+1; + } + solutionMove++; move(x,y,dest_x); - solutionTimer->start(500); } } diff --git a/mainwindow.cpp b/mainwindow.cpp index b78f9f8..b7346c4 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -122,6 +122,11 @@ void MainWindow::movesChanged(int moves) void MainWindow::solved(int moves) { + if(inSolution) + { + inSolution=false; + return; + } PlayField *pf=pack->levelAt(levelNo); Settings().saveHiscore(pack->getTitle(),pf->title, moves); levelHiscore=moves; @@ -175,5 +180,8 @@ void MainWindow::solve() confirm.setStandardButtons(QMessageBox::Yes | QMessageBox::No); int confirmation=confirm.exec(); if(confirmation==QMessageBox::Yes) + { + inSolution=true; ui->playwidget->showSolution(); + } } diff --git a/mainwindow.h b/mainwindow.h index 8db5b6d..f4febbb 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -25,6 +25,7 @@ protected: LevelPack *pack; int levelNo; int levelHiscore; + bool inSolution; QList packNames; void changeEvent(QEvent *e); diff --git a/mainwindow.ui b/mainwindow.ui index 21e7de2..a2775ef 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -243,14 +243,14 @@ - - - - Solve! - - - - + + + + Solve! + + + + diff --git a/qexed.pro b/qexed.pro index 4027683..589da17 100644 --- a/qexed.pro +++ b/qexed.pro @@ -20,7 +20,8 @@ SOURCES += main.cpp\ howtoplay.cpp \ settings.cpp \ needadvance.cpp \ - about.cpp + about.cpp \ + solutionwindow.cpp HEADERS += mainwindow.h \ playfield.h \ @@ -31,13 +32,15 @@ HEADERS += mainwindow.h \ howtoplay.h \ settings.h \ needadvance.h \ - about.h + about.h \ + solutionwindow.h FORMS += mainwindow.ui \ preferences.ui \ howtoplay.ui \ needadvance.ui \ - about.ui + about.ui \ + solutionwindow.ui CONFIG += mobility MOBILITY = -- 1.7.9.5