X-Git-Url: http://git.maemo.org/git/?p=vexed;a=blobdiff_plain;f=fieldview.cpp;h=5940197c3be1f14f7bbb21633aa7012fc7e8143f;hp=2ccb7574507b30c5b72ccdd1217d9b8eb3d680a3;hb=6c9fbeb1b4cda4d08076565aa30a3b0bf4d530ec;hpb=287af054a087505036ec2658fcafc0dac2464eee diff --git a/fieldview.cpp b/fieldview.cpp index 2ccb757..5940197 100644 --- a/fieldview.cpp +++ b/fieldview.cpp @@ -13,7 +13,8 @@ FieldView::FieldView(QWidget *parent) : moving=false; moves=new QList(); playField=0; - + solutionTimer=0; + inSolution=false; } void FieldView::mousePressEvent(QMouseEvent *event) @@ -42,9 +43,14 @@ void FieldView::mouseReleaseEvent(QMouseEvent *event) return; } } + move(selX,selY,moveX); +} + +void FieldView::move(int x, int y, int dest_x) +{ delete moves; moves=new QList(); - playField->move(selX, selY, moveX); + playField->move(x, y, dest_x); playMoves(); emit updateMoves(playField->moves); } @@ -95,9 +101,13 @@ void FieldView::playMove() connect(a,SIGNAL(finished()),this,SLOT(playMove())); a->start(); delete move; - } else if(playField->checkSolved()) + } else { - emit solved(playField->moves); + if(playField->checkSolved() && !inSolution) + { + emit solved(playField->moves); + } + emit animationEnd(); } } @@ -148,3 +158,59 @@ void FieldView::updateWidgets() } } } + + +// level should be resetted to show solution! +// create new widget +void FieldView::showSolution() +{ + stop(); + inSolution=true; + solutionMove=0; + solutionTimer=new QTimer(this); + connect(solutionTimer,SIGNAL(timeout()),this,SLOT(playSolutionMove())); + playSolutionMove(); +} + +void FieldView::stop() +{ + disconnect(this,SIGNAL(animationEnd()),this,SLOT(playSolutionMove())); + if(solutionTimer!=0) + { + 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) + { + stop(); + } else + { + solutionMove++; + move(x,y,dest_x); + solutionTimer->start(500); + } +}