-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilSquare.cpp
More file actions
114 lines (113 loc) · 3.54 KB
/
utilSquare.cpp
File metadata and controls
114 lines (113 loc) · 3.54 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
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
#include <iostream>
#include <vector>
#include <string>
#include "player.h"
#include "utilSquare.h"
using namespace std;
//utilSquare constructor
utilSquare::utilSquare(int position, string tileName, int cost) : propertySquare(position, tileName, cost)
{
this->utilRent = 25;
this->utilMulti = 1;
}
//Getters and setters
int utilSquare::getUtilRent()
{
return this->utilRent;
}
int utilSquare::getUtilMulti()
{
return this->utilMulti;
}
void utilSquare::setUtilRent(int rent)
{
this->utilRent = rent;
}
void utilSquare::setUtilMulti(int multi)
{
this->utilMulti = multi;
}
//Gets actions at current utilSquare
vector<string> utilSquare::getActions(player& player)
{
vector<string> actionsVector;
this->required(player);
if (this->getPropertyAvailable()) {
actionsVector.push_back("Buy Property");
}
if (player.getPlayerProperty().size() > 0) {
actionsVector.push_back("Buy Houses / Hotels");
actionsVector.push_back("Trade Property");
}
actionsVector.push_back("End Turn");
return actionsVector;
}
//Required actions at current utilSquare
void utilSquare::required(player& player)
{
if (!this->getPropertyAvailable()) {
if (this->getPropertyOwner() != &player) {
int min = 1, max = 3;
int randNum = rand() % (max - min + 1) + min;
int multi = this->getUtilMulti() * randNum;
int tempRent = this->getUtilRent() * this->getUtilMulti();
cout << "You paid: " << tempRent << " in Rent to " << this->getPropertyOwner()->getPlayerName() << endl;
player.setPlayerMoney(player.getPlayerMoney() - tempRent);
this->getPropertyOwner()->setPlayerMoney(this->getPropertyOwner()->getPlayerMoney() + tempRent);
}
}
}
//Purchases current utilSquare
void utilSquare::purchaseUtilSquare(player& player) {
if (this->getPropertyAvailable()) {
if (player.getPlayerMoney() >= this->getPropertyCost()) {
player.setPlayerMoney(player.getPlayerMoney() - this->getPropertyCost());
this->setPropertyAvailable(false);
this->setPropertyOwner(&player);
vector<int> currentPlayerProperty = player.getPlayerProperty();
currentPlayerProperty.push_back(this->getTilePosition());
player.setPlayerProperty(currentPlayerProperty);
cout << "You purchased: " << this->getTileName() << endl;
cout << "You now have: " << player.getPlayerMoney() << endl;
}
else {
cout << "You do not have enough money to purchase this property" << endl;
}
}
else {
cout << "This property is not available" << endl;
}
}
//Gets player selection from actions vector
int utilSquare::getPlayerSelection(vector<string>actions) {
int playerSelection = 0;
for (string action : actions) {
cout << "\t" << playerSelection << ": " << action << endl;
playerSelection++;
}
cout << "Please select an action: ";
cin >> playerSelection;
if (playerSelection > actions.size() - 1) {
cout << "Invalid Selection\n";
return getPlayerSelection(actions);
}
return playerSelection;
}
//Responds to player selection
void utilSquare::replyToPlayerSelection(vector<string>& actions, int selection, player& player) {
if (actions[selection] == "Buy Property") {
purchaseUtilSquare(player);
actions.erase(actions.begin() + selection);
}
else if (actions[selection] == "Buy Houses / Hotels") {
cout << "Sorry this feature has not been added yet" << endl;
actions.erase(actions.begin() + selection);
}
else if (actions[selection] == "End Turn") {
cout << "Ending Turn" << endl;
actions.erase(actions.begin() + selection);
}
else {
cout << "Invalid Selection" << endl;
}
}