-
Notifications
You must be signed in to change notification settings - Fork 5
/
store.cpp
43 lines (38 loc) · 1.01 KB
/
store.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
#include "store.h"
#include "tower.h"
#include "qpoint.h"
store::store(QPoint store, int sX, int sY, QPoint tower, int inter, int tX, int tY, int avaNum)
{
store = store;
storeX = sX; storeY = sY;
towerUL = tower;
interval = inter;
towerX = tX; towerY = tY;
avaTowerNum = avaNum;
}
int store::buyTower(QPoint mouse)
{
for (int i = 0; i < avaTowerNum; i++)
{
//计算第i个塔左上角位置
int iTowerX = towerUL.x() + i * (interval + towerX);
int iTowerY = towerUL.y();
//判断是否在第i个塔范围内
if ( (mouse.x() > iTowerX) && (mouse.x() < iTowerX + towerX)
&& (mouse.y() > iTowerY) && (mouse.y() < iTowerY + towerY))
return i;
}
return -1;
}
bool store::isAfford(int towerType, int gold)
{
if(towerType != -1)
{
Tower* towerTemp=new Tower((towerType, 0, 0));
int r = (towerTemp->intCost > gold);
delete towerTemp;
return r;
}
else return 0;
}
store::~store() {}