Fixed showSolution
authorpaul romanchenko <paulaner@gmail.com>
Thu, 23 Sep 2010 05:17:55 +0000 (09:17 +0400)
committerpaul romanchenko <paulaner@gmail.com>
Thu, 23 Sep 2010 05:17:55 +0000 (09:17 +0400)
fieldview.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
qexed.pro

index 5940197..f00c2fa 100644 (file)
@@ -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);
     }
 }
index b78f9f8..b7346c4 100644 (file)
@@ -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();
+    }
 }
index 8db5b6d..f4febbb 100644 (file)
@@ -25,6 +25,7 @@ protected:
     LevelPack *pack;
     int levelNo;
     int levelHiscore;
+    bool inSolution;
     QList<QString> packNames;
 
     void changeEvent(QEvent *e);
index 21e7de2..a2775ef 100644 (file)
          </item>
          <item>
           <layout class="QHBoxLayout" name="solveLandscape">
-         <item>
-          <widget class="QPushButton" name="solve">
-           <property name="text">
-            <string>Solve!</string>
-           </property>
-          </widget>
-         </item>
-         </layout>
+           <item>
+            <widget class="QPushButton" name="solve">
+             <property name="text">
+              <string>Solve!</string>
+             </property>
+            </widget>
+           </item>
+          </layout>
          </item>
          <item>
           <spacer name="verticalSpacer_2">
index 4027683..589da17 100644 (file)
--- 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 =