Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Character.h documentation for Player class methods
- /*Constructor*/
- Player::Player()
- {
- encounterNum = 0;
- journalSize = 0;
- password = "";
- setName("Hero");
- setHealth(100);
- setCurrentHealth(100);
- setSpeed(5);
- setDefense(5);
- setAttack(10);
- setGold(20.0);
- setupBag();
- myJournal = new BST<std::string>; //because of this player should always be dynamically allocated.
- }
- /*Inserts new item into players bag
- Pre: string item
- Post: new item added to players inventory*/
- void Player::addNewItem(std::string item)
- {
- addToBag(item);
- setBagSize(getBagSize() + 1);
- }
- /*New entry added into players journal
- Pre: string entry
- Post: new entry added to journal*/
- void Player::addToJournal(std::string entry)
- {
- myJournal->setRoot(myJournal->insertBST(myJournal->getRoot(), entry));
- }
- /*Displays contents of players journal entries
- Pre: void
- Post: journal entries displayed*/
- void Player::outputJournal() //new addition 6/3/18
- {
- myJournal->inorder(myJournal->getRoot());
- }
- /*Searches for player journal entry by title
- Pre: string entry
- Post: retrieves journal entry
- Return: boolean true if entry found, false otherwise*/
- bool Player::checkJournal(std::string entry) //new addition 6/3/18 cannot confirm if working just groundwork
- {
- return myJournal->searchBST(entry, myJournal->getRoot());
- }
- /*Inserts a new Entry into player journal
- Pre: string entry
- Post: new entry added to journal*/
- void Player::addNewEntry(std::string entry)
- {
- bool exists = true;
- exists = myJournal->searchBST(entry, myJournal->getRoot());
- if (!exists)
- {
- addToJournal(entry);
- journalSize++;
- }
- }
- /*Retrieves all entries from player journal
- Pre: integer size of entry array
- Post: void
- Return: string of journal entry*/
- std::string Player::getJournalEntries(int arrsize)
- {
- std::string *jarr = new std::string[arrsize];
- std::string jentries = "";
- int j = 0;
- myJournal->gameFetchJournal(jarr, arrsize, j, myJournal->getRoot());
- for (int i = 0; i < arrsize; i++)
- jentries = jentries + jarr[i] + '\t';
- delete[] jarr;
- return jentries;
- }
- /*Retrieves item from player bag
- Pre: integer index
- Post: void
- Return: string of bag item*/
- std::string Player::getBagItem(int index)
- {
- return myBag->getData(index);
- }
- /* Deletes Node with item from myBag string List
- Pre: integer index
- Post: item is removed from player bag*/
- void Player::removeBagItem(int index)
- {
- //std::cout << "Removing " << myBag->getData(index) << " item from your bag. " << std::endl;
- myBag->deleteAny(index);
- setBagSize(getBagSize() - 1);
- }
- /*Inserts a new item into players bag
- Pre: string item
- Post: new item added to bag*/
- void Player::addToBag(std::string item)
- {
- Node<std::string> *itemNode = new Node<std::string>;
- itemNode->setData(item);
- myBag->insertFirst(itemNode);
- itemNode = nullptr;
- }
- /*Displays contents of players bag to console
- Pre: integer i
- Post: all items inside playrs bag displayed*/
- 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];
- {
- return myBag->getData(i + 1);
- }
- /*Displays players journal entries in indented format
- Pre: void
- Post: void*/
- void Player::printIndent()
- {
- myJournal->postOrderOut(myJournal->getRoot(), 0);
- }
- /*Resets player attributes to original settings, used after player dies and before sent back
- to main menu
- Pre: void
- Post: Player object settings reset*/
- void Player::clearCharacter() //issue with addind in delete bag and delete jounral. for now removing them.
- {
- setName("Hero");
- setHealth(100);
- setCurrentHealth(100);
- setAttack(10);
- setDefense(5);
- setSpeed(5);
- setGold(0.0);
- setBagSize(0);
- if (myBag != NULL)
- clearBag();
- if (myJournal->getRoot() != NULL)
- {
- myJournal->clearBST(myJournal->getRoot());
- myJournal->setRoot(nullptr);
- }
- journalSize = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement