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

Imperative Drawing Library: idraw.jar

The idraw is an imperative version of the World libraries. The programmer has to implement the methods onTick, onKeyEvent that change the state of the World in response to 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 idraw 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. 
   * To start the world one must invoke the bigBang method. */
  public World(){ }

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

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

  /** End the world interactions: display the given message. */
  public void endOfWorld(String s);

  /** Change the World to what it should look like after a clock tick. */
  abstract public void onTick();

  /** Change the World to what it should look like
   * in response to the given key input. */
  abstract public void onKeyEvent(String s);

  /** Draw this world in 'theCanvas'. */
  abstract public void 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
    w.bigBang(...width..., ...height..., ...speed...); 
}

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


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