-
Notifications
You must be signed in to change notification settings - Fork 0
/
DevelopmentCard.cpp
107 lines (97 loc) · 3.56 KB
/
DevelopmentCard.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
/*
* File: DevelopmentCard.cpp
* Author: brandon
*
* Created on May 31, 2011, 7:15 PM
*/
#include "DevelopmentCard.h"
#include "GameLibrary.h"
#include "Player.h"
#include "Board.h"
#include "GameDockWidget.h"
#include <QtCore/QStringList>
#include <QtGui/QInputDialog>
DevelopmentCard::DevelopmentCard(QListWidget* parent) : QListWidgetItem(parent) {
type = rand() % DEVCARD_TYPES;
this->setText(QString::fromStdString(toString()));
}
DevelopmentCard::DevelopmentCard(int type, QListWidget* parent) : QListWidgetItem(parent) {
this->type = type;
this->setText(QString::fromStdString(toString()));
}
DevelopmentCard::~DevelopmentCard() {
}
bool DevelopmentCard::activate() {
bool ok = false;
QPair<int, int> yopResources;
QStringList s_list;
std::string toSteal;
std::vector<Player*>* players;
int stolenCount;
switch (type) {
case KNIGHT:
while (!GameLibrary::getCurrentBoard()->moveRobber(rand() % GameLibrary::getCurrentBoard()->getNumberOfTiles()));
ok = true;
//TODO: and knight card should steal from player...
break;
case ROAD_BUILD:
//GameLibrary::getCurrentLocalPlayer()->giveResource(WOOD, 2);
//GameLibrary::getCurrentLocalPlayer()->giveResource(BRICK, 2);
QMessageBox::information(GameLibrary::getDockWidget(),"Free Roads!", "You can now build 2 free roads!", QDialogButtonBox::Ok, QDialogButtonBox::Ok);
ok = true;
break;
case YEAR_PLENTY:
yopResources = YearOfPlentyDialog::getResourcePair(GameLibrary::getDockWidget());
if (yopResources.first > 0 && yopResources.second > 0) {
GameLibrary::getCurrentLocalPlayer()->giveResource(yopResources.first, 1);
GameLibrary::getCurrentLocalPlayer()->giveResource(yopResources.second, 1);
ok = true;
}
break;
case MONOPOLY:
s_list = QStringList();
for (int i = 0; i < NUM_RESOURCES; i++) {
s_list.append(QString::fromStdString(GameLibrary::getResourceString(i)));
}
toSteal = QInputDialog::getItem(GameLibrary::getDockWidget(), "Settlers | Monopoly Card", "What resource would you like to steal from everyone?", s_list, 0, false, &ok).toStdString();
if (ok) {
players = GameLibrary::getPlayers();
stolenCount = 0;
for (int i = 0; i < GameLibrary::getNumberOfPlayers(); i++) {
if (players->at(i) != GameLibrary::getCurrentLocalPlayer()) {
stolenCount += players->at(i)->stealResource(GameLibrary::getResource(toSteal));
}
}
GameLibrary::getCurrentLocalPlayer()->giveResource(GameLibrary::getResource(toSteal), stolenCount);
}
break;
case VICTORY_POINT:
GameLibrary::getCurrentLocalPlayer()->addPoint();
ok = true;
break;
}
return ok;
}
int DevelopmentCard::getType() {
return type;
}
std::string DevelopmentCard::toString() {
switch (type) {
case KNIGHT:
return "Knight Card";
break;
case ROAD_BUILD:
return "Road Builder's Card";
break;
case YEAR_PLENTY:
return "Year of Plenty Card";
break;
case MONOPOLY:
return "Monopoly Card";
break;
case VICTORY_POINT:
return "Victory Point Card";
break;
}
return "error card";
}