To load this file without formatting, visit http://whoyouknow.co.uk/ants/AntGraph/java/3/src/antgraph/Nest.java. This is a spam-protection measure; sorry for the inconvenience.
· Nest.java ·
1/* 2 * Nest.java 3 * 4 * Created on 13 October 2006, 22:47 5 * 6 * To change this template, choose Tools | Template Manager 7 * and open the template in the editor. 8 */ 9 10package antgraph; 11 12 13import java.awt.Color; 14import java.util.List; 15import java.util.Vector; 16 17/** 18 * 19 * @author James Hamilton 20 */ 21public class Nest implements Runnable { 22 23 private Vector<Ant> ants = new Vector<Ant>(); 24 private Vector<Food> food = new Vector<Food>(); 25 private Node node; 26 private int totalAnts = 0; 27 28 private Thread move; 29 30 public Nest(Node node) { 31 node.setNest(this); 32 move = new Thread(this); 33 move.setDaemon(true); 34 move.start(); 35 } 36 37 public Nest(Node node, int n) { 38 this(node); 39 addAnts(n); 40 } 41 42 public void addAnt() { 43 Ant ant = new Ant(node); 44 ants.add(ant); 45 46 totalAnts++; 47 } 48 49 public void addAnts(int n) { 50 for(int i = 0; i < n; i++) 51 addAnt(); 52 } 53 54 public void releaseAnt() { 55 if(ants.size() != 0) { 56 // System.out.println("Releasing Ant.."); 57 58 Ant ant = ants.remove(0); 59 60 ant.start(); 61 62 63 } 64 } 65 66 public void addAnt(Ant ant) { 67 food.add(ant.getFood()); 68 ant.setFood(null); 69 ants.add(ant); 70 System.out.println("ANT Returned to NEST"); 71 ant.stop(); 72 } 73 74 public void run() { 75 76 while(move != null) { 77 try { 78 79 releaseAnt(); 80 // System.out.println(ants.size() + " ants in nest"); 81 move.sleep((int)(1000 * Math.random()) + 1); 82 }catch (InterruptedException e) {} 83 } 84 } 85 86 87 public List<Ant> getAnts() { 88 return ants; 89 90 } 91 92 public Color getColor() { 93 return Color.LIGHT_GRAY; 94 } 95 96 public String toString() { 97 return "Nest"; 98 } 99 100 public int getTotalAnts() { 101 return totalAnts; 102 } 103} 104
· Nest.java ends ·
To load this file without formatting, visit http://whoyouknow.co.uk/ants/AntGraph/java/3/src/antgraph/Nest.java. This is a spam-protection measure; sorry for the inconvenience.