2 #include <QGraphicsPixmapItem>
5 const QString ghostImageFilename_ = ":/pix/aave.png";
6 const QString rockImageFilename_ =":/pix/kari.png";
7 const QString octopusImageFilename_= ":/pix/tursas.png";
10 SeaScene::SeaScene(QObject *parent) :
11 QGraphicsScene(parent)
17 void SeaScene::setupMap(int ghosts, int rocks, int octopuses)
19 //empty the list of free slots
22 //fill the list of free slots
24 int numberOfXTiles = width() / 40;
25 int numberOfYTiles = height() /40;
27 qDebug() << numberOfXTiles << " slots in x direction";
28 qDebug() << numberOfYTiles << " slots in y rirection";
30 for (int i = 0; i < numberOfXTiles; i++ )
32 for (int j = 0; j < numberOfYTiles; j++)
34 freeTiles_.append(QPointF(i*40,j*40));
40 void SeaScene::spreadGhosts(int ghosts)
42 for (int i=0; i < ghosts; i++)
44 QPointF * pPosition = findRandomFreeSlot();
46 //If there was no room no point to continue
47 if (pPosition == NULL)
50 QGraphicsPixmapItem * pGhost = addPixmap(QPixmap(":/pix/aave.png"));
51 pGhost->setData(0,"ghost");
52 pGhost->setPos(*pPosition);
57 QPointF* SeaScene::findRandomFreeSlot()
59 if (freeTiles_.isEmpty())
62 int index = qrand()%freeTiles_.size();
64 qDebug() << index << " index";
65 return new QPointF (freeTiles_.takeAt(index));