Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.10 KB | None | 0 0
  1. #include "RollDiceAction.h"
  2.  
  3. #include "Grid.h"
  4. #include "Player.h"
  5.  
  6. #include <time.h> // used to in srand to generate random numbers with different seed
  7.  
  8. RollDiceAction::RollDiceAction(ApplicationManager *pApp) : Action(pApp)
  9. {
  10.         // Initializes the pManager pointer of Action with the passed pointer
  11. }
  12.  
  13. void RollDiceAction::ReadActionParameters()
  14. {
  15.     // no parameters to read from user
  16. }
  17.  
  18. void RollDiceAction::Execute()
  19. {
  20.        
  21.     ///TODO: Implement this function as mentioned in the guideline steps (numbered below) below
  22.  
  23.  
  24.     // == Here are some guideline steps (numbered below) to implement this function ==
  25.     Grid* pGrid = pManager->GetGrid();
  26.     Output* pOut = pGrid->GetOutput();
  27.     Input* pIn = pGrid->GetInput();
  28.     Player* CurrentPlayer = pGrid ->GetCurrentPlayer();
  29.     // 1- Check if the Game is ended (Use the GetEndGame() function of pGrid), if yes, make the appropriate action
  30.     if ( pGrid ->GetEndGame() == true )
  31.     {
  32.        pOut ->PrintMessage(" The Game is finished. Thank you ! Click to continue ....");
  33.        int x,y;
  34.        pIn ->GetPointClicked(x,y);
  35.        return;
  36.     }
  37.     // -- If not ended, do the following --:
  38.     if ( CurrentPlayer ->getCheck_PreventPlayer() == true )
  39.     {
  40.         CurrentPlayer ->setCheck_PreventPlayer( false );
  41.         pOut ->PrintMessage(" You are prevented from rolling this turn. Click to continue ...");
  42.         int x,y;
  43.        pIn ->GetPointClicked(x,y);
  44.        pOut ->ClearStatusBar();
  45.        pGrid ->AdvanceCurrentPlayer();
  46.        CurrentPlayer ->increament_turnCount();
  47.        return;
  48.     }
  49.     if ( CurrentPlayer ->getCheck_DeductCoins() == true)
  50.     {
  51.           pGrid ->DeductCoins_OnePlayer(CurrentPlayer ->getPlayerNum());
  52.           pOut ->PrintMessage(" Your wallet will be decreased by 20 Coins in this turn. Click to continue ... ");
  53.           int x,y;
  54.           pIn ->GetPointClicked(x,y);
  55.           pOut ->ClearStatusBar();
  56.           CurrentPlayer ->increament_NumOfDeductCoins();
  57.     }
  58.  
  59.     // 2- Generate a random number from 1 to 6 --> This step is done for you
  60.     srand((int)time(NULL)); // time is for different seed each run
  61.     int diceNumber = 1 + rand() % 6; // from 1 to 6 --> should change seed
  62.     if ( CurrentPlayer ->getCheck_DeductRollNumb() == true )
  63.     {
  64.          string msg = "You got a dice value of : " + to_string(diceNumber);
  65.          pOut ->PrintMessage(msg);
  66.          int x,y;
  67.          pIn->GetPointClicked(x,y);
  68.          pOut ->ClearStatusBar();
  69.           pOut ->PrintMessage(" Your diceNumber will be decreased by 1 number in this turn. Click to continue ... ");
  70.           diceNumber -=1;
  71.           pIn ->GetPointClicked(x,y);
  72.           pOut ->ClearStatusBar();
  73.          CurrentPlayer ->increament_NumOfDeductRollNum();
  74.     }
  75.     string msg = "You got a dice value of : " + to_string(diceNumber);
  76.     pOut ->PrintMessage(msg);
  77.     int x,y;
  78.     pIn->GetPointClicked(x,y);
  79.     pOut ->ClearStatusBar();
  80.     // 3- Get the "current" player from pGrid
  81.     // 4- Move the currentPlayer using function Move of class player
  82.     CurrentPlayer ->Move(pGrid,diceNumber);
  83.     // 5- Advance the current player number of pGrid
  84.     pGrid ->AdvanceCurrentPlayer();
  85.     // NOTE: the above guidelines are the main ones but not a complete set (You may need to add more steps).
  86. }
  87.  
  88. RollDiceAction::~RollDiceAction()
  89. {
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement