Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.63 KB | None | 0 0
  1. #include "CardTen.h"
  2.  
  3.  
  4. CardTen::CardTen(const CellPosition & pos) : Card(pos) // set the cell position of the card
  5. {
  6.     cardNumber = 10; // set the inherited cardNumber data member with the card number (9 here)
  7.     OwnerPlayer = NULL ; //initialize the ownerplayer to null
  8.     checkCardTenSave = false; // initialize cardten to false ( first save )
  9.     checkCardTenload = false; // initialize cardten to false ( first load )
  10. }
  11. CardTen::CardTen()
  12. {
  13.     cardNumber = 10;
  14. }
  15. void CardTen::ReadCardParameters(Grid * pGrid)
  16. {
  17.     Output* pOut = pGrid->GetOutput();
  18.     Input* pIn = pGrid->GetInput();
  19.     Card* pCard = pGrid ->GetTheFirstCardTen();
  20.     if ( pCard)
  21.     {
  22.        pOut ->PrintMessage("New CardTen. Click to continue...");
  23.        int x,y;
  24.        pIn ->GetPointClicked(x,y);
  25.        pOut ->ClearStatusBar();
  26.        CardTen* FirstCardTen = dynamic_cast <CardTen*> ( pCard );
  27.        CardPrice = FirstCardTen ->CardPrice;
  28.        FeesToPay = FirstCardTen ->FeesToPay;
  29.        return;
  30.     }
  31.     pOut ->PrintMessage("New CardTen: Enter its CardPrice ...");
  32.     CardPrice = pIn ->GetInteger(pOut);
  33.     pOut ->PrintMessage(" Enter the fees you  want any other player to pay ...");
  34.     FeesToPay = pIn ->GetInteger(pOut);
  35.     pOut ->ClearStatusBar();
  36. }
  37.  
  38. void CardTen::Apply(Grid* pGrid, Player* pPlayer)
  39. {
  40.     Output* pOut = pGrid->GetOutput();
  41.     Input* pIn = pGrid->GetInput();
  42.  
  43.     if(!OwnerPlayer)
  44.     {
  45.         pOut ->PrintMessage ("Do you want to buy CardTen? (y/n) ");
  46.         string actualmsg = pIn ->GetSrting(pOut);
  47.         while ( actualmsg != "y" && actualmsg != "n" )
  48.         {
  49.          pOut ->PrintMessage ("Do you want to buy CardTen, please enter y for Yes and n for No: ");
  50.          actualmsg = pIn ->GetSrting(pOut);
  51.         }
  52.             if (actualmsg=="y")
  53.             {
  54.                 if (pPlayer->GetWallet()> CardPrice)
  55.                 {
  56.                     int NewWalletAmount = pPlayer->GetWallet()-CardPrice;
  57.                     pPlayer->SetWallet(NewWalletAmount);
  58.                     string msg =" Your new wallet amount is equal to " + to_string(NewWalletAmount);
  59.                     pOut ->PrintMessage(msg);
  60.                     int x,y;
  61.                     pIn ->GetPointClicked(x,y);
  62.                     pOut ->ClearStatusBar();
  63.                     OwnerPlayer = pPlayer;
  64.                     pGrid ->setAllCardTen(OwnerPlayer);
  65.                     return;
  66.                 }
  67.                 else
  68.                 {
  69.                     pOut ->PrintMessage(" you don't have enough money to buy the card . Click to continue...");
  70.                     int x,y;
  71.                     pIn ->GetPointClicked(x,y);
  72.                     pOut ->ClearStatusBar();
  73.                     return;
  74.                 }
  75.             }
  76.             else
  77.                 return;
  78.     }
  79.     else
  80.     {
  81.         if ( pPlayer->getPlayerNum() != OwnerPlayer ->getPlayerNum())
  82.         {
  83.         pPlayer ->SetWallet(pPlayer ->GetWallet() - FeesToPay);
  84.         OwnerPlayer ->SetWallet(OwnerPlayer ->GetWallet() + FeesToPay );
  85.         string msg =" Your new wallet amount is equal to " + to_string(pPlayer ->GetWallet() - FeesToPay);
  86.         pOut ->PrintMessage(msg);
  87.         int x,y;
  88.         pIn ->GetPointClicked(x,y);
  89.         pOut ->ClearStatusBar();
  90.         return;
  91.         }
  92.     }
  93. }
  94. void CardTen::Save(ofstream &OutFile, Type gameObject)
  95. {
  96.     if ( checkCardTenSave == false )
  97.     {
  98.     if ( gameObject == Cards )
  99.     {
  100.       OutFile << cardNumber << " " << position.GetCellNum() << " " << CardPrice << FeesToPay << endl;
  101.     }
  102.     }
  103.     else
  104.     {
  105.         if ( gameObject == Cards )
  106.     {
  107.       OutFile << cardNumber << " " << position.GetCellNum() << endl;
  108.     }  
  109.     }
  110. }
  111. void CardTen::Load(ifstream& Infile)
  112. {
  113.     if ( checkCardTenload == false )
  114.     {
  115.      int  CellposNum, CardPrice,FeesToPay ;
  116.     Infile >> CellposNum >> CardPrice >> FeesToPay;
  117.     CellPosition Cellpos(CellposNum);
  118.     position = Cellpos;
  119.     }
  120.     else
  121.     {
  122.       int  CellposNum, CardPrice,FeesToPay ;
  123.     Infile >> CellposNum ;
  124.     CellPosition Cellpos(CellposNum);
  125.     position = Cellpos;
  126.  
  127.     }
  128. }
  129.  
  130. void CardTen::SetOwnerPlayer(Player* pPlayer)
  131. {
  132.     OwnerPlayer = pPlayer;
  133. }
  134. CardTen::~CardTen()
  135. {
  136.  
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement