{
for (int i=0; i < ghosts; i++)
{
- QPointF position = findRandomFreeSlot();
+ QPointF * pPosition = findRandomFreeSlot();
+
+ //If there was no room no point to continue
+ if (pPosition == NULL)
+ return;
QGraphicsPixmapItem * pGhost = addPixmap(QPixmap(":/pix/aave.png"));
pGhost->setData(0,"ghost");
- pGhost->setPos(position);
+ pGhost->setPos(*pPosition);
+ delete pPosition;
}
}
-QPointF SeaScene::findRandomFreeSlot()
+QPointF* SeaScene::findRandomFreeSlot()
{
+ if (freeTiles_.isEmpty())
+ return NULL;
+
int index = qrand()%freeTiles_.size();
qDebug() << index << " index";
- return freeTiles_.takeAt(index);
+ return new QPointF (freeTiles_.takeAt(index));
}
protected:
- QPointF findRandomFreeSlot();
+ /*! Gives a pointer to a random position if a free one is found. Otherwise returns NULL.
+ The position is the upper left corner of a free 40x40 pixels slot.
+ */
+
+ QPointF* findRandomFreeSlot();
const QString ghostImageFilename_;
const QString rockImageFilename_;