can someone till what this function does void transferItem(itemType oldList[], itemType newList[], itemType item) { addItem(oldList, item, false); addItem(newList, item, true); }
You have a class, itemType. You also have a method in some class, addItem() that takes three parameters, two itemType arrays and a bool. In the first line you appear to be passing your objects and the item will NOT be added to the list, however in the second call the item WILL.
@eSpeX what about this function void sortItems(itemType itemList[]) { int i, last; itemType temp; for(last=MAX_ITEMS-1;last>=0;last--) { for(i=0;i<=last-1;i++) { if(itemList[i]>itemList[i+1]) { temp=itemList[i]; itemList[i]=itemList[i+1]; itemList[i+1]=temp; } } } }
That is a simple bubble sort for your itemList.
@eSpex is this just a simple switch statement void printItem(itemType item, bool printDesc) { switch(item) { case NUTS: cout<<"a handful of NUTS"; if(printDesc) cout<<" (Food: Health +1)"; break; case FRUIT: cout<<"a tropical FRUIT"; if(printDesc) cout<<" (Food: Health +2)"; break; case FIELD_RATIONS: cout<<"a package of field RATIONS"; if(printDesc) cout<<" (Food: Health +3)"; break; case FITNESS_MANUAL: cout<<"a FITNESS manual"; if(printDesc) cout<<" (Strength +1)"; break; case SWORD: cout<<"a jewel-encrusted SWORD"; if(printDesc) cout<<" (Strength +2)"; break; case GLOVES: cout<<"a pair of golden GLOVES"; if(printDesc) cout<<" (Strength +3, Endurance -1, Cunning -1)"; break; case CONDITIONING_MANUAL: cout<<"a CONDITIONING manual"; if(printDesc) cout<<" (Endurance +1)"; break; case SHIELD: cout<<"a mirror-coated SHIELD"; if(printDesc) cout<<" (Endurance +2)"; break; case BOOTS: cout<<"a pair of winged BOOTS"; if(printDesc) cout<<" (Strength -1, Endurance +3, Cunning -1)"; break; case SURVIVAL_MANUAL: cout<<"a SURVIVAL manual"; if(printDesc) cout<<" (Cunning +1)"; break; case RUBIKS_CUBE: cout<<"a floating Rubik's CUBE"; if(printDesc) cout<<" (Cunning +2)"; break; case HAT: cout<<"a safari HAT"; if(printDesc) cout<<" (Strength -1, Endurance -1, Cunning +3)"; break; case TEMP_ITEM: cout<<"a TEMPorary item"; //if(printDesc) //cout<<" a temporary item"; break; default: break; } }
Yes. It seems if it has a printDesc flag set then it also prints out the extra attributes.
@eSpeX i do not get this one itemType parseItem(string itemStr) { itemType item; if(itemStr=="NUTS") item=NUTS; else if(itemStr=="FRUIT") item=FRUIT; else if(itemStr=="RATIONS") item=FIELD_RATIONS; else if(itemStr=="FITNESS") item=FITNESS_MANUAL; else if(itemStr=="SWORD") item=SWORD; else if(itemStr=="GLOVES") item=GLOVES; else if(itemStr=="CONDITIONING") item=CONDITIONING_MANUAL; else if(itemStr=="SHIELD") item=SHIELD; else if(itemStr=="BOOTS") item=BOOTS; else if(itemStr=="SURVIVAL") item=SURVIVAL_MANUAL; else if(itemStr=="CUBE") item=RUBIKS_CUBE; else if(itemStr=="HAT") item=HAT; else if(itemStr=="TEMP") item=TEMP_ITEM; else //if(itemStr=="") // Delete the "if()". For ANY other case, item = NO_ITEM item=NO_ITEM; return item; }
The method takes a string, the name of an item, and returns that item.
In the beginning of the function you see it creates an itemType item, then depending on the value of the string passed in it will set the item to that specific type and return it to the calling function.
@eSpeX what about this one bool hasItem(itemType itemList[], itemType item) { bool found=false; int i=0; while(i<MAX_ITEMS and not found) { if(itemList[i]==item) found=true; i++; } return found; }
That one searches an array to see if a specific item is in the array.
@eSpeX what about this one int countItems(itemType itemList[]) { int i=0; while(itemList[i]!=NO_ITEM and MAX_ITEMS>i) { i++; } return i; }
This just gives the amount of items in the list. For example if this were for an inventory, it would tell you how many items you were carrying.
@eSpeX what about this one void addItem(itemType itemList[], itemType item, bool shouldAdd) { bool flag=true; // Please pick a more meaningful name for this variable int i; if(shouldAdd) { // Remove this /////////////// i=0; // while(i<MAX_ITEMS and flag) // { // if(itemList[i]==NO_ITEM) // { // itemList[i]=item; // flag=false; // } // i++; // } // ////////////////////////////// // Just put the item in itemList[MAX_ITEMS - 1] } else { i=0; while(i<MAX_ITEMS and flag) { if(itemList[i]==item) { itemList[i]=NO_ITEM; flag=false; } i++; } } sortItems(itemList); }
This function takes an item array, and item, and a boolean, if the bool passed is true then the function looks for an empty spot and places the item into the array. If the bool is false then the array is searched until a matching item is found, then the item is removed from the array.
@eSpeX ok thanks for your help i was working on a game for my c++ class and my group finished i just wanted to make sure what these functions did
You're welcome.
Join our real-time social learning platform and learn together with your friends!