forked from anthonyjuan-wang/Watopoly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacademic.cc
executable file
·126 lines (117 loc) · 4.67 KB
/
academic.cc
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
#include "academic.h"
#include "tile.h"
#include <string>
#include <memory>
#include <iostream>
#include <vector>
#include "player.h"
#include "board.h"
using namespace std;
Academic::Academic(int position, string blockName, string monopolyType, int purchaseCost, int improvementCost, int improvementNum,
vector<int> tuitionCost, shared_ptr<Board> board) : Tile{blockName, true, true, position, purchaseCost, board} {
tuition = tuitionCost;
this->improvementCost = improvementCost;
monopoly = monopolyType;
this->improvementNum = improvementNum;
}
Academic::~Academic() {}
int Academic::getImprovement() {
return this->improvementNum;
}
void Academic::setImprovement(int x) {
this->improvementNum = x;
}
int Academic::getImproveCost() {
return this->improvementCost;
}
string Academic::getMonopolyName() {
return monopoly;
}
void Academic::improveBuy(shared_ptr<Player> player) {
// Get current improvement #
// Get the improvement cost
// Subtract cost from bank
// Increase improvemnt #
int currentImprovement = getImprovement();
int improvementCost = getImproveCost();
player->subtractMoney(improvementCost);
setImprovement(currentImprovement + 1);
}
void Academic::improveSell(shared_ptr<Player> player) {
// Get current improvement #
// Get the improvement cost
// Add HALf the cost to bank
// Decrease improvement #
int currentImprovement = getImprovement();
int improvementCost = getImproveCost();
player->addMoney(improvementCost / 2);
setImprovement(currentImprovement - 1);
}
void Academic::action(std::shared_ptr<Player> player) {
if (!isOwned()) {
// Do you have enough money to buy
cout << "Would you like to buy " << getName() << " for $" << getPrice() << "? Enter 'yes' or 'no'." << endl;
// ADDED SPACES HERE
cout << "\n";
// Look for "yes" or "no"
string answer;
while(1) {
cin >> answer;
if (answer == "yes") {
// Check if almost bankrupt
int remaining = player->getMoney() - getPrice();
if (remaining < 0) {
cout << "You don't have enough money to purchase this building." << endl;
cout << getName() << " will now go up for auction" << endl;
auction();
break;
} else {
vector<shared_ptr<Tile>> boardTiles = getBoard()->getTiles();
int currPos = getPos();
player->addTile(boardTiles[currPos]);
cout << "You have successfuly purchased " << boardTiles[currPos]->getName() << " for $" << getPrice() << endl;
player->subtractMoney(getPrice());
setOwner(player);
break;
}
} else if (answer == "no") {
// Player decides not to buy. Building now goes up for auction
cout << getName() << " will now go up for auction" << endl;
auction();
break;
} else {
// Player did not type "yes" or "no"
cout << "Please enter either \"yes\" or \"no\": Would you like to purchase this building for " << getPrice() << endl;
}
}
} else {
// Player lands on an already owner academic building
// Check that the player does not already own this spot
if (getOwner() != player) {
cout << "This building is owned by " << getOwner()->getName() << ". You will need to pay tuition worth $" << tuition[getImprovement()] << endl;
// Get the cost of tuition based on # of improvements
int cost = tuition[getImprovement()];
int remaining = player->getMoney() - cost;
// Check the player is bankrupt after paying for tuition
if (remaining < 0) {
cout << "You do not have enough to pay for tution. Find a way to pay for this property or you must drop out" << endl;
player->setAlmostBankruptStatus(true);
player->setMoneyOwed(cost);
} else {
// Pay for the tution cost
string answerpay;
while(1) {
cout << "Please type \"pay\" to pay for your tuition" << endl;
cin >> answerpay;
if (answerpay == "pay") {
player->subtractMoney(cost);
break;
}
}
}
} else {
// Player lands on their own tile
cout << "Nice, you own this property!" << endl;
}
}
}