Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Dungeon-Game/inventory.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
28 lines (24 sloc)
843 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include "inventory.h" | |
using namespace std; | |
Inventory::Inventory() //constructor | |
{ | |
} | |
string Inventory::add(string item) //adds an item to inventory | |
{ | |
allItems.push_back(item); //adds the specified item to the back of the vector | |
std::cout<<"Added " <<item<<" to inventory."; | |
return item; | |
} | |
string Inventory::remove(string item) //removes an item from the inventory | |
{ | |
allItems.erase(std::remove(allItems.begin(), allItems.end(), item), allItems.end()); //removes any elements that meet a criteria (item) within a range (start and end) | |
std::cout<<"Tossed " <<item<<" away."; | |
} | |
void Inventory:: display() //show number of items in inventory | |
{ | |
std::cout<< "You have " << allItems.size() << " items."; //outputs the total size of the vector. | |
} |