Organization
Organization of the library
The library consists of two sets of modules (packages). The first set defines the environment for the game and asks the programmer to design the actions of the game (and its display). The second set provides the support for the graphics and sound components of the games.
World Game Libraries
This collection of five libraries (together with the world-images library and optionally the tunes library) allows a novice programmer to model the behavior of an interactive graphics-based game where the game behavior changes in reponse to the key presses, mouse clicks, and as time elapses (monitored by the ticking clock). The programmer also designs the view of the game at each clock tick, or as it changes in response to the key and mouse events.
More advanced programmers will enjoy augmenting their game with sound effects and musical themes.
There are five versions of the worlds to support a gradual increase in the program complexity:
javalib.funworld package allows the programmer to define the world, the collection of objects that comprise the current state of the game and to define methods that represent the actions in response to a key press, a mouse click, or in response to the time tick. Each action produces a new <em>world</em>. One can think of it as producing a series of scenes for an animation. Because the whole environment is mutation-free, the testing of the methods that represent the actions is very straightforward.
javalib.impworld package converts all the action methods found in the javalib.funworld package into imperative style. Now every action method just changes the state of the game. In some ways the code is simpler, but the testing of the methods is more difficult.
javalib.appletworld package allows the programmer to turn their imperative game into an applet by just changing the library import statements and adding one simple class that defines the initial state of the game. We also provide a sample html code that can be used to publish the game on a web page.
javalib.soundworld package extends the javalib.impworld library by adding the support for generating MIDI sounds in response to the key presses and time events.
javalib.appletsoundworld package allows the programmer to turn their soundworld game into an applet by just changing the library import statements and adding one simple class that defines the initial state of the game, using the same technique as the one used by the javalib.appletworld
Images and Tunes
The programmer first selects which style of the game she wants to design. The program then needs to import additional libraries from those listed below:
javalib.worldimages package allows the programmer to compose geometric shapes (circles, disks, rectangles, and more) with .png images to represent the game objects and the entire game scene. It also includes the class Posn that represents a point on the canvas.
javalib.colors package allows the novice programmer to define the six basic colors as (new Red(), new Green(), new Blue(), new White(), new Black(), or new Yellow(). The package should be imported with the javalib.worldimages.
javalib.worldcanvas package contains the classes that build the needed frame with a Canvas that displays the game. There are two versions of the canvas, one for Java applications (WorldCanvas) and one for Java Applets (AppletCanvas). The programmer does not need to know anything about the implementation, just include the package in the imports.
javalib.tunes package contains the classes that allow the programmer to compose MIDI tune sequence and play the melody using the default MIDI synthesizer. The package provides a class TuneBucket that is used by the sound versions of the worlds to keep track of currently playing MIDI notes for all instruments in the current synthesizer program.