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 position = findRandomFreeSlot();
46 QGraphicsPixmapItem * pGhost = addPixmap(QPixmap(":/pix/aave.png"));
47 pGhost->setData(0,"ghost");
48 pGhost->setPos(position);
52 QPointF SeaScene::findRandomFreeSlot()
54 int index = qrand()%freeTiles_.size();
56 qDebug() << index << " index";
57 return freeTiles_.takeAt(index);