Advertisement
Guest User

Character.h

a guest
Jun 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.85 KB | None | 0 0
  1. Character.h documentation for Player class methods
  2.  
  3. /*Constructor*/
  4. Player::Player()
  5. {
  6.     encounterNum = 0;
  7.     journalSize = 0;
  8.     password = "";
  9.     setName("Hero");
  10.     setHealth(100);
  11.     setCurrentHealth(100);
  12.     setSpeed(5);
  13.     setDefense(5);
  14.     setAttack(10);
  15.     setGold(20.0);
  16.     setupBag();
  17.     myJournal = new BST<std::string>; //because of this player should always be dynamically allocated.
  18. }
  19.  
  20. /*Inserts new item into players bag
  21.     Pre: string item
  22.     Post: new item added to players inventory*/
  23. void Player::addNewItem(std::string item)
  24. {
  25.     addToBag(item);
  26.     setBagSize(getBagSize() + 1);
  27. }
  28.  
  29. /*New entry added into players journal
  30.     Pre: string entry
  31.     Post: new entry added to journal*/
  32. void Player::addToJournal(std::string entry)
  33. {
  34.     myJournal->setRoot(myJournal->insertBST(myJournal->getRoot(), entry));
  35. }
  36.  
  37. /*Displays contents of players journal entries
  38.     Pre: void
  39.     Post: journal entries displayed*/
  40. void Player::outputJournal() //new addition 6/3/18
  41. {
  42.     myJournal->inorder(myJournal->getRoot());
  43. }
  44.  
  45. /*Searches for player journal entry by title
  46.     Pre: string entry
  47.     Post: retrieves journal entry
  48.     Return: boolean true if entry found, false otherwise*/
  49. bool Player::checkJournal(std::string entry) //new addition 6/3/18 cannot confirm if working just groundwork
  50. {
  51.     return myJournal->searchBST(entry, myJournal->getRoot());
  52. }
  53.  
  54. /*Inserts a new Entry into player journal
  55.     Pre: string entry
  56.     Post: new entry added to journal*/
  57. void Player::addNewEntry(std::string entry)
  58. {
  59.     bool exists = true;
  60.     exists = myJournal->searchBST(entry, myJournal->getRoot());
  61.     if (!exists)
  62.     {
  63.         addToJournal(entry);
  64.         journalSize++;
  65.     }
  66. }
  67.  
  68. /*Retrieves all entries from player journal
  69.     Pre: integer size of entry array
  70.     Post: void
  71.     Return: string of journal entry*/
  72. std::string Player::getJournalEntries(int arrsize)
  73. {
  74.     std::string *jarr = new std::string[arrsize];
  75.     std::string jentries = "";
  76.     int j = 0;
  77.     myJournal->gameFetchJournal(jarr, arrsize, j, myJournal->getRoot());
  78.     for (int i = 0; i < arrsize; i++)
  79.         jentries = jentries + jarr[i] + '\t';
  80.     delete[] jarr;
  81.     return jentries;
  82. }
  83.  
  84. /*Retrieves item from player bag
  85.     Pre: integer index
  86.     Post: void
  87.     Return: string of bag item*/
  88. std::string Player::getBagItem(int index)
  89. {
  90.     return myBag->getData(index);
  91.  
  92. }
  93.  
  94. /* Deletes Node with item from myBag string List
  95.     Pre: integer index
  96.     Post: item is removed from player bag*/
  97. void Player::removeBagItem(int index)
  98. {
  99.     //std::cout << "Removing " << myBag->getData(index) << " item from your bag. " << std::endl;
  100.     myBag->deleteAny(index);
  101.     setBagSize(getBagSize() - 1);
  102. }
  103.  
  104. /*Inserts a new item into players bag
  105.     Pre: string item
  106.     Post: new item added to bag*/
  107. void Player::addToBag(std::string item)
  108. {
  109.     Node<std::string> *itemNode = new Node<std::string>;
  110.     itemNode->setData(item);
  111.     myBag->insertFirst(itemNode);
  112.     itemNode = nullptr;
  113. }
  114.  
  115. /*Displays contents of players bag to console
  116.     Pre: integer i
  117.     Post: all items inside playrs bag displayed*/
  118. std::string Player::outputBag(int i) const//off by one, assuming i starts at 0 i.e. array indexing. array[0] corresponds to list[1];
  119. {
  120.     return myBag->getData(i + 1);
  121. }
  122.  
  123. /*Displays players journal entries in indented format
  124.     Pre: void
  125.     Post: void*/
  126. void Player::printIndent()
  127. {
  128.     myJournal->postOrderOut(myJournal->getRoot(), 0);
  129. }
  130.  
  131. /*Resets player attributes to original settings, used after player dies and before sent back
  132. to main menu
  133.     Pre: void
  134.     Post: Player object settings reset*/
  135. void Player::clearCharacter() //issue with addind in delete bag and delete jounral. for now removing them.
  136. {
  137.     setName("Hero");
  138.     setHealth(100);
  139.     setCurrentHealth(100);
  140.     setAttack(10);
  141.     setDefense(5);
  142.     setSpeed(5);
  143.     setGold(0.0);
  144.     setBagSize(0);
  145.     if (myBag != NULL)
  146.         clearBag();
  147.     if (myJournal->getRoot() != NULL)
  148.     {
  149.         myJournal->clearBST(myJournal->getRoot());
  150.         myJournal->setRoot(nullptr);
  151.     }
  152.     journalSize = 0;
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement