📄 gamecanvas.java
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
import com.nokia.mid.ui.*;
import java.io.IOException;
import java.util.Random;
import java.util.TimerTask;
import javax.microedition.lcdui.*;
public class GameCanvas extends FullCanvas
{
GameMain gameMain;
Random random;
Graphics gx;
Image gun1;
Image gun2;
Image gun3;
Image shadow;
Image sun;
Image tombstone;
DirectGraphics dg;
DeviceControl dc;
public final NokiaGameEffects gameEffects;
static short GAME_INI = 0;
static short GAME_READY = 1;
static short GAME_NUMBER = 2;
static short GAME_FAIL = 3;
static short GAME_SHOW = 4;
static short GAME_SUC = 5;
static short GAME_OVER = 7;
static short GAME_PLAY = 8;
boolean oneTimeFlag;
boolean bAKiller[][];
boolean bAMap[][];
boolean bMove;
boolean bPaint;
boolean bTarget;
boolean bMap;
boolean bBullet;
int nTarget;
int nX;
int nY;
int nTX;
int nTY;
int nGame;
int nLevel;
int nWindow;
int nKiller;
int nChar;
int nChoose;
int nTime;
int nScore;
int nGun;
int nShoot;
int nBullet;
int nPlus;
public GameCanvas(GameMain gamemain)
{
random = new Random();
gameMain = gamemain;
oneTimeFlag = true;
nTX = 23;
nTY = 96;
gameEffects = new NokiaGameEffects(gameMain);
try
{
gun1 = Image.createImage("/img/gun_hk.png");
gun2 = Image.createImage("/img/gun_psg.png");
gun3 = Image.createImage("/img/gun_us.png");
}
catch(IOException ioexception) { }
}
protected void showNotify()
{
}
protected void keyPressed(int i)
{
if(nGame == GAME_INI)
{
if(i == -1 || i == 50)
{
if(nLevel == 0)
nLevel = 3;
else
nLevel--;
} else
if(i == -2 || i == 56)
{
if(nLevel == 3)
nLevel = 0;
else
nLevel++;
} else
if(i == -3 || i == 52)
{
if(nGun == 0)
nGun = 2;
else
nGun--;
} else
if(i == -4 || i == 54)
{
if(nGun == 2)
nGun = 0;
else
nGun++;
} else
if(i == 53)
{
gameMain.gameTimer.count = 0;
if(nLevel == 0)
{
nTime = 90;
nWindow = 5;
} else
if(nLevel == 1)
{
nTime = 90;
nWindow = 5;
} else
if(nLevel == 2)
{
nTime = 150;
nWindow = 7;
} else
if(nLevel == 3)
{
nTime = 210;
nWindow = 9;
}
if(nLevel == 0)
{
nKiller = 1;
nX = nY = 2;
bAMap = new boolean[5][5];
bAKiller = new boolean[5][5];
} else
{
nKiller = nWindow;
nX = nY = nWindow / 2;
bAMap = new boolean[nWindow][nWindow];
bAKiller = new boolean[nWindow][nWindow];
}
if(nGun == 0)
{
nPlus = 4;
nBullet = 10;
} else
if(nGun == 1)
{
nPlus = 3;
nBullet = 20;
} else
if(nGun == 2)
{
nPlus = 6;
nBullet = 5;
}
gun1 = gun2 = gun3 = null;
gameMain.gameImg.load();
setKiller();
nGame = GAME_SHOW;
}
repaint();
} else
if(nGame == GAME_PLAY)
{
if(i == 50 || i == -1)
{
gameEffects.eachSound(4);
if(bAMap[nX][nY] && bAKiller[nX][nY])
setOneKiller();
if(nY > 0)
{
bMove = true;
nY--;
}
nShoot = 0;
nTY = 96;
nTX = 23;
} else
if(i == 56 || i == -2)
{
gameEffects.eachSound(4);
if(bAMap[nX][nY] && bAKiller[nX][nY])
setOneKiller();
if(nY < nWindow - 1)
{
bMove = true;
nY++;
}
nShoot = 0;
nTY = 96;
nTX = 23;
} else
if(i == 52 || i == -3)
{
gameEffects.eachSound(4);
if(bAMap[nX][nY] && bAKiller[nX][nY])
setOneKiller();
if(nX > 0)
{
bMove = true;
nX--;
}
nShoot = 0;
nTY = 96;
nTX = 23;
} else
if(i == 54 || i == -4)
{
gameEffects.eachSound(4);
if(bAMap[nX][nY] && bAKiller[nX][nY])
setOneKiller();
if(nX < nWindow - 1)
{
bMove = true;
nX++;
}
nShoot = 0;
nTY = 96;
nTX = 23;
} else
if(i == 48 && !bAMap[nX][nY])
{
bAMap[nX][nY] = true;
gameMain.gameTimer.count = 0;
gameEffects.eachSound(12);
if(bAKiller[nX][nY])
{
nTarget = random.nextInt() % 3;
if(nTarget < 0)
nTarget = -nTarget;
nChar = random.nextInt() % 3;
if(nChar < 0)
nChar = -nChar;
} else
if(random.nextInt() % 2 == 0)
{
nTarget = random.nextInt() % 3;
if(nTarget < 0)
nTarget = -nTarget;
nChar = random.nextInt() % 3;
if(nChar < 0)
nChar = -nChar;
nChar += 3;
if(random.nextInt() % 2 == 0)
bBullet = true;
}
} else
if(i == 53)
if(nShoot == 0)
nShoot = 1;
else
if(nShoot == 1 && bAMap[nX][nY])
{
gameEffects.eachSound(1);
if(bAKiller[nX][nY])
{
if((58 - nTY) * (58 - nTY) + ((34 + nTarget * 30) - nTX) * ((34 + nTarget * 30) - nTX) <= 64)
{
bTarget = true;
nShoot = 2;
} else
{
nShoot = 0;
nTY = 96;
nTX = 23;
}
} else
if(bBullet && nTY < 89 && nTY > 71 && nTX > 26 + nTarget * 30 && nTX < 42 + nTarget * 30)
{
nBullet += 5;
bTarget = true;
} else
if(nTY < 95 && nTY > 35 && nTX > 11 + nTarget * 30 && nTX < 49 + nTarget * 30)
{
bBullet = false;
bTarget = true;
}
nBullet--;
}
repaint();
if(i == -7)
{
if(gameMain.gameFlag == 4)
gameMain.gameFlag = 0;
else
gameMain.gameFlag = 4;
repaint();
} else
if(i == -6 && gameMain.gameFlag != 4)
{
gameMain.resumeFlag = true;
gameMain.gameFlag = 2;
if(gameMain.titleCanvas == null)
gameMain.titleCanvas = new TitleCanvas(gameMain);
gameMain.display.setCurrent(gameMain.titleCanvas.menuList);
}
} else
if(nGame == GAME_SUC || nGame == GAME_FAIL)
{
if(i == 53)
{
if(nGame == GAME_SUC)
nScore = nScore + nTime * nWindow;
gameMain.totalScore = nScore;
if(gameMain.scoreBoard == null)
gameMain.scoreBoard = new ScoreBoard(gameMain);
gameMain.rank = gameMain.scoreCal();
gameMain.scoreBoard.rank = gameMain.rank;
nScore = 0;
gameMain.gameTimer.cancel();
gameMain.gameTimer = null;
gameMain.gameImg = null;
gameMain.gameCanvas = null;
gameMain.resumeFlag = false;
gameMain.gameFlag = 2;
gameMain.display.setCurrent(gameMain.scoreBoard);
}
repaint();
}
if(i == 42)
if(bMap)
bMap = false;
else
bMap = true;
}
public void paint(Graphics g)
{
bPaint = false;
if(oneTimeFlag)
{
gx = g;
oneTimeFlag = false;
dg = DirectUtils.getDirectGraphics(g);
}
if(gameMain.gameFlag == 4)
{
gx.setColor(249, 185, 15);
gx.fillRect(44, 45, 40, 20);
gx.setFont(Font.getFont(0, 0, 8));
gx.setColor(30, 30, 200);
gx.drawString("PAUSE", 64, 50, 0x10 | 0x1);
} else
{
gx.setFont(Font.getFont(0, 0, 8));
if(nGame == GAME_INI)
drawIni();
else
if(nGame == GAME_SHOW)
drawShow();
else
if(nGame == GAME_READY)
{
drawBG();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -