funworld
Class World

java.lang.Object
  extended by funworld.World

public abstract class World
extends java.lang.Object

World for programming interactive games - with graphics, key events, mouse events and a timer. Designed to implement the same interface as DrScheme/ProfessorJ world teachpack library.

Since:
November 15 2007, March 17 2008, October 19 2009, February 4 2012
Author:
Viera K. Proulx

Field Summary
 WorldEnd lastWorld
          the last world - if needed
 Canvas theCanvas
          the canvas that displays the current world
 
Constructor Summary
World()
          The default constructor.
 
Method Summary
 boolean bigBang(int w, int h)
          Start the world by creating a canvas of the given size, creating and adding the key and mouse adapters, without running the the timer.
 boolean bigBang(int w, int h, double speed)
          Start the world by creating a canvas of the given size, creating and adding the key and mouse adapters, and starting the timer at the given speed.
 World endOfWorld(java.lang.String s)
          End the world interactions - leave the canvas open, show the image of the last world with the given message
 WorldImage lastImage(java.lang.String s)
          User defined method to draw the World.
abstract  WorldImage makeImage()
          User defined method to draw the World.
 World onKeyEvent(java.lang.String s)
          User defined method to be invoked by the key adapter on selected key events.
 World onMouseClicked(geometry.Posn mouse)
          User defined method to be invoked by the mouse adapter when a mouse is clicked.
 World onMouseEntered(geometry.Posn mouse)
          User defined method to be invoked by the mouse adapter when a mouse is entered.
 World onMouseExited(geometry.Posn mouse)
          User defined method to be invoked by the mouse adapter when a mouse is exited.
 World onMousePressed(geometry.Posn mouse)
          User defined method to be invoked by the mouse adapter when a mouse is pressed.
 World onMouseReleased(geometry.Posn mouse)
          User defined method to be invoked by the mouse adapter when a mouse is released.
 World onTick()
          User defined method to be invoked by the timer on each tick.
 WorldEnd worldEnds()
          This method is invoked at each tick.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theCanvas

public Canvas theCanvas
the canvas that displays the current world


lastWorld

public WorldEnd lastWorld
the last world - if needed

Constructor Detail

World

public World()
The default constructor. To start the world one must invoke the bigBang method.

Method Detail

bigBang

public boolean bigBang(int w,
                       int h,
                       double speed)
Start the world by creating a canvas of the given size, creating and adding the key and mouse adapters, and starting the timer at the given speed.

Parameters:
w - the width of the Canvas
h - the height of the Canvas
speed - the speed at which the clock runs
Returns:
true

bigBang

public boolean bigBang(int w,
                       int h)
Start the world by creating a canvas of the given size, creating and adding the key and mouse adapters, without running the the timer.

Parameters:
w - the width of the Canvas
h - the height of the Canvas
Returns:
true

worldEnds

public WorldEnd worldEnds()

This method is invoked at each tick. It checks if the world should end now.

The saved image will be shown when the world ends, otherwise it is ignored.

Returns:
pair (true, last image) or (false, any image)

endOfWorld

public World endOfWorld(java.lang.String s)
End the world interactions - leave the canvas open, show the image of the last world with the given message

Parameters:
s - the message to display
Returns:
this world

onTick

public World onTick()

User defined method to be invoked by the timer on each tick. Produces a new World.

Override this method in the game world class

Returns:
World that needs to have the canvas and the event handlers initialized

onKeyEvent

public World onKeyEvent(java.lang.String s)

User defined method to be invoked by the key adapter on selected key events. Produces a new World.

Override this method in the game world class

Returns:
World that needs to have the canvas and the event handlers initialized

onMouseClicked

public World onMouseClicked(geometry.Posn mouse)

User defined method to be invoked by the mouse adapter when a mouse is clicked. Update the World.

Override this method in the game world class

Parameters:
mouse - the location of the mouse when clicked
Returns:
World after the mouse event

onMouseEntered

public World onMouseEntered(geometry.Posn mouse)

User defined method to be invoked by the mouse adapter when a mouse is entered. Update the World.

Override this method in the game world class

Parameters:
mouse - the location of the mouse when entered
Returns:
World after the mouse event

onMouseExited

public World onMouseExited(geometry.Posn mouse)

User defined method to be invoked by the mouse adapter when a mouse is exited. Update the World.

Override this method in the game world class

Parameters:
mouse - the location of the mouse when exited
Returns:
World after the mouse event

onMousePressed

public World onMousePressed(geometry.Posn mouse)

User defined method to be invoked by the mouse adapter when a mouse is pressed. Update the World.

Override this method in the game world class

Parameters:
mouse - the location of the mouse when pressed
Returns:
World after the mouse event

onMouseReleased

public World onMouseReleased(geometry.Posn mouse)

User defined method to be invoked by the mouse adapter when a mouse is released. Update the World.

Override this method in the game world class

Parameters:
mouse - the location of the mouse when released
Returns:
World after the mouse event

makeImage

public abstract WorldImage makeImage()

User defined method to draw the World.

Override this method in the game world class

Returns:
the image that represents this world at this moment

lastImage

public WorldImage lastImage(java.lang.String s)

User defined method to draw the World.

Override this method in the game world class

Returns:
the image that represents the last world to be drawn