Thread: Problems with cin and GetAsyncKeyState

  1. #31
    Registered User
    Join Date
    Aug 2008
    Posts
    30
    Lemme see if I got the code correctly.

    The class baseobject is like a class for all the types of items that the player can carry in his/her inventory. virtual void Describe would have the description of the item. virtual bool isWeapon() determines if the item is a weapon and is false by default.

    The class weapon is like a class for the weapon type of item. isWeapon() would be true because it is a weapon.

    Parts I don't get :
    What is shortDesc and longDesc supposed to mean?
    useWeaponOn means equip or don't equip? or does it mean something else?
    No idea whats a virtual data type yet =(

  2. #32
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by KgNe View Post
    Lemme see if I got the code correctly.

    The class baseobject is like a class for all the types of items that the player can carry in his/her inventory. virtual void Describe would have the description of the item. virtual bool isWeapon() determines if the item is a weapon and is false by default.

    The class weapon is like a class for the weapon type of item. isWeapon() would be true because it is a weapon.
    Yup, that's pretty much it. Although, my thoughts was that baseobject:escribe would do something like this, which hopefully answers your question below as well:
    Code:
    void baseobject::Describe(bool brief)
    {
       if (brief) cout << shortDesc;
       else cout << longDesc << endl;
    }
    Parts I don't get :
    What is shortDesc and longDesc supposed to mean?
    useWeaponOn means equip or don't equip? or does it mean something else?
    No idea whats a virtual data type yet =(
    Let's start with virtual - it essentialy means "use the object itself to find the function". Without virtual, the compiler uses the object-type of the current variable to find the function. With virtual, the object holds a pointer to the function [usually in the form of a vtable to be precise]. The purpose of this is that we can then use a baseobject pointer to hold an object [e.g. a vector of baseobject pointers], but the list could hold weapons and other derived objects that have different properties.

    So, for example:
    Code:
    vector<baseobject> stuff;
    baseobject *pillow = new baseobject("pillow", "A soft pillow - it looks so comfortable that you may want to rest your head on it right now");
    weapon *axe = new weapon("axe", "A very sharp looking axe", 0.5);
    
    stuff.push_back(pillow);
    stuff.push_back(axe);
    
    ... 
    for(int i = 0; i < stuff.Size(); i++)
    {
       if (stuff[i]->isWeapon()) {
          cout << "You can use ";
          stuff[i]->Describe(true);
          cout << "as a weapon";
       }
    }
    For the above to work, we obviously need isWeapon to be called on the weapon class for axe to be recognized as a weapon.

    My idea of "useWeaponOn" was more like when you say "Fight monster with axe", it would do "axe->useWeaponOn(monster)".

    I think the description stuff is clarified by the examples.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #33
    Registered User
    Join Date
    Aug 2008
    Posts
    30
    Ahh OK I can roughly get it. Read up on the whole Cprogramming.com tutorial before continuing would be a good idea?

Popular pages Recent additions subscribe to a feed