Java Reference
In-Depth Information
consumption.leave = true;
}
public void destroyApp (boolean forced) {
}
}
The consumption
Thread
is a separate class that monitors the power the
Javagochi
needs for
living. In the
run()
method, every 0.5 seconds the score is updated depending on the
Javagochi
's
happiness and the small amount of body mass that is transformed back to life energy:
public class Consumption extends Thread {
Javagochi javagochi;
boolean leave = false;
public Consumption (Javagochi javagochi) {
this.javagochi = javagochi;
}
public void run() {
while (!leave) {
try {
sleep (500);
}
catch (InterruptedException e) {break;}
javagochi.score += 10 - javagochi.deviation;
javagochi.transform (-5);
}
}
}
Now that you know how a
Javagochi
works, it is your job to give the
Javagochi
an appropriate
appearance by implementing the missing
Face
class.
Scaling and Fitting
In many cases, it is a good idea to scale displayed graphics depending on the actual screen size.
Otherwise, the display will look nice on one particular device type, but won't fit the screen on devices
with a lower screen resolution or become unnecessarily small on devices with higher screen resolutions.
We will now show how scaling works for the
Javagochi
example. A picture of a
Javagochi
is
shown in
Figure 3.19
.
You will start by drawing the shape of the face, a simple ellipse. In this case, the
ellipse will reflect the
Javagochi
's weight. If the
Javagochi
is at its ideal weight, the ellipse
becomes a circle.
Figure 3.19. A happy
Javagochi
at its ideal weight.
Search WWH ::
Custom Search