J2ME 2D Small Game entry (vi) Timers and rewards and punishments and evaluations

Source: Internet
Author: User
Evaluation six, timer and rewards and punishments and evaluation

It's time for us to join our timer, and I'm going to start timing from the beginning of the game and keep updating to the screen, and the timer stops working after the game is over.



First, the current moment is recorded at the time of initialization:

gametime=0;

Gametimeoffset=system.currenttimemillis ();



In the future, as long as the game does not gameover in each update cycle are calculated:

Gametime= (System.currenttimemillis ()-gametimeoffset)/1000;

Convert to Seconds



The next thing to do is to show it, remember we have implemented the font class, this is useful, first of all, instantiate 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 '};

And then there's the display:

Fontbig.drawstring (String.valueof (gametime), screenwidth/2-15,10);

It's really convenient yeah!.





Then there is the reward system, which we require to add a bomb to the player every 20s.

int awardindex= (int) gametime/20;//Calculation award Time

if (awardindex>bombawardtop)

Awardindex=bombawardtop;

if (bombaward[awardindex]!=0) {//If this 20s is not rewarded

Bombnum+=bombaward[awardindex];

bombaward[awardindex]=0;//rewarded.

}



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

We create a helper class that provides a way to enter the game time and return a string comment.

public class Stringtools {

Protected Stringtools () {

}



public static String timeopinion (long gametime) {

if (gametime<10) {

Return "does you have with your foot";

Return "I can ' t belive,your are a game master";

}else if (gametime<16) {

Return "Come boy, can do it!";

}else if (gametime<20) {

Return "What a pity! Try again. ";

}else if (gametime<25) {

Return "Very OK, you are a real man."

}else if (gametime<30) {

Return "I know your have talent of this game."

}else if (gametime<40) {

Return "I can ' t belive, your are a game master";

}else{

Return "Oh I God, are you a human";

}

}

}

Then it shows up, I don't have the right size font picture on hand, I use it directly

g.DrawString (Stringtools.timeopinion (gametime), 5,22,g.left|g.top);

Want to be in the small screen of mobile phone so that things are very difficult, in fact, this is my mobile phone to play the game is not interested, but I am full of confidence in mobile phone network applications.






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.