-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInputDiceValueAction.cpp
74 lines (58 loc) · 2 KB
/
InputDiceValueAction.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
#include "InputDiceValueAction.h"
#include "Grid.h"
#include "Player.h"
InputDiceValueAction::InputDiceValueAction(ApplicationManager* pApp) : Action(pApp)
{
diceNumber = 0;
}
void InputDiceValueAction::ReadActionParameters()
{
Grid* pGrid = pManager->GetGrid();
Input* pIn = pGrid->GetInput();
Output* pOut = pGrid->GetOutput();
pOut->PrintMessage("Input Dice Value: ");
diceNumber = pIn->GetInteger(pGrid->GetOutput());
}
void InputDiceValueAction::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();
Output* pOut = pGrid->GetOutput();
if (pGrid->GetEndGame())
{
pGrid->PrintErrorMessage("Game Ended! hahaha");
return;
}
int Prisons = pGrid->GetCurrentPlayer()->GetPrison();
if (Prisons > 0)
{
Output* pOut = pGrid->GetOutput();
pOut->PrintMessage("You are still in Prison!!");
}
else
{
ReadActionParameters(); // 2 - Read the needed parameters from the user
}
// -- If not ended, do the following --:
// 3- Get the "current" player from pGrid
Player* pPlayer = pGrid->GetCurrentPlayer();
// 4- Move the currentPlayer using function Move of class player
int currentPos = pPlayer->GetCell()->GetCellPosition().GetCellNum();
if (currentPos + diceNumber >= 99)
{
pGrid->SetEndGame(true);
pPlayer->Move(pGrid, 99 - currentPos);
pGrid->PrintErrorMessage("Game has ended! Player " + to_string(pGrid->getCurrPlayerNumber()) + " has won!! Click for Options..");
pOut->PrintMessage("You can restart or go to design mode...");
return;
}
pPlayer->Move(pGrid, diceNumber);
// 5- Advance the current player number of pGrid
pGrid->AdvanceCurrentPlayer();
// NOTE: the above guidelines are the main ones but not a complete set (You may need to add more steps).
}
InputDiceValueAction::~InputDiceValueAction()
{
}