Ship can now pick ghosts
[ghostsoverboard] / seascene.cpp
index b330532..cfa78ec 100644 (file)
@@ -98,6 +98,7 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses)
     pShip->setData(0,"ship");
     pShip->setPos(*pPosition);
     addItem(pShip);
+    connect(pShip,SIGNAL(pickingGhost(QGraphicsItem*)),this, SLOT(removeGhost(QGraphicsItem*)) );
     pShip->startMoving();
     delete pPosition;
 }
@@ -131,3 +132,10 @@ QPointF* SeaScene::findRandomFreeSlot()
     return new QPointF (freeTiles_.takeAt(index));
 
 }
+
+void SeaScene::removeGhost(QGraphicsItem *pGhost)
+{
+    removeItem(pGhost);  //remove the item from scene
+    freeTiles_.append(pGhost->scenePos()); //add the item's position to free slots
+    delete pGhost;
+}