📄 game.java
字号:
}
/*if (Menu.soundEnabled()) {
//System.out.println("====run=====close==1=");
// Game.sound.close();
// try {
// Thread.sleep(20L);
// } catch (Exception exception) {
// }
Game.sound.getPlayer(2);
//System.out.println("====run=====close==2=");
}*/
while (running) {
if (!isShown() && isShown)
isShown = false;
else if (isShown() && !isShown)
isShown = true;
landscape.assignCenter();
try {
Thread.sleep(20L);
} catch (Exception exception) {
}
check_watchdog();
if (surrenderFrameDirection == 0)
surrenderFrame++;
else
surrenderFrame--;
if (surrenderFrame > 2) {
surrenderFrame = 1;
surrenderFrameDirection = 1;
}
if (surrenderFrame < 0) {
surrenderFrame = 1;
surrenderFrameDirection = 0;
}
if (!paused) {
check_watchdog();
particleSystem.runFrame();
check_watchdog();
for (int i = 0; i < teams.length; i++) {
//System.out.println("====game===i===="+i);
teams[i].runFrame();
}
Weapon.runFrame();
for (int j = 0; j < cloudX.length; j++)
if (windFactor > 0)
cloudX[j] = (cloudStartX[j] + curFrame / (8 - j % 3))
% (300 + cloud.width + 60) - 30;
else
cloudX[j] = (cloudStartX[j] + curFrame / (8 + j % 3))
% (300 + cloud.width + 60) - 30;
check_watchdog();
for (int k = 0; k < teams.length; k++)
if (teams[k].isDead())
running = false;
if (endTurn) {
boolean flag = true;
for (int l = 0; l < teams.length; l++) {
for (int i1 = 0; i1 < teams[l].wormList.length; i1++) {
teams[l].wormList[i1].setIdle();
if (!teams[l].wormList[i1].healthCountDownOK())
flag = false;
}
}
if (flag) {
if (endTurnTime == -1L)
endTurnTime = Worms.getTime();
if (Worms.getTime() - endTurnTime > 1000L
|| !endTurnPause) {
activeTeam ^= 0x1;
teams[activeTeam].endTurn();
teams[activeTeam].activateNextWorm();
//System.out.println("====game==run====activateNextWorm===========");
for (int j1 = 0; j1 < teams.length; j1++)
teams[j1].resetHealthCountDown();
windFactor = Math.abs(random.nextInt()) % 512 - 256;
particleSystem.setWind(windFactor);
endTurn = false;
startTurnTime = Worms.getTime();
LastGetTime = startTurnTime;
}
}
}
}
//runCount++;
//新加
if (Worms.runTimes == 0) {
runCount++;
if (m < run.length) {
int count[] = run[m];
if (count[2] == runCount) {
press = true;
if (count[0] == 1) {
keyPressed(count[1]);
} else {
keyReleased(count[1]);
}
press = false;
m++;
}
} else {
//Worms.runTimes++;
pauseLostTeam = -2;
press = true;
running = false;
runCount = 0;
m = 0;
}
}
initialized = true;
if (counter % 2 == 0)
repaint();
//System.out.println("=====counter===="+counter);
counter++;
}
if (pauseLostTeam == -1 && Worms.runTimes != 0 ) {
System.out.println("=======isplay=======");
if (Menu.soundEnabled() ) {
//sound.close();
sound.getPlayer(4);
sound.start();
//sound.close();
/*
* try { sound_VICTORY.start(); } catch (MediaException
* mediaexception1) { }
*/
try {
Thread.sleep(500L);
} catch (Exception exception1) {
}
}
if (teams[1].isDead())
pauseLostTeam = 0;
else
pauseLostTeam = 1;
}
try {
Thread.sleep(100L);
} catch (Exception exception1) {
}
check_watchdog();
/*if (Menu.soundEnabled()) {
//sound_THEMETUNE.start();
//sound.close();
Game.sound.getPlayer(1);
Game.sound.start();
}*/
}
public void paint(Graphics g) {
check_watchdog();
if (!initialized) {
g.setColor(255, 255, 255);
g.fillRect(0, 0, screenWidth, screenHeight);
return;
}
g.setClip(0, 0, screenWidth, screenHeight);
windIndicatorG = windIndicatorI.getGraphics();
if (!initialized) {
g.setColor(255, 255, 255);
g.fillRect(0, 0, screenWidth, screenHeight);
return;
}
if (state == 0) {
g.setColor(93, 191, 227);
g.fillRect(0, 0, screenWidth, screenHeight);
landscape.paint(g);
for (int i = 0; i < 360 / water.width + 4; i++) {
water.setPosition(((-32 + Landscape.levelX) - (curFrame / 2)
% water.width)
+ i * water.width, ((Landscape.levelY + 150)
- water.height - 6) + 10);
water.paint(g);
}
check_watchdog();
for (int j = 0; j < teams.length; j++)
if (j != activeTeam)
teams[j].paint(g);
teams[activeTeam].paint(g);
particleSystem.paint(g);
Weapon.paint(g);
for (int k = 0; k < cloudX.length; k++) {
cloud.setPosition(cloudX[k] + Landscape.levelX, cloudY[k]
+ Landscape.levelY);
cloud.paint(g);
}
for (int l = 0; l < 360 / water.width + 4; l++) {
water.setPosition(((-32 + Landscape.levelX) - curFrame
% water.width)
+ l * water.width,
((Landscape.levelY + 150) - water.height) + 10);
water.paint(g);
}
check_watchdog();
Worm.medic.setPosition(2, 4);
Worm.medic.paint(g);
String s = "" + teams[activeTeam].getActiveWorm().getHealth();
FontRender.writeString(g, s, 16, 3);
tag_cx = g.getClipX();
tag_cy = g.getClipY();
tag_cw = g.getClipWidth();
tag_ch = g.getClipHeight();
g.setClip(screenWidth - 26, 2, 26, 19);
// System.out.println("=====currentWormActiveWeapon==="+currentWormActiveWeapon);
// System.out.println("=====currentWormAmmoCount==="+currentWormAmmoCount);
g.drawImage(Weapon.WeaponIcons, screenWidth - 26
- currentWormActiveWeapon * 26, 2, 20);
if (currentWormActiveWeapon > 0)
FontRender.writeString(g, Integer
.toString(currentWormAmmoCount),
(screenWidth - 26) + 1, 3);
g.setClip(tag_cx, tag_cy, tag_cw, tag_ch);
byte byte0 = 5;
byte byte1 = 35;
byte byte2 = 18;
int i1 = screenHeight - byte2 - 5;
check_watchdog();
if (!Weapon.isActive() && !endTurn) {
g.setColor(0, 0, 0);
g.fillRoundRect(byte0, i1, byte1, byte2, 6, 6);
g.setColor(0, 0, 0);
g.fillRoundRect(byte0, i1 - 7, byte1, 9, 6, 6);
g.setColor(128, 60, 0);
g.drawRoundRect(byte0 + 2, (i1 + 2) - 7, byte1 - 4, 7, 6, 6);
g.drawRoundRect(byte0 + 2, i1 + 2, byte1 - 4, byte2 - 4, 6, 6);
//System.out.println("======paint===timeleft===="+timeLeft);
FontRender.writeString(g, "" + timeLeft, byte0
+ (byte1 - FontRender.stringWidth("" + timeLeft)) / 2,
1 + i1 + (byte2 - 11) / 2);
windIndicatorG.setColor(0, 0, 0);
windIndicatorG.fillRect(0, 0, windIndicatorI.getWidth(),
windIndicatorI.getHeight());
int j1 = Math.abs(windFactor) >> 4;
if (j1 > 15)
j1 = 15;
if (j1 < 1)
j1 = 1;
boolean flag = false;
if (windFactor > 0) {
windIndicatorG.setClip(15, 0, j1, windIndicatorI
.getHeight());
for (int k1 = 5; k1 < 30; k1 += 5) {
windIconRed.setPosition(k1 + (curFrame / 2) % 5, 0);
windIconRed.paintRaw(windIndicatorG);
}
} else {
windIndicatorG.setClip(15 - j1, 0, j1, windIndicatorI
.getHeight());
for (int l1 = 0; l1 < 20; l1 += 5) {
windIconBlue.setPosition(l1 - (curFrame / 2) % 5, 0);
windIconBlue.paintRaw(windIndicatorG);
}
}
g.drawImage(windIndicatorI, 8, screenHeight - 27, 20);
}
byte byte3 = 0;
if (teams[0].humanTeam && teams[1].humanTeam) {
byte3 = 0;
if (!teams[activeTeam].redTeam)
byte3 = 1;
} else {
byte3 = 0;
if (!teams[activeTeam].humanTeam)
byte3 = 2;
}
check_watchdog();
if (Worms.getTime() % 512L > 256L
&& Worms.getTime() - startTurnTime < 3000L) {
player.setFrame(byte3);
player.setPosition(screenWidth - player.width - 2, screenHeight
- player.height - 2);
player.paint(g);
}
if (Worms.runTimes == 0) {
g.setColor(0);
String str = "按返回进入主菜单";
g.drawString(str, (screenWidth - font.stringWidth(str)) / 2,
screenHeight / 2 - 15, 0);
}
/*
* if(paused) { check_watchdog();
* surrender.setFrame(surrenderFrame);
* surrender.setPosition((screenWidth - surrender.width) / 2, 30);
* surrender.paint(g); icons.setFrame(1);
* icons.setPosition((screenWidth - icons.width) / 2 - (icons.width -
* 4), 70); icons.paint(g); teams[activeTeam].getActiveWorm(); Imp
* imp = Worm.crosshair; if(pauseMenuItem == 0)
* imp.setPosition(icons.positionX - 10, icons.positionY - 10);
* icons.setFrame(0); icons.setPosition((screenWidth - icons.width) /
* 2 + (icons.width - 4), 70); icons.paint(g); if(pauseMenuItem ==
* 1) imp.setPosition(icons.positionX - 10, icons.positionY - 10);
* imp.paint(g); }
*/
}
curFrame++;
}
private void addGX10Softkeys(String s, String s1) {
/*if (GX10Command_LEFT != null && GX10Command_RIGHT != null
&& s == GX10Command_LEFT.getLabel()
&& s1 == GX10Command_RIGHT.getLabel()) {
System.gc();
return;
}*/
try {
removeCommand(GX10Command_LEFT);
GX10Command_LEFT = null;
removeCommand(GX10Command_RIGHT);
GX10Command_RIGHT = null;
if (s != "") {
GX10Command_LEFT = new Command(s, 2, 1);
addCommand(GX10Command_LEFT);
}
if (s1 != "") {
GX10Command_RIGHT = new Command(s1, 4, 1);
addCommand(GX10Command_RIGHT);
}
//System.out.println("======s======"+s);
//System.out.println("======s1======="+s1);
System.gc();
} catch (Exception exception) {
}
return;
}
public void commandAction(Command command, Displayable displayable) {
//动画演示时返回
if (command == GX10Command_BACK) {
//System.out.println("====game====GX10Command_BACK===");
//isPlay = true;
pauseLostTeam = -2;
//Worms.runTimes++;
press = true;
running = false;
runCount = 0;
m = 0;
} else {
//武器
if (command.getCommandType() == 2)
keyPressed(21);
//暂停
if (command.getCommandType() == 4)
keyPressed(22);
}
}
public void check_watchdog() {
//System.out.println("====game====check_watchdog===");
if (System.currentTimeMillis() - LastGetTime > 3000L) {
startTurnTime += System.currentTimeMillis() - LastGetTime;
Worm.turnStartTime += System.currentTimeMillis() - LastGetTime;
//System.out.println("====game===check_watchdog==Worm.turnStartTime="+Worm.turnStartTime);
timeLeft = 30 - (int) (System.currentTimeMillis() - Worm.turnStartTime) / 1000;
//System.out.println("====game===check_watchdog==timeLeft="+timeLeft);
}
LastGetTime = System.currentTimeMillis();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -