eptione){
e.printStackTrace();
}
if(!pause){
if(moveOn()){
gs.repaint();
}
else{
JOptionPane.showMessageDialog(null,"sorrymyboy,GAMEOVER!","message",JOptionPane.INFORMATION_MESSAGE);
running=false;
}
}
}
/*booleanrunning=true;
while(running){
try{
Thread.sleep(interval);
}
catch(InterruptedExceptione){
e.printStackTrace();
}
if(!pause){
if(moveOn()){
gs.repaint();
}
else{
JOptionPane.showMessageDialog(null,"iamsorry,youfailed!","message",JOptionPane.INFORMATION_MESSAGE);
break;
}
}
}//endwhile
running=false;//当且仅当失败退出的时候;
*/
}
//获取当前游戏得分
publicintgetScore(){
returnthis.score;
}
//加速
publicvoidspeedUp(){
interval*=speedRate;
}
//减速
publicvoidspeedDown(){
interval/=speedRate;
}
//设置暂停
publicvoidchagePause(){
pause=!pause;
}
//设置方向
publicvoidchageDirection(intnewdirection){
if(direction%2!=newdirection%2){
direction=newdirection;
}
}
//生成食物
privateNodecreateFood(){
/*
*创建一个随机数的生成器,这个是java.util.Random类
*与java.lang.Math类中的rand