📄 gamedraws.java
字号:
}//帮助菜单选择
if (KeyCode == getKeyCode(Canvas.FIRE)) {
if(menuIndex==1){
if (MoveTitle == (MenuY+46)) {
try {
mid.notifyDestroyed();
} catch (Exception e) {
}
repaint();
}}
}//退出菜单选择
}
/*===============================*/
/* 排名记录系统 */
/*===============================*/
public void SaveScore(){
gc=new gameScore(Score); //记录上榜得分
boolean biger=gc.compareScore(); //比较
if(biger || gc.endId<6){ //记录前五名高分
inputDatas(); //输入名字
}else{
ListScore(); //显示排名
}
}
/**======显示排名======*/
public void ListScore(){
menuIndex=4;
this.setCommandListener(this);
removeCommand(menuPause);
setCommand(menuBack);
display.setCurrent(this);
repaint();
}
/**=====填写信息方法====*/
public void inputDatas(){
f.setCommandListener(this);
delForm(); //清除
f.removeCommand(menuBack);
f.addCommand(menuOk);
f.append(tf);
f.append("干的不错!上榜了: "+Score+"分");
display.setCurrent(f);
}
/*===============================*/
/* 碰撞检测系统 */
/*===============================*/
public void Impact(Graphics g)
{
//取得敌机宽高
for(int i=0;i<difficulty;i++)
{
epW[i] = pic.gameUI[SuiJi[i]].getWidth()+MoveEpX[i];
epH[i] = pic.gameUI[SuiJi[i]].getHeight()+MoveEpY[i];
}
//敌机子弹宽度
epBtW = pic.gameUI[13].getWidth()+epBtX[0];
//获得战机宽高
planeW = MovePX+18; planeH = MovePY+18;
//检测敌机
for(int i=0;i<difficulty;i++)
{
if((MoveBtX>=MoveEpX[i]&&MoveBtX<=epW[i])
&&(MoveBtY>=MoveEpY[i]&&MoveBtY<=epH[i]))
{
MoveBtX=-10;Score+=40;
MoveEpX[i] = Math.abs(rd.nextInt())%100+5;
MoveEpY[i] = -Math.abs(rd.nextInt())%50;
SuiJi[i] = Math.abs(rd.nextInt())%7+14;
SuiJiEpX[i] = Math.abs(rd.nextInt())%28;
}
}
//检测敌机子弹
for(int i=0;i<difficulty;i++)
{
if((epBtY[i]>=MovePY&&epBtX[i]>=MovePX&&epBtX[i]<=planeW
&&epBtY[i]<=planeH))
{
epBtX[i]=-10;MovePY =110;MovePX=27;
Lifes-=1;if(Lifes<0) MovePX=-40;}
}
//碰撞敌机
for(int i=0;i<difficulty;i++)
{
if(MoveEpY[i]>=MovePY&&MoveEpX[i]>=MovePX
&&MoveEpX[i]<=planeW&&MoveEpY[i]<=planeH)
{
MovePX=27; MovePY =110;
MoveEpY[i]=180; Lifes-=1;
MoveEpX[i] = Math.abs(rd.nextInt())%100+5;
MoveEpY[i] = -Math.abs(rd.nextInt())%50;
SuiJi[i] = Math.abs(rd.nextInt())%7+14;
}
}
}
/*===============================*/
/* 飞机、游戏背景移动线程 */
/*===============================*/
class PlaneMove extends TimerTask {
public void run()
{
if(!alive)
{
if(IbackY<0) IbackY++;
else IbackY=0;
if (BackGY <= 0) {//背景从y<0开始下移
BackGY = BackGY + 1;
}
if (BackGY > 0) {//至y>0返回重新移动
BackGY = -384;
}
//检测战机水平移动的边界
if (PlaneMove == 0)
{
if (MovePX <= 0) {MovePX = 0;}
MovePX -= 4;
}
if (PlaneMove == 1)
{
if (MovePX >= 105) {MovePX = 105;}
MovePX += 4;
}
//检测战机上下移动的边界
if (PlaneMove == 3)
{
if (MovePY <= 0) {MovePY = 5;}
MovePY -= 5;
}
if (PlaneMove == 4)
{
if (MovePY >= 105) {MovePY = 105;}
MovePY += 5;
}
repaint();
}
}
}
/*===============================*/
/* 首页背景移动线程 */
/*===============================*/
class backMove extends TimerTask
{
public void run()
{
if(Iback)
{
if(IbackY<0) IbackY++;
else {IbackY=0;Iback=false;}
repaint();
}
}
}
/*===============================*/
/* 战机子弹发射线程 */
/*===============================*/
class PlaneBullet extends TimerTask{
public void run()
{
if(!alive)
{
if (MoveBtY <0)
MoveBtY=MovePY;//子弹发射位置
if(MoveBtY==MovePY)
MoveBtX = MovePX+9;//子弹移动
for (int i = 0; i < SpeedpBt; i++) //子弹发射速度
MoveBtY -= 1;
repaint();
}
}
}
/*===============================*/
/* 敌机子Ⅰ弹发射线程 */
/*===============================*/
class bulletEp extends TimerTask{
public void run()
{
if(!alive)
{
for(int i=0;i<difficulty;i++)
{
if (epBtY[i] >128)
epBtY[i]=MoveEpY[i];//子弹发射位置
if(epBtY[i]==MoveEpY[i])
epBtX[i] = MoveEpX[i]+9;//子弹移动
}
for (int i = 0; i < SpeedepBt; i++) //子弹发射速度
{epBtY[0] += 1;epBtY[1] += 1;
epBtY[2] += 1;epBtY[3] += 1;}
repaint();
}
}
}
/*===============================*/
/* 敌机移动线程 */
/*===============================*/
class Enemy extends TimerTask
{
public void run()
{
if(!alive)
{
for(int i=0;i<difficulty;i++)
{
if(MoveEpY[i]>=145)
MoveEpY[i] = 0;
}
for(int i= 0;i<SpeedEnemy;i++)//控制敌机飞行速度
{MoveEpY[0]+=1; MoveEpY[1]+=1;
MoveEpY[2]+=1;MoveEpY[3]+=1;}
repaint();
}
}
}
/*===============================*/
/* 实现命令监听 */
/*===============================*/
public void commandAction(Command c, Displayable s)
{
if(c==menuOk)//触发确认命令
{
if (MoveTitle == MenuY)
{menuIndex=2;repaint();} //触发新游戏菜单
if ((MoveTitle == (MenuY+23))&&menuIndex==1)
{helpPage();} //触发帮助菜单
if ((MoveTitle == (MenuY+46))&&menuIndex==1)
{mid.notifyDestroyed();} //触发退出菜单
if(count1>0) {SelectAir();count1=0;} //选择战机,count用于阻止自动选择
if(Lifes<0||Score>=TopScore)//游戏结束或通关
{
gc.writeToDate(tf.getString()); //将记录写入仓库
System.out.println("控制");
ListScore(); //显示排行
Lifes=0;Score=0;//归零判断条件,防止二次判断
}
System.out.println(menuIndex);
}
if (c == menuBack)//触发返回菜单
{
if(Lifes<0||Score>=TopScore) SaveScore();//高分者填写记录
else menuIndex=1;
if((menuIndex==3||menuIndex==2)&&Lifes>=0)
{
count1=0;//阻止自动选择战机
menuIndex=1;removeCommand(menuPause);
setCommand(menuOk);repaint();
}
else
{
if(menuIndex==4)
{Lifes=0;menuIndex=1;
setCommand(menuOk);repaint();}
else
{
alive = false;
System.out.println("控制");
removeCommand(menuPause);
count1=0; backPage();
OverY=200;
}
}
pause=0;//重置暂停开关
IbackY=-128;Iback=true;
}
if(c==menuPause)//触发暂停菜单
{
count++;
if(count%2!=0)alive = true;
else alive = false;
}
}
/**=====定义退出方法====*/
private void exit(MIDlet midlet){
midlet.notifyDestroyed();
}
/**======定义返回======*/
private void backPage(){
this.setCommandListener(this);
setCommand(menuOk);
display.setCurrent(this);
repaint();
}
/**====清空Form窗体====*/
private void delForm(){
for(int i=0;i<f.size();i++){
f.delete(i);
}
for(int i=0;i<f.size();i++){
f.delete(i);
}
}
/**==定义设置命令方法===*/
private void setCommand(Command c){
this.removeCommand(menuBack);
this.removeCommand(menuOk);
this.addCommand(c);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -