J2ME 2D Game Getting Started (6) Timer and Awards and Punishment and Evaluation

xiaoxiao2021-03-06  117

6. Timer and rewards and punishments and evaluation

We should join our timer, I want to start timing from the game start time, and constantly update to the screen, stop working at the time of the game.

First recording the current time when initialization:

Gametime = 0;

GametimeOffset = system.currenttimemillis ();

Whenever the game does not GameOver is performed at each update cycle:

Gametime = (System.currentTimeMillis () - GametimeOffset / 1000;

// Convert to second

The following is to display it, remember the font class we have implemented, this is useful, first is instantified a font class:

IMG = imageTools.getimage ("/ pic / b_number.png");

Fontbig = New font (g, IMG, 10, 15,

New char [] {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'});

Then it is displayed:

Fontbig.drawstring (String.Valueof (Gametime), ScreenWidth / 2-15, 10);

It is really convenient for Yeah!

Then the reward system, we stipulate that it will add a Bomb to the player every 20s.

INT awardIndex = (int) gametime / 20; // calculate the reward time

IF (AwardIndex> BombaWardtop)

AwardIndex = BombaWardTop;

IF (Bombaward [AwardIndex]! = 0) {// If this 20s has no reward

Bombnum = Bombaward [AwardIndex];

Bombaward [AwardIndex] = 0; // Reward

}

As simple as possible and give some prompts is the principle I write this article, so the evaluation system, very ez.

We create a secondary class, provide a method, enter the game time, return a string review.

Public class stringtools {

protected stringtools () {

}

Public Static String Timeopinion (long gametime) {

IF (Gametime <10) {

Return "Do you play with your foot?";

// Return "I can't Belive, Your A Game Master";

} else IF (Gametime <16) {

Return "Come Boy, You Can do it!";

Else IF (Gametime <20) {

"." what a pity! try again. "

Else IF (Gametime <25) {

Return "Very Well, You Are A Real Man.";

} else IF (Gametime <30) {

Return "I know you have talent of this game";

} Else IF (Gametime <40) {

Return "I can't Belive, Your Are A Game Master."

} else {

RETURN "OH my god, are you a human?";

}

}

It's okay to show it, I don't have the right size font picture in hand, I use it directly.

g.drawstring (StringTools.Timeopinion (Gametime), 5, 22, G.LEFT | G.TOP);

If you want to be very hard, it is quite hard, in fact, this is also a place to play games on your mobile phone, but I am full of confidence in mobile phone network applications.

转载请注明原文地址:https://www.9cbs.com/read-98261.html

New Post(0)