Which is the best idea?

Hi,
In my game I am making their are these things call item windows. At the moment you call the game class to add an item to the window. Like so

1
2
3
4
5
6
7
8
9
10
11
    case 11: /* Send item to window*/
    {
        u16 itemId;
        u32 itemQuantity;
        fillInStream(6);
        itemId = inStream->readUShort();
        itemQuantity = inStream->readUInt();
        game->addItem(itemId, itemQuantity, INVENTORY_WINDOW);

    }
    break;


1
2
3
4
5
6
7
8
9
10
11
void Game::addItem(u16 itemId, u16 quantity, WINDOW_TYPE window)
{
    if (window == INVENTORY_WINDOW)
    {
        inventoryWindow->getItemWindow()->addItem(itemId, quantity);
    }
    else
    {
        guienv->addMessageBox(L"Server Error", L"The server attempted to send an item to an invalid window.");
    }
}


Now my question is would it be a better idea to have all windows extend a Window class and this window class has a virtual void called addItem. Not all windows are going to be able to add items to them so I suppose my original idea was better. Or maybe a better idea again would be to have a window class and then a getTypes function and it will return a char explaining what the object is capable of doing.

That way you could just do something bitwize like this

 
  this->setTypes(HOLDS_ITEMS | HOLDS_MESSAGES);


Any feedback please? Share your ideas if you wish
Last edited on
Topic archived. No new replies allowed.