This step is almost a trivial one. When we kill a monster, we want our score to increase by - let's say - 20 points.
So we do this in the collision notification method of the Monster class. However, the
score is an attribute of the player, and the Monster class does not have access to that variable. We might need access
to the player instance in many other situations, for example for increasing the amount of cluster bombs, for decreasing
the shields, for adding power-ups, whatever. So it's useful if we give other classes the ability to obtain a reference
to the player object. The most appropriate place to do this is to add a new method to the Stage class:
Stage.java
1 /**
2 * Curso B?sico de desarrollo de Juegos en Java - Invaders
3 *
4 * (c) 2004 Planetalia S.L. - Todos los derechos reservados. Prohibida su reproducci?n
5 *
6 * http://www.planetalia.com
7 *
8 */
9 package version22;
10
11 import java.awt.image.ImageObserver;
12
13 public interface Stage extends ImageObserver {
14 public static final int WIDTH=640;
15 public static final int HEIGHT=480;
16 public static final int PLAY_HEIGHT = 400;
17 public static final int SPEED=10;
18 public SpriteCache getSpriteCache();
19 public void addActor(Actor a);