Fixed showSolution
[vexed] / fieldview.cpp
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);
     }
 }