Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you want is an enum containing all your elements, with a couple of methods. Here is an example, feel free to use it if it suites your needs.<br/> If desired, you can also make a second enum for Type (as Templar suggested) and add it as a field in you Element enum.</p> <pre><code>import java.util.ArrayList; import java.util.Arrays; import java.util.List; public enum Element { //Example instances, replace with what is appropriate for your game. WATER, // Basic WOOD, // Basic IRON, // Basic STONE, // Basic FIRE, // Basic CARBON(WOOD, FIRE), //Intermediate FORGE(STONE, IRON), // Intermediate STEEL(FORGE, IRON); // Final private Element[] parts; private Element() { //instantiates parts to prevent NullPointerException this.parts = new Element[0]; } private Element(Element... parts) { this.parts = parts; } /** * return all the parts of this Element. * @return */ public List&lt;Element&gt; getParts() { return Arrays.asList(parts); } /** * find all elements that have this Element listed as one of their parts. * * @param part * @return */ public List&lt;Element&gt; getComposites() { List&lt;Element&gt; composites = new ArrayList&lt;Element&gt;(); // Iterate through all Elements for (Element composite : Element.values()) { // Iterate through each Element's parts for (Element part : composite.parts) { // If the element has a part equal to the argument, // Add the element to the list of composites. if (part == this) { composites.add(composite); } } } return composites; } } </code></pre>
    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.
    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