To load this file without formatting, visit http://whoyouknow.co.uk/ants/java/17.0/src/ants/AntSimulator.java. This is a spam-protection measure; sorry for the inconvenience.
· AntSimulator.java ·
1/* 2 * AntSimulator.java 3 * 4 * Created on 07 October 2006, 01:43 5 * 6 * To change this template, choose Tools | Template Manager 7 * and open the template in the editor. 8 */ 9 10package ants; 11 12 13import ants.control.AntControl; 14import java.awt.BorderLayout; 15import java.awt.Dimension; 16import java.awt.event.ActionEvent; 17import java.awt.event.ActionListener; 18import java.awt.event.MouseAdapter; 19import java.awt.event.MouseEvent; 20import javax.swing.JApplet; 21import javax.swing.JButton; 22import javax.swing.JFrame; 23import javax.swing.JPanel; 24 25/** 26 * 27 * @author James Hamilton 28 */ 29public class AntSimulator extends JApplet { 30 31 private Grid grid; 32 33 /** Creates a new instance of AntSimulator */ 34 public AntSimulator(int size) { 35 36 initialise(); 37 38 int r = (int)(Math.random() * Math.sqrt(8)) * (int)(Math.random() *Math.sqrt(8)); 39 System.out.println(r); 40 41 42// JSlider sliderFoodStrength = new JSlider(); 43// panel.add(sliderFoodStrength, BorderLayout.WEST); 44// sliderFoodStrength.setValue(0); 45// sliderFoodStrength.addChangeListener( new ChangeListener() { 46// public void stateChanged(ChangeEvent e) { 47// JSlider source = (JSlider)e.getSource(); 48// if (!source.getValueIsAdjusting()) { 49// int value = (int)source.getValue(); 50// Grid.getInstance().resetFoodStrengths(); 51// 52// 53// System.out.println(value); 54// } 55// } 56// }); 57// 58 59 setVisible(true); 60 } 61 62 public void initialise() { 63 grid = Grid.getInstance(100); 64 grid.reset(); 65 setSize(getSize()); 66 67 getContentPane().remove(grid); 68 getContentPane().add(grid, BorderLayout.CENTER); 69// try { 70// System.out.println(Grid.getInstance().getGridSquare(1, 1).getDirectionOf(Grid.getInstance().getGridSquare(0,2))); 71// System.exit(0); 72// }catch (Exception e) { 73// 74// } 75 //grid.populate(100); 76 grid.getNest().addAnts(4); 77 78 grid.populateWithObstacles(0); 79 //grid.populateWithFood(5); 80 try { 81 grid.addFoodCluster(80, 20, 3);//7 82 grid.addObstacleCluster(50, 21, 4); 83 grid.addObstacleCluster(50, 22, 4); 84 grid.addObstacleCluster(50, 23, 4); 85 // grid.addFoodCluster(30, 80, 3); 86 }catch (Exception e) { 87 //no such grid square. 88 } 89 90 Grid.getInstance().resetFoodStrengths(); 91 92 try { 93 94 // System.out.println(Grid.getInstance().getGridSquare(0, 23).getGridSquares(1)); 95 96 } catch (Exception ex) { 97 ex.printStackTrace(); 98 } 99 } 100 101 public AntSimulator() { 102 this(100); 103 } 104 105 public Dimension getSize() { 106 return grid.getSize(); 107 } 108 109 public static void main(String[] args) { 110 java.awt.EventQueue.invokeLater(new Runnable() { 111 public void run() { 112 JFrame f = new JFrame("Ant Simulator"); 113 final AntSimulator m = new AntSimulator(100); 114 f.add(m); 115 f.setSize((int)m.getSize().getWidth() + 13, (int)m.getSize().getHeight() + 35); 116 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 117 f.setResizable(false); 118 f.setVisible(true); 119 120 AntControl.getInstance().setVisible(true); 121 ///new AntControl().setVisible(true); 122 } 123 }); 124 125 126 127 } 128} 129
· AntSimulator.java ends ·
To load this file without formatting, visit http://whoyouknow.co.uk/ants/java/17.0/src/ants/AntSimulator.java. This is a spam-protection measure; sorry for the inconvenience.