Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Perhaps you're looking for a design to help you get started.<br> Since you said you're a beginner, I'll avoid polymorphism, templates, and all that other fluff.<br> Here's a very basic design:</p> <p>ItemProperty : Says what an item does and by how much. </p> <pre><code>struct ItemProperty { enum effectType { PLAYER_HP, PLAYER_MP, CURE_POISON, REVIVE, ERROR } ; ItemProperty (const effectType effect = ERROR, int magnitude = 0) ; private: int magnitude ; effectType effect ; }; ItemProperty::ItemProperty (const effectType effect, int magnitude) : effect (effect), magnitude (magnitude) { } </code></pre> <p><br> Item: The stuff you wanted in an item. </p> <pre><code>class Item { public: Item () ; Item (const std::string &amp;name, const std::string &amp;description, const ItemProperty &amp;itemProperty, const int buyValue, const int sellValue) ; private: std::string name ; std::string desciption ; ItemProperty itemProperty ; int buyValue ; int sellValue ; }; Item::Item () : buyValue (0), sellValue (0) { } Item::Item (const std::string &amp;name, const std::string &amp;description, const ItemProperty &amp;itemProperty, const int buyValue, const int sellValue) : name (name), desciption (description), itemProperty (itemProperty), buyValue (buyValue), sellValue (sellValue) { } </code></pre> <p><br> Main: Creating a potion </p> <pre><code>int main (void) { Item potion ("Potion", "Regain 50 HP", ItemProperty (ItemProperty::PLAYER_HP, 50), 50, 25) ; return 0 ; } </code></pre> <p>Once you have a better grasp on programming, you'll be able to figure out better designs than this. But for now, keep it simple.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload