IntroItem, improved movement rules and move counting.
[impuzzle] / src / puzzleitem.cpp
index 1be8e9e..500b475 100644 (file)
@@ -22,6 +22,8 @@
 #include <QGraphicsSceneMouseEvent>
 #include <QPropertyAnimation>
 
 #include <QGraphicsSceneMouseEvent>
 #include <QPropertyAnimation>
 
+int PuzzleItem::moveCount_ = 0;
+
 PuzzleItem::PuzzleItem(QGraphicsItem *parent) :
         QGraphicsPixmapItem(parent)
 {
 PuzzleItem::PuzzleItem(QGraphicsItem *parent) :
         QGraphicsPixmapItem(parent)
 {
@@ -75,9 +77,17 @@ void PuzzleItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
         GameView::instance()->setEmptyPlace(tmp);
         event->accept();
 
         GameView::instance()->setEmptyPlace(tmp);
         event->accept();
 
+        moveCount_++;
+
         // If piece is in its place check if we won the game
         // If piece is in its place check if we won the game
+        bool won = false;
         if(currentPlace() == correctPlace()) {
         if(currentPlace() == correctPlace()) {
-            GameView::instance()->areAllPiecesOk();
+            won = GameView::instance()->areAllPiecesOk();
+        }
+
+        // if we didn't win set pieces that can be moved
+        if(!won) {
+            GameView::instance()->setMovingPieces();
         }
     }
     else {
         }
     }
     else {
@@ -89,3 +99,13 @@ void PuzzleItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
 {
     event->ignore();
 }
 {
     event->ignore();
 }
+
+int PuzzleItem::moveCount()
+{
+    return moveCount_;
+}
+
+void PuzzleItem::resetMoveCount()
+{
+    moveCount_ = 0;
+}