Advertisement
chopical

Item.cpp

Mar 4th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.65 KB | None | 0 0
  1. #include "Item.h"
  2.  
  3. Item::Item(string nName,float nX,float nY,float nWeight){
  4.     Log(string("(Item::Item)>")+nName+string(":")+to_string(nX)+string(":")+to_string(nY)+string(":")+to_string(nWeight));
  5.     Name=nName;
  6.     Weight=nWeight;
  7.     X=nX;
  8.     Y=nY;
  9. }
  10.  
  11. Item Item::Retrieve(string Item_Name){
  12.     Log(string("(Item ")+Name+string("::Retrieve)>")+Item_Name);
  13.     int found = Find(Item_Name);
  14.     return Contents[found];
  15. }
  16.  
  17. string Item::GetName(){
  18.     Log(string("(string ")+Name+string("::GetName)>")+Name);
  19.     return Name;
  20. }
  21.  
  22. float Item::GetWeight(){
  23.     Log(string("(float ")+Name+string("::GetWeight)>")+to_string(Weight));
  24.     return Weight;
  25. }
  26.  
  27. string Item::GetDescription(){
  28.     Log(string("(string ")+Name+string("::GetDescription)>")+Description);
  29.     return Description;
  30. }
  31. void Item::SetDescription(string Item_Name){
  32.     Log(string("(void ")+Name+string("::SetDescription)>")+Item_Name);
  33.     Description = Item_Name;
  34. }
  35.  
  36. void Item::SetName(string Item_Name){
  37.     Log(string("(void ")+Name+string("::SetName)>")+Item_Name);
  38.     Name=Item_Name;
  39. }
  40.  
  41. void Item::Add(Item item){
  42.     Log(string("(void ")+Name+string("::Add)>")+item.Name);
  43.     int found = Find(item.Name);
  44.         if(!found){
  45.             Names.push_back(item.Name);
  46.             Contents.push_back(item);
  47.             Weight = Weight + item.Weight;
  48.         }else{
  49.             Contents[found].Increment(found);
  50.         }
  51. }
  52.  
  53. void Item::Remove(Item item){
  54.     Log(string("void ")+Name+string("::Remove)>")+item.Name);
  55.     int found = Find(item.Name);
  56.     if(found){
  57.         if(found > 1){
  58.             Contents[found].Decrement(found);
  59.         }else{
  60.             vector<Item> tmplist;
  61.             for(int a=0;a<Contents.size();++a){
  62.                 if(Contents[a].Name != Contents[found].Name){
  63.                     tmplist.push_back(Contents[a]);
  64.                 }
  65.             }
  66.             Contents.clear();
  67.             for(int a=0;a<tmplist.size();++a){
  68.                     Contents.push_back(tmplist[a]);
  69.                 }
  70.             }
  71.         }
  72. }
  73.  
  74. int Item::Find(string Item_Name){
  75.     Log(string("(int ")+Name+string("::Find)>")+Item_Name);
  76.     int result=0;
  77.     for(int a=0;a < Contents.size();++a){
  78.         if(Contents[a].Name == Item_Name){
  79.             result = a;
  80.         }
  81.     }
  82.     return result;
  83. }
  84.  
  85. void Item::Increment(int index){
  86.     Log(string("(void ")+Name+string("::Increment)>")+to_string(index));
  87.     Contents[index].Quantity+1;
  88. }
  89. void Item::Decrement(int index){
  90.     Log(string("(void ")+Name+string("::Decrement)>")+to_string(index));
  91.     Contents[index].Quantity-1;
  92. }
  93.  
  94. void Item::Log(string str){
  95.     cout << str << endl;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement