-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathguiplayers.cpp
180 lines (125 loc) · 4.36 KB
/
guiplayers.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "guiplayers.h"
GUIPlayers::GUIPlayers(Player* p, int playerNum){
player = p;
stringstream ss;
ownedProperties = new QPushButton*[40];
ownedCount = 0;
//player's number
string tempNum;
ss << (playerNum + 1);
ss >> tempNum;
tempNum = "Player " + tempNum;
ss.clear();
QString qNum = QString::fromStdString(tempNum);
numLabel = new QLabel( this );
numLabel->setText( qNum );
//player's money
ss << player->getMoneyAmount();
string tempMoney;
ss >> tempMoney;
tempMoney = ("$" + tempMoney);
ss.clear();
QString qMoney = QString::fromStdString(tempMoney);
moneyLabel = new QLabel( this );
moneyLabel->setText( qMoney );
//player's game piece
string tempPiece = player->getGamePieceName();
QString qTempPiece = QString::fromStdString(tempPiece);
gamePieceImg = new QLabel(this);
gamePieceImg->setPixmap(qTempPiece);
gamePieceImg->setFixedWidth(55);
gamePieceImg->setFixedHeight(50);
gamePieceImg->setScaledContents(true);
//Adding all parts to layout
layout = new QVBoxLayout;
layout->addWidget(gamePieceImg);
layout->addWidget(numLabel);
layout->addWidget(moneyLabel);
sideBar = new QWidget(this);
sideBar->setLayout(layout);
setWidget(sideBar);
this->setMinimumSize(QSize(143, 650));
this->setMaximumSize(QSize(143, 650));
}
GUIPlayers::GUIPlayers(){
}
void GUIPlayers::setMoneyText(){
stringstream ss;
ss << player->getMoneyAmount();
string tempMoney;
ss >> tempMoney;
tempMoney = ("$" + tempMoney);
ss.clear();
QString qMoney = QString::fromStdString(tempMoney);
moneyLabel->setText( qMoney );
}
void GUIPlayers::addProperty(int propertyNum, string propertyName, Space** tempArray){
QString tempName = QString::fromStdString(propertyName);
QPushButton* newButton = new QPushButton(tempName);
ownedProperties[ownedCount] = newButton;
ownedProperties[ownedCount]->setEnabled(false);
currentPropertyNum = propertyNum;
allProperties[ownedCount] = propertyNum;
/*
QSignalMapper* signalMapper = new QSignalMapper(this);
for(int i = 0; i < ownedCount; i++){
connect(ownedProperties[ownedCount], SIGNAL(clicked(i)), this, SLOT(upgradeSpace(i)) );
//connect (ownedProperties[i], SIGNAL(clicked()), signalMapper, SLOT(map()));
//signalMapper->setMapping(ownedProperties[i], i);
//connect(ownedProperties[i], SIGNAL(clicked()), this, SLOT(upgradeSpace()) );
}
//connect (signalMapper, SIGNAL(mapped(int)), this, SIGNAL(clicked(int)));
//connect (signalMapper, SIGNAL(mapped(int)), this, SLOT(upgradeSpace(int)));
*/
connect(ownedProperties[ownedCount], SIGNAL(clicked()), this, SLOT(upgradeSpace()) );
layout->addWidget(ownedProperties[ownedCount]);
sideBar->setLayout(layout);
setWidget(sideBar);
ownedCount++;
}
void GUIPlayers::enableUpgrade(){
for( int i = 0; i < ownedCount; i++){
if(((player->getMoneyAmount() - allSpaces[allProperties[i]]->getPropertyCost()) <= 0) || !(allSpaces[allProperties[i]]->getType() == "Property")) {
ownedProperties[i]->setEnabled(false);
} else {
ownedProperties[i]->setEnabled(true);
}
}
}
void GUIPlayers::disableUpgrade(){
for( int i = 0; i < ownedCount; i++){
ownedProperties[i]->setEnabled(false);
}
}
void GUIPlayers::upgradeSpace(){
bool isUpgraded;
//int currentSpace = allProperties[num];
isUpgraded = allSpaces[currentPropertyNum]->upgrade();
if(isUpgraded == true){
if((player->getMoneyAmount() - allSpaces[currentPropertyNum]->getPropertyCost()) <= 0) {
string text = "You do not have enough money to upgrade this property!";
QString qText = QString::fromStdString(text);
QMessageBox UpGradeLimit;
UpGradeLimit.setText(qText);
UpGradeLimit.exec();
} else {
moneyAction.giveBank(player, bankPointer, allSpaces[currentPropertyNum]->getPropertyCost());
}
} else {
string text = "Maximum (5) amount of upgrades reached for this property!";
QString qText = QString::fromStdString(text);
QMessageBox maxUpgrade;
maxUpgrade.setText(qText);
maxUpgrade.exec();
}
setMoneyText();
disableUpgrade();
}
void GUIPlayers::setAllSpaces(Space** spaceArray){
allSpaces = new Space*[40];
allSpaces = spaceArray;
}
void GUIPlayers::setBank(Bank* tempBank){
bankPointer = new Bank;
bankPointer = tempBank;
}