-
Notifications
You must be signed in to change notification settings - Fork 0
/
Block.cpp
110 lines (94 loc) · 2.25 KB
/
Block.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "Block.h"
#include "Controller.h"
Block::Block(QGraphicsItem* parent, Score* blockScore):
blockScore{blockScore}, QGraphicsRectItem (parent)
{
plant = nullptr;//at first this is null
//start timer
bTimer = new QTimer();
bTimer->start(50);
//initialize all plants flags
sunflower = false;
shooter = false;
oak = false;
cherry = false;
}
void Block::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (plant == nullptr)
{
if (shooter){
plant = new Shooter(bTimer, parentItem());
scene()->addItem(plant);
plant->setPos(x() , y());
emit signalIsPlacedToScore(100);
emit signalIsPlacedToBoard();
}
else if (sunflower){
plant = new SunFlower(bTimer, blockScore, parentItem());
scene()->addItem(plant);
plant->setPos( x() , y());
emit signalIsPlacedToScore(50);
emit signalIsPlacedToBoard();
}
else if (cherry){
plant = new Cherry(bTimer, parentItem());
scene()->addItem(plant);
plant->setPos(x() + 10 - 80 , y() + 10 - 100);
emit signalIsPlacedToScore(150);
emit signalIsPlacedToBoard();
}
else if (oak){
plant = new Oak(bTimer, 5,parentItem());
scene()->addItem(plant);
plant->setPos(x()+10 , y()+10);
emit signalIsPlacedToScore(150);
emit signalIsPlacedToBoard();
}
}
else if (plant != nullptr && shovel){
delete plant;
plant = nullptr;
emit isDeleted();
}
}
void Block::ShooterSellected()
{
if (!(shooter||sunflower||cherry||oak))
{
shooter = true;
}
}
void Block::SunFlowerSellected()
{
if (!(shooter||sunflower||cherry||oak))
{
sunflower = true;
}
}
void Block::OakSellected()
{
if (!(shooter||sunflower||cherry||oak))
{
oak = true;
}
}
void Block::CherrySellected()
{
if (!(shooter||sunflower||cherry||oak))
{
cherry = true;
}
}
void Block::UnSelect()
{
sunflower = false;
shooter = false;
oak = false;
cherry = false;
shovel = false;
}
void Block::ShovelSellected()
{
shovel = true;
}