The implementation of props stacking in the backpack

Source: Internet
Author: User

Just enumerate the function steps of the pseudo-algorithm and leave it to think later.

Description of function Required:

// get the same type of items and the smallest number

Specific function actions:

BOOL Bagmanager::obtain (item* pitem) {    item// Get backpack similar item     if  ( Pitem)    // presence of the item              }    else    //  The item does not exist directly add    }    returnfalse;

Very intuitive and easy to deal with, there is only need to modify the item parameters can be, there is no item added to the new lattice inside. But there might be a lattice, and then there are the remaining, we can actually let else's disposal, such as:

 bool  bagmanager::obtain (item* Pitem) {   Item  * Ptempitem = Finditembysourceid (Pitem->getsourceid ()); //     get backpack similar items  if   (pitem) { //  The item exists   if  (pitem->getnum S () > 0  ) { //  direct add    false  ;}  

However, there is also a problem, adding pitem the remaining quantity after a stack, or the number of itself pitem is far more than the maximum number of a lattice stack, you need to do more judgment on the remaining processing

BOOLBagmanager::obtain (item*pitem) {Item* Ptempitem = Finditembysourceid (Pitem->getsourceid ());//get backpacks for similar items    if(pitem) {//the item exists            }    if(Pitem->getnums ()! =0&& pitem->getnums () > Pitem->getlimitstacknums ()) { //the number of remaining items is still greater than the maximum number of stacks in a grid   }    if(Pitem->getnums () >0)    { //Remaining quantity Append    }        return false;}

The implementation of props stacking in the backpack

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.