-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInputDiceValueAction.cpp
77 lines (61 loc) · 1.83 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
75
76
77
#include "InputDiceValueAction.h"
#include "Grid.h"
#include "Player.h"
InputDiceValueAction::InputDiceValueAction(ApplicationManager* pApp) :Action(pApp)
{
}
void InputDiceValueAction::ReadActionParameters()
{
// A pointer to the Input/Output interfaces
Grid* pGrid = pManager->GetGrid();
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
bool gameEnded = pGrid->GetEndGame();
if (!gameEnded)
{
pOut->PrintMessage("Please Enter a dice value between 1-6 . ");
int value = pIn->GetInteger(pOut); //store the passed integer in (value)
//Verification on the input dice value
if (value > 0 && value < 7)
{
DiceValue = value; //sets the dice value with the input value
}
//if the dice value is out of range
else
{
int x, y;
DiceValue = -1;
pOut->PrintMessage("The Dice value you entered is out of range, Click to continue. ");
pIn->GetPointClicked(x, y);
pOut->ClearStatusBar();
}
}
// clears the status bar
pOut->ClearStatusBar();
}
void InputDiceValueAction::Execute()
{
ReadActionParameters();
// Check if the Game is ended
Grid* pGrid = pManager->GetGrid();
Input* pIn = pGrid->GetInput();
Output* pOut = pGrid->GetOutput();
bool gameEnded = pGrid->GetEndGame();
// -- If not ended && Dice value is within the range
if ((!gameEnded) && (DiceValue != -1))
{
int x, y;
pOut->PrintMessage("The dice value you entered is " + to_string(DiceValue) + ", click to continue.");
pIn->GetPointClicked(x, y);
// Get the "current" player from pGrid
Player* currentPlayer = pGrid->GetCurrentPlayer();
// Move the currentPlayer using function Move of class player
currentPlayer->Move(pGrid, DiceValue);
// Advance the current player number of pGrid
pOut->ClearStatusBar();
pGrid->AdvanceCurrentPlayer();
}
}
InputDiceValueAction:: ~InputDiceValueAction()
{
}