This repository was archived by the owner on Dec 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshop.cpp
More file actions
77 lines (65 loc) · 2.29 KB
/
Copy pathshop.cpp
File metadata and controls
77 lines (65 loc) · 2.29 KB
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
#include "shop.h"
using std::to_string;
Shop::Shop(int &money, qreal &moneyRatio, qreal &itemRatio, int &nextW, int &nextH, QObject *parent)
: money(money), moneyRatio(moneyRatio), itemRatio(itemRatio), nextW(nextW), nextH(nextH)
{
QVBoxLayout *layout = new QVBoxLayout(this);
QWidget *wMoneyRatio, *wItemRatio, *wNextMap;
wMoneyRatio = new QWidget;
wItemRatio = new QWidget;
wNextMap = new QWidget;
QHBoxLayout *lMoneyRatio = new QHBoxLayout(wMoneyRatio);
QHBoxLayout *lItemRatio= new QHBoxLayout(wItemRatio);
QHBoxLayout *lNextMap = new QHBoxLayout(wNextMap);
QLabel *tMoneyRatio = new QLabel("Money Ratio\t$1000");
QLabel *tItemRatio = new QLabel("Item Ratio\t$4000");
QLabel *tNextMap = new QLabel("Next Map Size\t$2000");
dMoneyRatio = new QLabel(to_string(moneyRatio).c_str());
dItemRatio = new QLabel(to_string(itemRatio).c_str());
dNextMap = new QLabel((to_string(nextW)+" x "+to_string(nextH)).c_str());
QPushButton *bMoneyRatio = new QPushButton("Upgrade");
QPushButton *bItemRatio = new QPushButton("Upgrade");
QPushButton *bNextMap= new QPushButton("Upgrade");
connect(bMoneyRatio, &QPushButton::clicked, this, &Shop::handleMoneyRatio);
connect(bItemRatio, &QPushButton::clicked, this, &Shop::handleItemRatio);
connect(bNextMap, &QPushButton::clicked, this, &Shop::handleNextMap);
lMoneyRatio->addWidget(tMoneyRatio);
lMoneyRatio->addWidget(dMoneyRatio);
lMoneyRatio->addWidget(bMoneyRatio);
lItemRatio->addWidget(tItemRatio);
lItemRatio->addWidget(dItemRatio);
lItemRatio->addWidget(bItemRatio);
lNextMap->addWidget(tNextMap);
lNextMap->addWidget(dNextMap);
lNextMap->addWidget(bNextMap);
layout->addWidget(wMoneyRatio);
layout->addWidget(wItemRatio);
layout->addWidget(wNextMap);
}
void Shop::handleMoneyRatio()
{
if (money < 1000 || moneyRatio >= 4.0) {
return;
}
moneyRatio += 0.1;
dMoneyRatio->setText(to_string(moneyRatio).c_str());
money -= 1000;
}
void Shop::handleItemRatio()
{
if (money < 4000 || itemRatio >= 0.8) {
return;
}
itemRatio += 0.1;
dItemRatio->setText(to_string(itemRatio).c_str());
money -= 4000;
}
void Shop::handleNextMap()
{
if (money < 2000 || nextW >= 512) {
return;
}
nextW *= 2; nextH *= 2;
dNextMap->setText((to_string(nextW)+" x "+to_string(nextH)).c_str());
money -= 2000;
}