/** * Written by Josh Lifton 31JUL2002. * Adapted from code written on 10MAY2000. * Copyright (c) Josh Lifton 2000-2002. * GUI for duelling flocks of boids. * */ import java.applet.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class BoidDuel extends Applet implements Runnable, ActionListener, AdjustmentListener, ComponentListener, WindowListener { private static final int SCROLLBARVISIBLE = (int) (0.2*Integer.MAX_VALUE); private static final int SCROLLBARMAX = Integer.MAX_VALUE - SCROLLBARVISIBLE; private static final Color TEAM1COLOR = Color.black; private static final Color TEAM2COLOR = Color.red; public Frame frame; private Thread thread; public boolean pauseFlag, replayFlag; public Flock flock; public Panel team1Panel, team2Panel, arenaPanel, controlPanel; private Button pauseButton, resetButton, random1Button, random2Button, replayButton; private Scrollbar turnAngle1, turnAngle2, acceleration1, acceleration2, sensorRange1, sensorRange2, collisionRange1, collisionRange2, attackConstant1, attackConstant2, retreatConstant1, retreatConstant2; private Label turnAngle1Label, turnAngle2Label, acceleration1Label, acceleration2Label, sensorRange1Label, sensorRange2Label, collisionRange1Label, collisionRange2Label, attackConstant1Label, attackConstant2Label, retreatConstant1Label, retreatConstant2Label, timeLabel, team1Label, team2Label; private int time = 0; public int width = 800; public int height = 600; private int boidsPerTeam = 30; private int numberOfTeams = 2; private int team1Wins = 0; private int team2Wins = 0; private String startString = "Start"; private String pauseString = "Pause"; private String resumeString = "Resume"; private Locale[] supportedLocales = {Locale.US, Locale.JAPAN}; private long seed; /** Method called when used as an application. */ public static void main(String args[]) { BoidDuel boidDuel = new BoidDuel(); boidDuel.frame = new Frame("Boid Duel"); boidDuel.init(); } public void init() { /* * Set random seed. */ setSeed(System.currentTimeMillis()); /* * Determine what language to use. */ String resourceBundleName = getClass().getName() + "RB"; Locale applicationLocale = supportedLocales[0]; for (int i=0; i