Advertisement
Slowhand-VI

TUT: blackjack_manager.fos

Jan 19th, 2016
240
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**<
  2.  *  Manager class for Blackjack module.
  3.  */
  4.  
  5. #ifndef __BLACKJACK_MANAGER__
  6. #define __BLACKJACK_MANAGER__
  7.  
  8. #include "blackjack.fos"
  9.  
  10. class CBlackjackManager
  11. {
  12.     private array<CBlackjack@> games;
  13.  
  14.     CBlackjackManager()
  15.     {
  16.         //  This will show that this is called twice for some reason, needs to be fixed, not sure how. Probably put constructor call somewhere to when the server starts?
  17.         Log("BlackjackManager constructor called." + GetNumberOfGamesAvailable());
  18.         games = array<CBlackjack@>(0);
  19.     }
  20.  
  21.     CBlackjack@ GetPlayerGame(uint playerId)
  22.     {
  23.         for (uint i = 0; i < games.length(); i++)
  24.         {
  25.             if (games[i].GetPlayerId() == playerId)
  26.             {
  27.                 return games[i];
  28.             }
  29.         }
  30.         return null;
  31.     }
  32.  
  33.     CBlackjack@ CreateNewGame(uint playerId, uint dealerId, int numberOfDecksInShoe)
  34.     {
  35.         CBlackjack bj = CBlackjack(playerId, dealerId, numberOfDecksInShoe);
  36.         games.insertLast(bj);
  37.         return bj;
  38.     }
  39.  
  40.     void RemovePlayerGame(uint playerId)
  41.     {
  42.         for (uint i = 0; i < games.length(); i++)
  43.         {
  44.             if (games[i].GetPlayerId() == playerId)
  45.             {
  46.                 games.removeAt(i);
  47.             }
  48.         }
  49.     }
  50.  
  51.     int GetNumberOfGamesAvailable()
  52.     {
  53.         return games.length();
  54.     }
  55. };
  56.  
  57. /**< I moved this here, but need to find a place for it, where it will run only once. */
  58. CBlackjackManager blackjackManager = CBlackjackManager();
  59.  
  60. #endif // __BLACKJACK_MANAGER__
Advertisement
RAW Paste Data Copied
Advertisement