📄 gamecanvas.java
字号:
//产生飞行物的方法有问题
import javax.microedition.lcdui.*;
import java.util.*;
class GameCanvas extends Canvas implements Runnable,CommandListener{
private int screenWidth = 128;
private int screenHeight = 128;
private myMan man;
private int board1[][]=new int[9][6];
private int board2[][]=new int[9][6];
private int board3[][]=new int[9][6];
private int board4[][]=new int[9][6];
private int jumpUD;
private int[] speed;
private Image back;
private Image back1;
private Image back2;
private Image img1;
private Image img2;
Image imgs[]=new Image[3];
Image m[] =new Image[13];
Image n[] =new Image[1];
private boolean jumpCan;
private int manState=0;
private static int STATE=0;
private Font defFont = Font.getDefaultFont();
private static final int SCORE_AREA = Font.getDefaultFont().getHeight();
private Command exitCmd = new Command("Exit", Command.SCREEN, 1);
private Command pauseCmd = new Command("Pause", Command.SCREEN, 5);
private Command resumeCmd = new Command("Resume", Command.SCREEN, 5);
private Command quitCmd = new Command("Quit", Command.SCREEN, 1);
private static final short TITLE = 0;
private static final short GAME_START = 1;
private static final short GAME_PLAYING = 2;
private static final short GAME_END = 5;
private int gameState;
private boolean isPaused;
private boolean isStopped;
private boolean win;
boolean isGameOver=false;
boolean GameOver=false;
private boolean minzero=false;
private int minute=0,second=0;
private int ms=0;
private int v=0;
int c=0;
int tmpY2=0;
int centerX=0;
int centerY=0;
private final int a=200;
float t=0.1f;
private int s=0;
private int tmpX=0;
private int tmpY=0;
private int level=1;
private int curMenu=0;
private int menuCount=0;
private Image buffer;
private Graphics g1;
private Random r=new Random();
private int p=0;//记录电网
private int p2=0;//记录生命数
private JumpDemo main;
int w=0;
int w3=0;
int w4=0;
// int w5=0;
int w6=0;
GameCanvas(JumpDemo main){
this.main=main;
buffer = Image.createImage(screenWidth,screenHeight);//创建缓冲区域
g1 = buffer.getGraphics();
man = new myMan(this);
try{
img1=Image.createImage("/img1.png");
img2=Image.createImage("/img2.png");
back=Image.createImage("/back.png");
back1=Image.createImage("/back1.png");
for(int i=0;i<13;i++){
m[i]=Image.createImage("/m"+String.valueOf(i)+".png");
}
for(int i=0;i<3;i++){
imgs[i]=Image.createImage("/p"+String.valueOf(i)+".png");
}
}catch(Exception e){}
setCommandListener(this);
gameState = TITLE;
}
void Init(){
jumpUD=10;
man.setX(0);
man.setY(54);
man.setState(2);
man.setAlive(true);
manState=0;//不在板子上
jumpCan=true;//站立态
win=false;
for(int i=0;i<9;i++){
board1[i][0]=25;
board1[i][1]=-31+i*38;
board1[i][2]=0;
board1[i][3]=0;
board1[i][4]=0;
board1[i][5]=0;
}
for(int i=0;i<9;i++){
board2[i][0]=46;
board2[i][1]=-31+i*38;
board2[i][2]=0;
board2[i][3]=0;
board2[i][4]=0;
board2[i][5]=0;
}
for(int i=0;i<9;i++){
board3[i][0]=67;
board3[i][1]=-31+i*38;
board3[i][2]=0;
board3[i][3]=0;
board3[i][4]=0;
board3[i][5]=0;
}for(int i=0;i<9;i++){
board4[i][0]=88;
board4[i][1]=-31+i*38;
board4[i][2]=0;
board4[i][3]=0;
board4[i][4]=0;
board4[i][5]=0;
}
//清除游戏循环停止标志
isStopped = false;
//清除暂停标志
isPaused = false;
isGameOver=false;
GameOver=false;
}
void GameInit(){
if(level==1){
speed=new int[]{1,-2,2,-1};
/* board1[0][2]=1;//猴子
board1[1][2]=4;//蜜蜂
board1[2][2]=6;//蛇
board1[3][2]=8;//人静态
board1[4][2]=9;//狼人静态
board1[5][2]=10;//可吃物动画
board1[6][2]=12;//假美眉*/
board1[0][2]=1;//猴子
board1[3][2]=4;//蜜蜂
board1[5][2]=6;//蛇
board2[5][2]=1;//猴子
board2[7][2]=12;//假美眉
board3[2][2]=9;//鄂鱼静态
board3[5][2]=1;//猴子
board3[7][2]=12;//假美眉
board4[2][2]=4;//鄂鱼静态
board4[5][2]=4;//可吃物动画
board4[7][2]=1;//假美眉
board1[6][3]=1;//为0代表板子,为1代表弹床,
board1[7][3]=1;//弹床
board1[6][4]=1;//为0代表不能上下跳跃,为一代表只能下跳,为二代表只能上跳,为三代表可以上下跳
board1[7][4]=3;
board1[8][4]=2;
board3[8][3]=1;
board3[8][4]=1;
board3[0][4]=2;
board4[2][3]=1;
board4[2][4]=1;
board4[3][4]=2;
p=0;//加电网
}
else if(level==2){
speed=new int[]{1,-2,2,-1};
board1[0][2]=9;
board1[3][2]=1;
board1[5][2]=12;
board1[7][2]=4;
board2[2][2]=1;
board2[5][2]=4;
board2[7][2]=6;
board3[2][2]=9;//鄂鱼静态
board3[5][2]=1;//猴子
board3[7][2]=12;//假美眉
board4[2][2]=4;//蜜蜂
board4[5][2]=4;//蜜蜂
board4[7][2]=1;//假美眉
board4[6][2]=10;//可吃物动画
board4[8][2]=10;
board1[6][3]=1;//为0代表板子,为1代表弹床,
board1[7][3]=1;//弹床
board1[6][4]=1;//为0代表不能上下跳跃,为一代表只能下跳,为二代表只能上跳,为三代表可以上下跳
board1[7][4]=3;
board1[8][4]=2;
board3[8][3]=1;
board3[8][4]=1;
board3[0][4]=2;
board4[2][3]=1;
board4[2][4]=1;
board4[3][4]=2;
p=1;//加电网
}
else if(level==3){
speed=new int[]{2,-1,2,-1};
board1[0][2]=1;//猴子
board1[3][2]=4;//蜜蜂
board1[5][2]=6;//蛇
board2[2][2]=9;//鄂鱼静态
board2[5][2]=1;//猴子
board2[7][2]=12;//假美眉
board3[2][2]=9;//鄂鱼静态
board3[5][2]=1;//猴子
board3[7][2]=12;//假美眉
board3[0][2]=10;//可吃物
board4[2][2]=4;//蜜蜂
board4[5][2]=4;//蜜蜂
board4[7][2]=1;//假美眉
board4[6][2]=10;//可吃物动画
board1[6][3]=1;//为0代表板子,为1代表弹床,
board1[7][3]=1;//弹床
board1[6][4]=1;//为0代表不能上下跳跃,为一代表只能下跳,为二代表只能上跳,为三代表可以上下跳
board1[7][4]=3;
board1[8][4]=2;
board3[8][3]=1;
board3[8][4]=1;
board3[0][4]=2;
board4[2][3]=1;
board4[2][4]=1;
board4[3][4]=2;
p=2;//加电网
}
else if(level==4){
speed=new int[]{1,-3,2,-1};
board1[0][2]=1;//猴子
board1[3][2]=4;//蜜蜂
board1[5][2]=6;//蛇
board2[2][2]=9;//鄂鱼静态
board2[5][2]=1;//猴子
board2[7][2]=12;//假美眉
board3[2][2]=9;//鄂鱼静态
board3[5][2]=1;//猴子
board3[7][2]=12;//假美眉
board3[0][2]=10;//可吃物
board4[2][2]=4;//蜜蜂
board4[5][2]=4;//蜜蜂
board4[7][2]=1;//假美眉
board4[6][2]=10;//可吃物动画
board4[8][2]=10;
board1[6][3]=1;//为0代表板子,为1代表弹床,
board1[7][3]=1;//弹床
board1[6][4]=1;//为0代表不能上下跳跃,为一代表只能下跳,为二代表只能上跳,为三代表可以上下跳
board1[7][4]=3;
board1[8][4]=2;
board3[8][3]=1;
board3[8][4]=1;
board3[0][4]=2;
board4[2][3]=1;
board4[2][4]=1;
board4[3][4]=2;
p=2;//加电网
}
else if(level==5){
speed=new int[]{1,-2,2,-1};
board1[0][2]=1;//猴子
board1[3][2]=4;//蜜蜂
board1[5][2]=6;//蛇
board2[2][2]=9;//鄂鱼静态
board2[5][2]=1;//猴子
board2[7][2]=12;//假美眉
board3[2][2]=9;//鄂鱼静态
board3[5][2]=1;//猴子
board3[7][2]=12;//假美眉
board3[0][2]=6;//蛇
board4[2][2]=4;//蜜蜂
board4[5][2]=4;//蜜蜂
board4[7][2]=1;//假美眉
board4[6][2]=10;//可吃物动画
board4[8][2]=10;
board1[6][3]=1;//为0代表板子,为1代表弹床,
board1[7][3]=1;//弹床
board1[6][4]=1;//为0代表不能上下跳跃,为一代表只能下跳,为二代表只能上跳,为三代表可以上下跳
board1[7][4]=3;
board1[8][4]=2;
board3[8][3]=1;
board3[8][4]=1;
board3[0][4]=2;
board4[2][3]=1;
board4[2][4]=1;
board4[3][4]=2;
p=3;//加电网
}
else if(level==6){
speed=new int[]{1,-2,2,-1};
board1[0][2]=1;//猴子
board1[3][2]=4;//蜜蜂
board1[5][2]=6;//蛇
board2[2][2]=9;//鄂鱼静态
board2[5][2]=1;//猴子
board2[7][2]=12;//假美眉
board3[2][2]=9;//鄂鱼静态
board3[5][2]=1;//猴子
board3[7][2]=12;//假美眉
board3[0][2]=6;//蛇
board4[2][2]=4;//蜜蜂
board4[5][2]=4;//蜜蜂
board4[7][2]=1;//假美眉
board4[6][2]=10;//可吃物动画
board1[6][3]=1;//为0代表板子,为1代表弹床,
board1[7][3]=1;//弹床
board1[6][4]=1;//为0代表不能上下跳跃,为一代表只能下跳,为二代表只能上跳,为三代表可以上下跳
board1[7][4]=3;
board1[8][4]=2;
board3[8][3]=1;
board3[8][4]=1;
board3[0][4]=2;
board4[2][3]=1;
board4[2][4]=1;
board4[3][4]=2;
p=3;//加电网
}
else if(level==7){
speed=new int[]{1,-2,2,-1};
board1[0][2]=1;//猴子
board1[3][2]=4;//蜜蜂
board1[5][2]=6;//蛇
board2[2][2]=9;//鄂鱼静态
board2[5][2]=1;//猴子
board2[7][2]=12;//假美眉
board3[2][2]=9;//鄂鱼静态
board3[5][2]=1;//猴子
board3[7][2]=12;//假美眉
board3[0][2]=6;//蛇
board4[2][2]=4;//蜜蜂
board4[5][2]=4;//蜜蜂
board4[7][2]=1;//假美眉
board4[6][2]=10;//可吃物动画
board1[6][3]=1;//为0代表板子,为1代表弹床,
board1[7][3]=1;//弹床
board1[6][4]=1;//为0代表不能上下跳跃,为一代表只能下跳,为二代表只能上跳,为三代表可以上下跳
board1[7][4]=3;
board1[8][4]=2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -