// Class: SimpleMBSDemo1 // // Author: Alyce Brady, Joel Booth // // This class is based on the College Board's SimpleMBSDemo1 class, as // allowed by the GNU General Public License. The original SimpleMBSDemo1 // is a component class within the AP(r) CS Marine Biology Simulation // case study (see // http://www.collegeboard.com/student/testing/ap/compsci_a/case.html). // // License Information: // This class is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation. // // This class is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. package edu.kzoo.mbsInAGrid; import java.awt.Color; import edu.kzoo.grid.BoundedGrid; import edu.kzoo.grid.Direction; import edu.kzoo.grid.Location; import edu.kzoo.grid.display.DisplayMap; import edu.kzoo.grid.display.ScaledImageDisplay; import edu.kzoo.grid.display.RotatedDecorator; import edu.kzoo.grid.display.ScaledImageTintDecorator; import edu.kzoo.grid.gui.GridAppFrame; /** * Grid Container Package Examples:
* * The SimpleMBSDemo1 class provides a main method that creates * a simulation of a number of fish swimming in a bounded environment. * It also creates a simple window in which to view the environment * after each timestep in the simulation. Unlike the full version of * the simulation program, SimpleMBSDemo1 does not use an object * of the Simulation class. * *

* This SimpleMBSDemo1 class is based on the College Board's * SimpleMBSDemo1 class, as allowed by the GNU General * Public License. * * @author Alyce Brady * @author Joel Booth (changes made to use decorators) * @version 23 August 2004 **/ public class SimpleMBSDemo1 { // Specify number of rows and columns in environment. private static final int ENV_ROWS = 10; // rows in environment private static final int ENV_COLS = 10; // columns in environment // Specify attributes of the grid display. private static final int MAX_WIDTH = 300; private static final int MAX_HEIGHT = 300; private static final int MIN_CELL_SIZE = 20; private static final Color BACKGROUND_COLOR = Color.BLUE; // Specify how many timesteps to run the simulation. private static final int NUM_STEPS = 25; // number of timesteps /** Start the Marine Biology Simulation program. * The String arguments (args) are not used in this application. **/ public static void main(String[] args) { // Construct an empty environment (represented as a grid) and // several fish in the context of that environment. BoundedGrid env = new BoundedGrid(ENV_ROWS, ENV_COLS); GridFish f1 = new GridFish(env, new Location(2, 2)); GridFish f2 = new GridFish(env, new Location(2, 3)); GridFish f3 = new GridFish(env, new Location(5, 8)); // Construct a window to display an environment as a grid // and specify how to display a fish. GridAppFrame display = new GridAppFrame(); display.includeSpeedSlider(); display.constructWindowContents("Marine Biology Simulation Demo 1", BACKGROUND_COLOR, MAX_WIDTH, MAX_HEIGHT, MIN_CELL_SIZE); display.setGrid(env); // Create a ScaledImageDisplay that uses a RotatedDecorator as // well as a ScaledImageTintDecorator to associate with a GridFish. ScaledImageDisplay imageDisplay = new ScaledImageDisplay("smallfish.gif"); imageDisplay.addDecorator(new RotatedDecorator(Direction.EAST)); imageDisplay.addDecorator(new ScaledImageTintDecorator()); DisplayMap.associate("edu.kzoo.mbsInAGrid.GridFish", imageDisplay); // Run the simulation for the specified number of steps. for ( int i = 0; i < NUM_STEPS; i++ ) { f1.act(); f2.act(); f3.act(); display.showGrid(); } } }