📄 gamecanvas.java
字号:
import com.nokia.mid.ui.*;
import com.nokia.mid.sound.Sound;
import java.util.Random;
import javax.microedition.lcdui.*;
public class GameCanvas extends FullCanvas
implements Runnable {
private DragonSoul P;
private Thread J;
//true:胜利 false:失败
private boolean V;
//游戏暂停控制变量
private boolean bPause;
//游戏运行时间
private long B;
//游戏暂停时纪录下系统时间
private long a;
private Image time;
private Image digits;
private Image panel;
private Image message;
private Image arena;
private Image houses[];
public Image player_u = null;
//游戏角色
private Player player1;
private Player player2;
//背景图片定位坐标
private int b;
//对局时的刷新次数
private long refreshNum;
public Random t;
//控制游戏开始字幕显示
private int sCounter;
//游戏开始字幕
private String G;
//回合控制
private boolean E;
//判断游戏是否超时
private boolean overTime;
//private Image super_ind;
//回合进行的时间
private int A;
//回合数
private int round;
//角色胜利的回合数
private int vRound[];
private boolean z;
//十六进制声音字符串
private static final String e[] = {
"024A3A65A1A5D17DA185B990C404000F18CAEB25051C8000", "024A3A65A1A5D17DA185B990C80400171CCAE927041382CDC144E000", "024A3A61A1A5D17DB1959CC404000F1ACAEB2903902D0000", "024A3A61A1A5D17DB1959CC804001722CAE82304938289C164E000", "024A3A6591A5957DC9BDD5B99004001718CAEB36C3702D02D025051B6000", "024A3A6191A5957D9D85B59404001318CAEB3702D025051B6800", "024A3A65DDA5B97DC9BDD5B99004001D18CAE620620620618A22C2AC498828C24000", "024A3A61DDA5B97D9D85B59404002118CAE558560560560720560560A27027027049580000", "024A3A55CDD5C195C804001918CAE939029041981182CD40B40000"
};
private byte j[][];
private boolean I;
//线程类对象
private a h;
//判断游戏模式2
private boolean M;
//判断游戏模式3
private boolean m;
//中绝技判断
public boolean c;
private Image face;
private Sound F;
/**
* 游戏主画面的构造函数,创建和初始化变量
* @param wfightn40 DragonSoul,游戏入口类对象
*/
public GameCanvas(DragonSoul wfightn40)
{
B = 0L;
a = 0L;
houses = new Image[2];
vRound = new int[2];
j = new byte[9][];
P = wfightn40;
try {
time = Image.createImage("/time.png");
digits = Image.createImage("/digits.png");
panel = Image.createImage("/panel.png");
message = Image.createImage("/message.png");
arena = Image.createImage("/arena.png");
houses[0] = Image.createImage("/houses_front.png");
houses[1] = Image.createImage("/hourse_back.png");
player_u = Image.createImage("/players_u.png");
if (face == null)
face = Image.createImage("/faces.png");
for(int i1 = 0; i1 < e.length; i1++)
j[i1] = DragonSoul.setStingToByte(e[i1]);
F = new Sound(1000, 1000L);
//System.gc();
} catch(Exception exception) {
//System.out.println(exception);
}
t = new Random();
}
/**
* 绘制游戏画面
* @param g1 Graphics
*/
protected void paint(Graphics g1){
//g1.setClip(0, 0, getWidth(), getHeight());
g1.setColor(0x722AEF);
g1.fillRect(0, 0, getWidth(), getHeight());
g1.drawImage(panel, 0, getHeight(), 0x20 | 0x4);
for(int i1 = 0; i1 < getWidth() / arena.getWidth() + 3; i1++)
g1.drawImage(arena, (i1 - 1) * arena.getWidth() - getB() % arena.getWidth(), getHeight() - panel.getHeight(), 0x20 | 0x4);
g1.drawImage(houses[1], getWidth() / 2, getHeight() - panel.getHeight() - arena.getHeight(), 0x20 | 0x1);
g1.drawImage(houses[0], (getWidth() / 2) - getB() % getWidth(), getHeight() - panel.getHeight() - arena.getHeight(), 0x20 | 0x1);
if(getB() > 0)
{
g1.drawImage(houses[0], ((getWidth() * 3) / 2) - getB() % getWidth(), getHeight() - panel.getHeight() - arena.getHeight(), 0x20 | 0x1);
} else
if(getB() < 0)
{
g1.drawImage(houses[0], - getWidth() / 2 - getB() % getWidth(), getHeight() - panel.getHeight() - arena.getHeight(), 0x20 | 0x1);
}
player2.drawPlayer(g1);
player1.drawPlayer(g1);
player2.drawSkill(g1);
player1.drawSkill(g1);
g1.setClip(0, 0, getWidth(), getHeight());
if(P.backToGameMode() != 0 && !M && !m)
{
if(P.backToGameMode() == 3)
{
int i3 = player1.getE();
if(i3 > DragonSoul.eNum[player1.getPlayer()])
{
int i2 = 60;
g1.setColor(0xffff00);
g1.fillRoundRect(getWidth() / 2 - i2, 6, i2, 4, 4, 4);
g1.setColor(0xffffff);
g1.drawRoundRect(getWidth() / 2 - i2, 6, i2, 4, 4, 4);
i3 -= DragonSoul.eNum[player1.getPlayer()];
i2 = 15 + (45 * i3) / DragonSoul.eNum[player1.getPlayer()];
g1.setColor(0xffff00);
g1.fillRoundRect(getWidth() / 2 - i2, 12, i2, 4, 4, 4);
g1.setColor(0xffffff);
g1.drawRoundRect(getWidth() / 2 - i2, 12, i2, 4, 4, 4);
} else
{
int j2 = 15 + (45 * i3) / DragonSoul.eNum[player1.getPlayer()];
g1.setColor(0xffff00);
g1.fillRoundRect(getWidth() / 2 - j2, 6, j2, 4, 4, 4);
g1.setColor(0xffffff);
g1.drawRoundRect(getWidth() / 2 - j2, 6, j2, 4, 4, 4);
}
} else
{
int k2 = 15 + (45 * player1.getE()) / DragonSoul.eNum[player1.getPlayer()];
g1.setColor(0xffff00);
g1.fillRoundRect(getWidth() / 2 - k2, 6, k2, 10, 4, 4);
g1.setColor(0xffffff);
g1.drawRoundRect(getWidth() / 2 - k2, 6, k2, 10, 4, 4);
}
int l2 = 15 + (45 * player2.getE()) / DragonSoul.eNum[player2.getPlayer()];
g1.setColor(0xffff00);
g1.fillRoundRect(getWidth() / 2, 6, l2, 10, 4, 4);
g1.setColor(0xffffff);
g1.drawRoundRect(getWidth() / 2, 6, l2, 10, 4, 4);
}
if(!M && !m)
g1.drawImage(time, getWidth() / 2, 4, 0x10 | 0x1);
g1.setClip(0, 0, getWidth(), getHeight());
g1.setFont(Font.getFont(64, 1, 8));
if(!M && !m)
{
g1.setColor(136);
g1.drawString(DragonSoul.name[player1.getPlayer()], 25, 21, 0x10 | 0x4);
g1.setColor(0xffff00);
g1.drawString(DragonSoul.name[player1.getPlayer()], 24, 20, 0x10 | 0x4);
g1.setColor(136);
g1.drawString(DragonSoul.name[player2.getPlayer()], (getWidth() - 25) + 1, 21, 0x10 | 0x8);
g1.setColor(0xffff00);
g1.drawString(DragonSoul.name[player2.getPlayer()], getWidth() - 24, 20, 0x10 | 0x8);
if(!player1.judgeForceTime())
g1.setClip(0, 36, getWidth(), (P.fistImage.getHeight() * (A - player1.getForceTime())) / 20);
if(!player1.judgeForceTime() || player1.judgeForceTime() && refreshNum % (long)2 == (long)1)
g1.drawImage(P.fistImage, getWidth() / 4 - 4, 36, 0x10 | 0x1);
}
g1.setClip(0, 0, getWidth(), getHeight());
g1.setFont(Font.getFont(64, 1, 8));
g1.setColor(136);
g1.drawString(DragonSoul.name[player1.getPlayer()], 25, (getHeight() - 21) + 1, 0x10 | 0x4);
g1.setColor(0xffff00);
g1.drawString(DragonSoul.name[player1.getPlayer()], 24, getHeight() - 21, 0x10 | 0x4);
g1.setColor(136);
g1.drawString(DragonSoul.name[player2.getPlayer()], (getWidth() - 24) + 1, (getHeight() - 13) + 1, 0x10 | 0x8);
g1.setColor(0xffff00);
g1.drawString(DragonSoul.name[player2.getPlayer()], getWidth() - 24, getHeight() - 13, 0x10 | 0x8);
g1.setClip(0, 0, getWidth(), getHeight());
if(vRound[0] > 0)
g1.drawImage(P.fistImage, 24, getHeight() - panel.getHeight() / 4, 0x4 | 0x2);
if(vRound[0] > 1)
g1.drawImage(P.fistImage, 24 + P.fistImage.getWidth(), getHeight() - panel.getHeight() / 4 - P.fistImage.getHeight()/2, 0x4 | 0x10);
if(vRound[0] > 2)
g1.drawImage(P.fistImage, 24 + P.fistImage.getWidth() * 2, getHeight() - panel.getHeight() / 4 - P.fistImage.getHeight()/2, 0x4 | 0x10);
if(vRound[1] > 0)
g1.drawImage(P.fistImage, getWidth() - 24, getHeight() - (panel.getHeight() * 3) / 4 - P.fistImage.getHeight()/2, 0x8 | 0x10);
if(vRound[1] > 1)
g1.drawImage(P.fistImage, getWidth() - 24 - P.fistImage.getWidth(), getHeight() - (panel.getHeight() * 3) / 4 - P.fistImage.getHeight()/2, 0x8 | 0x10);
if(vRound[1] > 2)
g1.drawImage(P.fistImage, getWidth() - 24 - P.fistImage.getWidth() * 2, getHeight() - (panel.getHeight() * 3) / 4 - P.fistImage.getHeight()/2, 0x8 | 0x10);
g1.setClip(2, getHeight() - 19, face.getWidth(), face.getHeight() / 8);
g1.drawImage(face, 2, getHeight() - 19 - (face.getHeight() / 8) * player1.getPlayer(), 0x10 | 0x4);
DirectGraphics directgraphics = DirectUtils.getDirectGraphics(g1);
g1.setClip(getWidth() - face.getWidth() - 2, getHeight() - 19, face.getWidth(), face.getHeight() / 8);
directgraphics.drawImage(face, getWidth() - face.getWidth() - 2, getHeight() - 19 - (face.getHeight() / 8) * player2.getPlayer(), 0x10 | 0x4, 8192);
if(sCounter == 0 && !I && !M && !m)
if(P.setting[3] == 2 || P.backToGameMode() == 0)
{
g1.setClip(0, 0, getWidth(), getHeight());
g1.drawImage(P.m, getWidth() / 2, 25, 0x10 | 0x1);
} else
{
int j3 = A;
if(j3 > 99)
j3 = 99;
g1.setClip(getWidth() / 2 - 1 - digits.getWidth() / 10, 22, digits.getWidth() / 10, digits.getHeight());
g1.drawImage(digits, getWidth() / 2 - 1 - ((j3 / 10 + 1) * digits.getWidth()) / 10, 22, 0x10 | 0x4);
g1.setClip(getWidth() / 2 + 1, 22, digits.getWidth() / 10, digits.getHeight());
g1.drawImage(digits, (getWidth() / 2 + 1) - ((j3 % 10) * digits.getWidth()) / 10, 22, 0x10 | 0x4);
}
g1.setClip(0, 0, getWidth(), getHeight());
g1.setColor(0xa27737);
g1.setFont(Font.getFont(64, 1, 8));
int k3 = (message.getHeight() - g1.getFont().getHeight()) / 2 + 3;
if(sCounter > 0) {
if(sCounter > 15)
{
byte byte0 = 15;
int i4 = ((message.getWidth() - byte0 * 2) * (5 - (sCounter - 15))) / 5;
g1.setClip((getWidth() - i4) / 2, 30, i4, message.getHeight());
//g1.drawImage(message, getWidth() / 2, 30, 0x10 | 0x1);
g1.drawImage(message, (getWidth() - i4) / 2, 30, 0);
g1.drawString(G, getWidth() / 2, 30 + k3, 0x10 | 0x1);
g1.setClip((getWidth() - i4) / 2 - byte0, 30, byte0, message.getHeight());
g1.drawImage(message, (getWidth() - i4) / 2 - byte0, 30, 0);
g1.setClip((getWidth() - i4) / 2 + i4, 30, byte0, message.getHeight());
//g1.drawImage(message, (getWidth() - i4) / 2 + i4 + byte0, 30, 0x10 | 0x8);
g1.drawImage(message, (getWidth() - i4) / 2 + i4 + byte0 - message.getWidth(), 30,0);
} else
{
g1.drawImage(message, getWidth() / 2, 30, 0x10 | 0x1);
g1.drawString(G, getWidth() / 2, 30 + k3, 0x10 | 0x1);
}
}
if(I){
int l3 = A;
if(l3 > 99)
l3 = 99;
g1.setClip(getWidth() / 2 - 1 - digits.getWidth() / 10, 22, digits.getWidth() / 10, digits.getHeight());
g1.drawImage(digits, getWidth() / 2 - 1 - ((l3 / 10 + 1) * digits.getWidth()) / 10, 22, 0x10 | 0x4);
g1.setClip(getWidth() / 2 + 1, 22, digits.getWidth() / 10, digits.getHeight());
g1.drawImage(digits, (getWidth() / 2 + 1) - ((l3 % 10) * digits.getWidth()) / 10, 22, 0x10 | 0x4);
g1.setClip(0, 0, getWidth(), getHeight());
g1.setColor(0);
g1.drawString("任意键", getWidth() / 2 + 1, 51, 0x10 | 0x1);
g1.drawString("继续", getWidth() / 2 + 1, 71, 0x10 | 0x1);
g1.setColor(0xffffff);
g1.drawString("任意键", getWidth() / 2, 50, 0x10 | 0x1);
g1.drawString("继续", getWidth() / 2, 70, 0x10 | 0x1);
}
if(M || m) {
g1.setFont(Font.getFont(64, 1, 0));
int ai1[] = {
0, 0xffff00
};
for(int j4 = 0; j4 < ai1.length; j4++) {
g1.setColor(ai1[j4]);
g1.drawString("恭喜恭喜!", (getWidth() / 2 + 1) - j4, 3 - j4, 0x10 | 0x1);
if (M) {
g1.drawString("你被封为了龙魂", (getWidth() / 2 + 1) - j4, (3 - j4) + g1.getFont().getHeight(), 0x10 | 0x1);
} else {
g1.drawString("你赢了", (getWidth() / 2 + 1) - j4, (3 - j4) + g1.getFont().getHeight(), 0x10 | 0x1);
}
// if(M)
// g1.drawString("The Tournament!", (getWidth() / 2 + 1) - j4, (3 - j4) + g1.getFont().getHeight() * 2, 0x10 | 0x1);
// else
// g1.drawString("The Survival!", (getWidth() / 2 + 1) - j4, (3 - j4) + g1.getFont().getHeight() * 2, 0x10 | 0x1);
}
}
}
/**
* 按键响应
* @param i1 int,按键代码
*/
protected void keyPressed(int i1)
{
//System.out.println("**i1 = " + i1);
if(I)
{
h.stopThread();
setGamePlayer(player1.getPlayer(), player2.getPlayer());
return;
}
if(i1 == -6) {
a = System.currentTimeMillis();
P.initGameHelpMenu();
}
if(i1 == 52 || i1 == -3){
player1.playerAction(1);
} else
if(i1 == 54 || i1 == -4)
{
player1.playerAction(2);
} else
if(i1 == 50 || i1 == -1)
{
player1.playerAction(3);
} else
if(i1 == 56 || i1 == -2)
{
player1.playerAction(4);
} else
if(i1 == 51)
{
player1.playerAction(5);
} else
if(i1 == 49)
{
player1.playerAction(6);
} else
if(i1 == 57)
{
player1.playerAction(7);
} else
if(i1 == 55)
{
player1.playerAction(8);
} else
if(i1 == 53 || i1 == getKeyCode(8))
{
player1.judgeSkill();
} else
if(i1 == 42)
P.setSoundState();
}
/**
* 按键释放响应
* @param i1 int,按键代码
*/
protected void keyReleased(int i1)
{
if(player1.getState() == 1 || player1.getState() == 2)
player1.playerAction(0);
}
/**
* 声音播放函数
* @param i1 int,声音状态
*/
public void start(int i1){
if(P.setting[0] == 1)
try
{
if(F.getState() != 1)
try
{
F.stop();
}
catch(Exception exception)
{
System.out.println(exception);
}
F.release();
F.init(j[i1], 1);
F.play(1);
} catch(Exception exception1) {
System.out.println(exception1);
}
}
/**
* 设定游戏角色
* @param i1 int,角色1
* @param j1 int,角色2
*/
public void setGamePlayer(int i1, int j1)
{
M = false;
m = false;
I = false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -