-
Notifications
You must be signed in to change notification settings - Fork 1
/
Return.cpp
68 lines (61 loc) · 2.17 KB
/
Return.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
#include "Return.h"
#include "Input.h"
#include "Output.h"
#include"Player.h"
#include"Card.h"
Return::Return(ApplicationManager *pApp) : Action(pApp)
{
// Initializes the pManager pointer of Action with the passed pointer
}
Return::~Return()
{
}
void Return::ReadActionParameters()
{
// Get a Pointer to the Input / Output Interfaces
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
// Read the wallet value parameter
do{
pGrid->PrintErrorMessage("Enter the value of the city you want to return its mortgage (((7-11))) if there,click and enter");
cardNumber=pGrid->GetInput()->GetInteger(pGrid->GetOutput());
}while(cardNumber<7||cardNumber>11);
// Clear messages
pOut->ClearStatusBar();
}
// Execute the action
void Return::Execute()
{
// The first line of any Action Execution is to read its parameter first
// and hence initializes its data members
Grid* pgrid = pManager->GetGrid();
int pplayer;
string yesno;
if(pgrid->GetCurrentPlayer()->getpnum()-1<0)// check Accept.cpp execute for further details on the logic of this line
pplayer=3;
else
pplayer=pgrid->GetCurrentPlayer()->getpnum()-1;
do
{
ReadActionParameters();
if(pgrid->checkmortgage(cardNumber,pplayer))
{
Card* cards = pgrid->getcity(cardNumber);
int mortgaged= cards->getmor();
Player* morta = pgrid->getplayer(mortgaged);
Player* owner = pgrid->getplayer(pplayer);
morta->SetWallet(morta->GetWallet() + (cards->getprice()/100)*70); // return the 70% mortgage value to the accepting player
owner->SetWallet(owner->GetWallet() - (cards->getprice()/100)*70);
pgrid->setmorta(cardNumber,5);// 5 is the default value of a non mortgaged city // make this city not mortgaged
}
else
{
pgrid->PrintErrorMessage("ERROR....City may not be on grid or not mortgaged or not even yours,click to return");
return;
}
pgrid->PrintErrorMessage("Do you want to return another city from its mortgage?? click then enter y/n");
yesno = pgrid->GetInput()->GetSrting(pgrid->GetOutput());
pgrid->UpdateInterface();
}while(yesno =="n");
}