Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What I don't like in this solution :</p> <ul> <li>Simple solutions is best solutions</li> <li>Difficult to maintain since your xml is based on a graph.</li> <li>Don't really take advantage of OOP</li> <li>Source of bugs</li> <li>Probable use of <code>Reflection</code> for small problems (I say small because if your do a such game you'll face far more difficults problems ;) ). This implies unnecessary complexity.</li> </ul> <p>What I like in this solution :</p> <ul> <li>You have just perfectly understood the problem. Each item have a list of transormations with some other objects. Now the problem is how to <strong>represent</strong> (and not store) it</li> </ul> <p>What i would have do (juste IMHO, your solution is good, too) : use OOP in a node-only point of view. So your tree will become a <strong>state machine</strong> (as you were speaking about path ;) ) if you want to attach that to a data structure. </p> <pre><code>public class InventoryObject { protected Dictionnary&lt;Type, InventoryObject&gt; _combinations = new Dictionnary&lt;Type, InventoryObject&gt;(); public InventoryObject() {} public InventoryObject Combine(InventoryObject o) { foreach (var c in _combinations) if (typeof(o) == c.Key) return c.Value throw new Exception("These objects aren't combinable"); } } public class BlueHerb : InventoryObject { public Herb() { _combinations.Add(RedHerb, new BlueRedHerb()); _combinations.Add(GreenHerb, new BlueGreenHerb()); } } public class BlueRedHerb: InventoryObject { public BlueRedHerb() { _combinations.Add(GreenHerb, new GreyHerb()); } } </code></pre> <p>Then just call <code>BlueHerb.Combine(myRedHerb);</code> to get the result. You can also do <code>BlueHerb.Combine(myStone);</code> and easily debug.</p> <p>I try to keep my example as simple as possible. A lot of modifications can be done in order to light up the code (a class <code>Herb</code>, a class <code>CombinedHerb</code>, use LINQ queries, etc...) </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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