-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiceValueAction.cpp
More file actions
71 lines (55 loc) · 1.23 KB
/
Copy pathDiceValueAction.cpp
File metadata and controls
71 lines (55 loc) · 1.23 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
#include "DiceValueAction.h"
#include "Player.h"
DiceValueAction::DiceValueAction(ApplicationManager* pApp) : Action(pApp)
{
num = 0;
anum = 0;
}
DiceValueAction::~DiceValueAction()
{
}
void DiceValueAction::ReadActionParameters()
{
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
pOut->PrintMessage("please enter a dice value between 1-6: ");
num = pIn->GetInteger(pOut);
if (num > 6 || num < 1)
{
pGrid->PrintErrorMessage("Invalid");
}
else
{
anum = 1;
}
}
void DiceValueAction::Execute()
{
///TODO: Implement this function as mentioned in the guideline steps (numbered below) below
// == Here are some guideline steps (numbered below) to implement this function ==
// 1- Check if the Game is ended (Use the GetEndGame() function of pGrid), if yes, make the appropriate action
Grid* pGrid = pManager->GetGrid();
if (pGrid->GetEndGame())
{
pGrid->PrintErrorMessage("Game has ended");
}
else
{
ReadActionParameters();
if (anum)
{
Player* p1 = pGrid->GetCurrentPlayer();
if (p1->GetWallet())
{
p1->Move(pGrid, num);
pGrid->AdvanceCurrentPlayer();
}
else
{
p1->IncTurnCount();
pGrid->AdvanceCurrentPlayer();
}
}
}
}