-
Notifications
You must be signed in to change notification settings - Fork 35
/
minesweepscene.cpp
44 lines (37 loc) · 1.02 KB
/
minesweepscene.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "minesweepscene.h"
#include "fielddata.h"
#include <QGraphicsPixmapItem>
//#include <QDebug>
mineSweepScene::mineSweepScene(QObject *parent):
QGraphicsScene(parent)
{
initItems();
}
mineSweepScene::~mineSweepScene(){
clearItems();
}
void mineSweepScene::initItems(){
int w = Field->getWidth();
int h = Field->getHeight();
for(int x=0;x<w;++x){
_items.push_back(ItemColumn());
for(int y=0;y<h;++y){
_items[x].push_back(new cellItem(x,y));
static int cw = _items[0][0]->boundingRect().width();
static int ch = _items[0][0]->boundingRect().height();
_items[x][y]->setPos(x*cw,y*ch);
addItem(_items[x][y]);
}
}
}
void mineSweepScene::clearItems(){
int w = Field->getWidth();
int h = Field->getHeight();
for(int x=0;x<w;++x){
for(int y=0;y<h;++y){
delete _items[x][y];
_items[x][y]=nullptr;
}
}
_items.clear();
}