JavaLib
 
WorldLib
 
draw
idraw
adraw
colors
 
Samples
 
Sources
Downloads
 
TSRJ Home
TSRJ Local

Functional Drawing Library: draw.jar

The draw package defines the abstract class World and the class Canvas. The programmer has to implement the methods onTick, onKeyEvent that produce the new World as it looks after the corresponding event. In addition, the programmer defines the draw method that uses the various draw... methods in the class Canvas to produce the scene that represents the user's World in theCanvas, defined in the World class.

The Javadocs for the draw library.

/**
 * World for programming interactive games - with graphics, key events,
 * and a timer. 
 */
abstract public class World{

  /** the canvas that displays the current world */
  protected Canvas theCanvas;

  /** The default constructor.  */
  public World(){ }

  /** Start the world by creating a canvas of the given size 
     *  and starting the timer at the given speed. */
  public boolean bigBang(int w, int h, double speed);

  /** End the world clock and key events: 
   * display the given message. */
  public boolean endOfTime(String s);

  /** End the world interactions: display the given message
   * produce the final version of the World. */
  public World endOfWorld(String s);

  /** Produces a new World as it should look after a clock tick. */
  abstract public World onTick();

  /** Produces a new World as it should look 
   * in response to the given key input. */
  abstract public World onKeyEvent(String s);

  /** Draw this world in 'theCanvas'. */
  abstract public boolean draw();
}

To run the game invoke its bigBang method from within one of the test cases in the Examples. Alternately, a standalone start of the world can be written as:

public static void main(String[] argv){
    // user defines the starting world
    World w = new MyWorld(...);                           
 
    // user supplies the world size and clock speed
    boolean go = w.bigBang(...width..., ...height..., ...speed...); 
}

Here is a complete code for a running program called BlobWorldFun.java


last updated on Fri Apr 1 14:26:43 EDT 2011generated with DrRacket