Thanks for the reply Regenuluz this is the path I ended up taking after a little more research.
For those looking to implement a similar system here is a test program called "Three Monkeys" that I made to get my head around the comparable method.
The program will generate 3 Monkey objects and place them in an ArayList, then randomly generate an initiative roll for each. The ArrayList is then re-ordered based on highest roll and each monkey takes it in turn to say what they have to say. Hope this helps someone.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| public class Monkeys implements Comparable{ public int initiative; int speed; String action; public Monkeys(String action) { super(); this.action = action; speed = 5; } public int genInit(int roll) { this.initiative = roll + speed; return this.initiative; }
public int compareTo(Object o) { Monkeys tmp = (Monkeys)o; if(this.initiative < tmp.initiative) { return -1; }else if(this.initiative > tmp.initiative) { return 1; }return 0; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| import java.util.ArrayList; import java.util.Collections; import java.util.Random;
public class MonkeyMagic { public static void main(String[] args) { ArrayList<Monkeys> m = new ArrayList(); m.add(new Monkeys("I am a bezerker monkey")); m.add(new Monkeys("I just wants the bananas")); m.add(new Monkeys("I am a lovely monkey")); Random rand = new Random(); for(Monkeys i: m) { int r = rand.nextInt(100); i.genInit(r); } Collections.sort(m); for(Monkeys i: m) { System.out.println(i.initiative + " " + i.action); try { Thread.sleep(1000); } catch (Exception e) {} } } } |