To load this file without formatting, visit http://whoyouknow.co.uk/ants/java/17.1/src/ants/FoodCluster.java. This is a spam-protection measure; sorry for the inconvenience.
· FoodCluster.java ·
1/* 2 * FoodCluster.java 3 * 4 * Created on 12 November 2006, 22:23 5 * 6 * To change this template, choose Tools | Template Manager 7 * and open the template in the editor. 8 */ 9 10package ants; 11 12import java.awt.Point; 13import java.util.Vector; 14 15/** 16 * 17 * @author James Hamilton 18 */ 19public class FoodCluster implements Runnable { 20 21 private int radius = 5; 22 private int x, y; 23 private Vector<GridSquare> gridSquares; 24 private int strengthRadius = 0; 25 26 private Thread move; 27 28 /** Creates a new instance of FoodCluster */ 29 public FoodCluster(int x, int y, int radius) { 30 this.setX(x); 31 this.setY(y); 32 this.radius = radius; 33 34 try { 35 gridSquares = Grid.getInstance().getGridSquare(x, y).getGridSquares(radius, true); 36 37 for(GridSquare gs : gridSquares) 38 gs.setFood(new Food(gs)); 39 40 }catch (Exception e) { 41 42 } 43 44 // move = new Thread(this); 45 // move.setDaemon(true); 46 // move.start(); 47 48 // recalculateStrengths(); 49 } 50 51 public void recalculateStrengths() { 52 recalculateStrengths(false); 53 } 54 55 public void recalculateStrengths(boolean reset) { 56 57 try { 58 Vector<GridSquare> gridSquares = Grid.getInstance().getGridSquare(x, y).getGridSquares(getRadius() + getStrengthRadius(), true); 59 60 for(GridSquare gs : gridSquares) { 61 // if(reset) gs.setFoodStrength(0); 62 Point p = gs.getCoordinateXY(); 63 64 double c2 = Math.pow(p.x - getX(), 2) + Math.pow(p.y - getY(), 2); 65 //System.out.println(Math.sqrt(c2)); 66 if(Math.sqrt(c2) <= 100)//getRadius() + getStrengthRadius()) 67 gs.setFoodStrength((1 / c2*300));//gs.getFoodStrength() + 68 } 69 }catch (Exception e) { 70 71 } 72 } 73 74 public void run() { 75 76 while(move != null) { 77 try { 78 79 recalculateStrengths(true); 80 81 move.sleep(1000); 82 }catch (InterruptedException e) {} 83 } 84 } 85 86 public int getRadius() { 87 return radius; 88 } 89 90 public void setRadius(int size) { 91 this.radius = size; 92 } 93 94 public int getX() { 95 return x; 96 } 97 98 public void setX(int x) { 99 this.x = x; 100 } 101 102 public int getY() { 103 return y; 104 } 105 106 public void setY(int y) { 107 this.y = y; 108 } 109 110 public int getStrengthRadius() { 111 112 return strengthRadius; 113 } 114 115 public void setStrengthRadius(int strengthRadius) { 116 recalculateStrengths(true); 117 // System.out.println("Setting strength raduis: " + strengthRadius); 118 this.strengthRadius = strengthRadius; 119 } 120 121 122} 123
· FoodCluster.java ends ·
To load this file without formatting, visit http://whoyouknow.co.uk/ants/java/17.1/src/ants/FoodCluster.java. This is a spam-protection measure; sorry for the inconvenience.