Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////// Game.cpp //////////////////////
- #include <../Head.hpp>
- void Start(Item &Root){
- Root.Retrieve("Exit Status").SetDescription("Ok!");
- }
- ////////////////////// Engine.cpp //////////////////////
- #include <../Head.hpp>
- void Start(Item &Root);
- int main( int argc, char* args[] ){
- Item Root("Root");
- Item Tmp("Exit Status");
- Tmp.SetDescription("?");
- Root.Add(Tmp);
- Start(Root);
- cout << Root.Retrieve("Exit Status").GetDescription() << endl;
- return 0;}
- ////////////////////// Head.hpp //////////////////////
- #include <iostream>
- #include <string>
- #include <vector>
- #include <Item.h>
- #define string std::string
- #define cout std::cout
- #define cin std::cin
- #define endl std::endl
- #define cerr std::cerr
- #define string std::string
- #define vector std::vector
- ////////////////////// Item.h //////////////////////
- #ifndef ITEM_H
- #define ITEM_H
- #include "../Head.hpp"
- class Item
- {
- vector<string> Names;
- vector<Item> Contents;
- float X=0,Y=0,Quantity=1,Weight=1;
- string Name="Root",Description;
- void Increment(int index);
- void Decrement(int index);
- public:
- Item(string nName,float nX=1,float nY=1,float nWeight=1);
- void Add(Item item);
- void Remove(Item item);
- int Find(string Item_Name);
- string GetName();
- float GetWeight();
- string GetDescription();
- void SetDescription(string Item_Name);
- void SetName(string Item_Name);
- Item Retrieve(string Item_Name);
- };
- #endif // ITEM_H
- ////////////////////// Item.cpp //////////////////////
- #include "Item.h"
- Item::Item(string nName,float nX,float nY,float nWeight){
- Name=nName;
- Weight=nWeight;
- X=nX;
- Y=nY;
- }
- Item Item::Retrieve(string Item_Name){
- int found = Find(Item_Name);
- return Contents[found];
- }
- string Item::GetName(){
- return Name;
- }
- float Item::GetWeight(){
- return Weight;
- }
- string Item::GetDescription(){
- return Description;
- }
- void Item::SetDescription(string Item_Name){
- Description = Item_Name;
- }
- void Item::SetName(string Item_Name){
- Name=Item_Name;
- }
- void Item::Add(Item item){
- int found = Find(item.Name);
- if(!found){
- Names.push_back(item.Name);
- Contents.push_back(item);
- Weight = Weight + item.Weight;
- }else{
- Contents[found].Increment(found);
- }
- }
- void Item::Remove(Item item){
- int found = Find(item.Name);
- if(found){
- if(found > 1){
- Contents[found].Decrement(found);
- }else{
- vector<Item> tmplist;
- for(int a=0;a<Contents.size();++a){
- if(Contents[a].Name != Contents[found].Name){
- tmplist.push_back(Contents[a]);
- }
- }
- Contents.clear();
- for(int a=0;a<tmplist.size();++a){
- Contents.push_back(tmplist[a]);
- }
- }
- }
- }
- int Item::Find(string Item_Name){
- int result=0;
- for(int a=0;a < Contents.size();++a){
- if(Contents[a].Name == Item_Name){
- result = a;
- }
- }
- return result;
- }
- void Item::Increment(int index){
- Contents[index].Quantity+1;
- }
- void Item::Decrement(int index){
- Contents[index].Quantity-1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement