To load this file without formatting, visit http://whoyouknow.co.uk/ants/java/17.1/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        setVisible(true);
  43    }
  44    
  45    public void initialise() {
  46        grid = Grid.getInstance(100);
  47        grid.reset();
  48        setSize(getSize());  
  49
  50        getContentPane().remove(grid);
  51        getContentPane().add(grid, BorderLayout.CENTER);
  52
  53        grid.getNest().addAnts(8);
  54        
  55        grid.populateWithObstacles(0);
  56        //grid.populateWithFood(5);
  57        try {
  58            grid.addFoodCluster(80, 20, 3);//7
  59           grid.addObstacleCluster(50, 21, 4);
  60            grid.addObstacleCluster(50, 22, 4);
  61           grid.addObstacleCluster(50, 23, 4);
  62          //  grid.addFoodCluster(30, 80, 3);
  63        }catch (Exception e) {
  64            //no such grid square.
  65        }
  66        
  67        Grid.getInstance().resetFoodStrengths();
  68        
  69    }
  70    
  71    public AntSimulator() {
  72        this(100);
  73    }
  74    
  75    public Dimension getSize() {
  76        return grid.getSize();
  77    }
  78    
  79    public static void main(String[] args) {
  80        java.awt.EventQueue.invokeLater(new Runnable() {
  81            public void run() {
  82                JFrame f = new JFrame("Ant Simulator");
  83                final AntSimulator m = new AntSimulator(100);
  84                f.add(m);
  85                f.setSize((int)m.getSize().getWidth() + 13, (int)m.getSize().getHeight() + 35);
  86                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  87                f.setResizable(false);
  88                f.setVisible(true);
  89
  90                AntControl.getInstance().setVisible(true);
  91            }
  92        });
  93          
  94        
  95        
  96    }   
  97}
  98

· AntSimulator.java ends ·

Generated by CHIP: Code Highlighting in PHP, version 2.7.0.