Introduction to OOP: Chapter 8: The Solitaire Game
[next]
[previous]
[audio]
[real]
[text]
The Game Class
public class Solitaire extends Applet {
static DeckPile deckPile;
static DiscardPile discardPile;
static TablePile tableau [ ];
static SuitPile suitPile [ ];
static CardPile allPiles [ ];
public void init() {
// first allocate the arrays
allPiles = new CardPile[13];
suitPile = new SuitPile[4];
tableau = new TablePile[7];
// then fill them in
allPiles[0] = deckPile = new DeckPile(335, 5);
allPiles[1] = discardPile = new DiscardPile(268, 5);
for (int i = 0; i < 4; i++)
allPiles[2+i] = suitPile[i] =
new SuitPile(15 + 60 * i, 5);
for (int i = 0; i < 7; i++)
allPiles[6+i] = tableau[i] =
new TablePile(5 + 55 * i, 80, i+1);
}
public void paint(Graphics g) {
for (int i = 0; i < 13; i++)
allPiles[i].display(g);
}
public boolean mouseDown(Event evt, int x, int y) {
for (int i = 0; i < 13; i++)
if (allPiles[i].includes(x, y)) {
allPiles[i].select(x, y);
repaint();
return true;
}
return true;
}
}
Intro OOP, Chapter 8, Slide 21
This applet uses Java 1.0.3. Note that the techniques used to respond to
events changed starting with Java 1.1. A more recent version of this
application can be found from the links found on the
first slide.