The Game Class

The class Solitaire is the main class for the application. This class inherits from the Java library class Applet, which is the root class for all applets.

Note the definition of the static variables at the head of the class description.

The method init initializes the various piles of cards. In addition to being assigned to their appropriate static class, they are also assigned in an array named allPiles. Notice how this variable simplifies the painting routine. To paint the table, we simply tell each pile of cards to paint itself.

You will recall, however, that the function display is overridden in various subclasses. Thus this loop will sometimes be invoking CardPile.display, other times TablePile.display.

A similar trick is being played in the mouse down routine. The includes and select methods are all overridden, nevertheless, when the look invokes the function, the appropriate method will be selected depending upon the type of the value being held in the array.

[audio] [real] Text to accompany slide21, in Chapter 8 of An Introduction to Object-Oriented Programming