Vi. Timer, rewards and punishments and evaluation
We should add our timer. I want to start timing from the beginning of the game and constantly update it to the screen. After the game is over, the timer will stop working.
First, record the current time during initialization:
Gametime = 0;
Gametimeoffset = System. currentTimeMillis ();
In the future, as long as the game does not have gameover, the calculation will be performed once in each update cycle:
Gametime = (System. currentTimeMillis ()-gametimeoffset)/1000;
// Convert to seconds
The following is to display it. Do you still remember the font class we used to implement? This is useful. First, 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 '});
Then it is displayed:
Fontbig. drawString (String. valueOf (gametime), screenwidth/2-15, 10 );
It's really convenient, yeah!
Next is the reward system, which requires that a bomb be added to the player every 20 s.
Int awardindex = (int) gametime/20; // calculate the reward time
If (awardindex> bombawardtop)
Awardindex = bombawardtop;
If (bombaward [awardindex]! = 0) {// if there is no reward for this 20 s
Bombnum + = bombaward [awardindex];
Bombaward [awardindex] = 0; // rewarded
}
As simple as possible and give some tips is the principle I wrote this article, so the evaluation system is very ez.
We create a helper class that provides a method to input the game time and return a String comment.
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 are a game master ";
} Else if (gametime <16 ){
Return "come boy, you can do it! ";
} Else if (gametime <20 ){
Return "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 .";