六、计时器和奖惩与评价 
    我们该加入我们的计时器了,我要从游戏开始时刻开始计时,并不断的更新到屏幕上,在游戏结束后计时器要停止工作。 
  
首先在初始化的时候将当前时刻记录下来: 
gametime=0; 
gametimeoffset=System.currentTimeMillis(); 
  
以后只要游戏不gameover就在每个更新周期都进行一次计算: 
    gametime=(System.currentTimeMillis()-gametimeoffset)/1000; 
//转换为秒 
  
下面要做的就是将它显示出来,还记得我们曾经实现的字体类了吗,这下子有用了,首先是实例化一个字体类: 
    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'}); 
然后就是显示: 
fontbig.drawString(String.valueOf(gametime),screenwidth/2-15,10); 
还真是方便yeah! 
  
  
接着是奖励系统,我们规定每过20s就加一个bomb给玩家。 
int awardindex=(int)gametime/20;//计算奖励时间 
    if(awardindex>bombawardtop) 
      awardindex=bombawardtop; 
    if(bombaward[awardindex]!=0){//如果本20s没有奖励 
      bombnum+=bombaward[awardindex]; 
      bombaward[awardindex]=0;//奖励过了 
} 
  
尽可能简单和给出些提示是我写本文的原则, 所以评价系统,很ez。 
我们建立一个辅助类,提供一个方法,输入游戏时间,返回一个String评语。 
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."; 
    }else if(gametime<40){ 
      return "i can't belive, your are a game master."; 
    }else{ 
      return "oh my god, are you a human?"; 
    } 
  } 
} 
之后显示出来就好了,我手头没有合适大小的字体图片,我直接使用 
g.drawString(StringTools.timeOpinion(gametime),5,22,g.LEFT|g.TOP); 
想在手机小小的屏幕容下那么东西是挺费劲的,其实这也是我对手机上玩游戏没什么兴趣,不过我对手机网络应用冲满了信心。 
   
 
  |