📄 ictankcanvas.java
字号:
/*
* @(#)icTankCanvas.java 0.20 02/11/07
* Copyright (c) 2002 InterScape Creations. All Rights Reserved.
*/
import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import com.nokia.mid.ui.FullCanvas;
import com.nokia.mid.sound.Sound;
import java.util.TimerTask;
import java.util.Timer;
import java.util.Random;
import java.util.Vector;
public class icTankCanvas
extends FullCanvas
implements Runnable {
public static Graphics G = null;
private final SuperTank parent;
Display display;
ChoiceGroup yChoice;
private int fadeCol = 0;
private boolean fadein = true;
private Form scoreForm; // form for scores
private TextBox levelText; // for input of new level
Hero hero;
private Bullet[] bullet;
private Enemy[] enemy;
private Enemy[] backenemy;
private Enemy[] enemyNormal;
private Enemy[] enemyGreen;
private byte beginlist[] = new byte[105];
Sound sD[];
Sound s;
int numEnemy;
int liveCount;
boolean newFlag = false;
boolean pauseStart = false;
boolean canmove;
boolean enemyover;
icTimer ictimer;
icTimer overtimer;
icTimer ictimer1;
icTimer tankout;
int enemyout;
int iii = 0;
Timer MyTimer = new Timer();
volatile Thread animationThread = null;
int gameStatus;
int width, height;
int menuSelect;
public int mapInfo[] = new int[ (52 * 52)];
public int mapInfoFormer[] = new int[ (52 * 52)];
//add by johnson
boolean reDraw;
boolean paused;
public boolean paused1;
boolean pauseBack;
int life;
int level;
int fontHeight;
int fontWidth;
//private int score;
boolean gameWin, gameLose;
boolean bigScreen = false;
Image logo, t_logo;
Image ic;
Image helpImage;
int frameWidth, frameHeight;
int mapWidth, mapHeight;
int mapOffsetX, mapOffsetY;
int dataOffsetX, dataOffsetY;
int gameSubStatus;
int gameSelect = 1;
char password[] = new char[4];
int passPos = 1;
int pasLevel;
boolean ifTimer;
boolean homeWall;
Symbol symboll = new Symbol();
Image bombImage;
boolean bombFlag;
boolean cap;
Vector tempPos = new Vector();
//record the mark
int totalMark;
int sessionMark;
int normalNum;
int redNum;
int greenNum;
int superNum;
int bonusMark;
private static char[] levelPas = {
'a', 'F', 'g', '2',
'e', '6', '2', 'a',
'G', 'f', 'a', '6',
'j', 'A', '7', '4',
'7', '1', 'v', 'h',
'n', '0', 'G', '6',
'D', '7', 'k', '7',
'4', 'A', 'g', '4',
'B', 'f', 'B', '9',
'h', 'k', 'a', 'J',
'k', 'h', '3', '1',
'A', '3', 'F', '7',
'c', 'l', 'd', 'J',
'8', 'R', 'e', 'e',
'd', 'f', 'h', 'f',
'7', 'g', 'V', 'c',
'n', 'J', 'T', '6',
'S', 'H', '3', 'I',
'9', 'j', 'S', 'p',
// 'q','L','d','3' };
'B', 'A', 'A', 'A'};
Image title;
Image map;
Image map1;
Image tile1;
Image tile2;
Image tile3;
Image tile4;
Image victor;
Image logo1;
Image logo2;
Image logo3;
Image winlose;
int title_x, title_y;
int title_w, title_h;
int tileW;
int tileWidth, tileHeight;
public boolean firstTime = true;
private boolean showLevel = true;
boolean shootFlag = false;
boolean grassPaint = false;
//add by johnson to realize adding new enemy
int timeCount;
int maxShowEnemy = 7;
//boolean enemyAlive[] = new boolean[3];
boolean enemyAlive[] = new boolean[maxShowEnemy]; //modified by johnson
boolean bulletAlive[] = new boolean[3];
int maxEnemy, maxBullet;
final int MAX_NUM = 15;
// int[] enemyGroup0={0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0};
int[] enemyGroup = {
0, 0, 0, 2, 1, 3, 2, 0, 2, 1, 0, 3, 3, 2, 1, 0, 0, 0, 0, 0};
int numPos = 0;
LoadAnimator loadAnimator;
public icTankCanvas() {
this.parent = null;
}
public icTankCanvas(SuperTank parent, Display dis) {
this.parent = parent;
// this.display = display;
loadAnimator = new LoadAnimator(dis, this);
}
String msg = null;
public void run() {
int MAX_TIME = 20;
loadAnimator.play(); //启动动画
loadAnimator.getnownum(1);
ImageHelper helper = new ImageHelper();
loadAnimator.getnownum(2);
ictimer = new icTimer();
overtimer = new icTimer();
ictimer1 = new icTimer();
MyTimer.schedule(ictimer, 50, 1000);
MyTimer.schedule(overtimer, 50, 1000);
MyTimer.schedule(ictimer1, 50, 1000);
hero = new Hero();
reDraw = false;
bullet = new Bullet[3];
enemy = new Enemy[MAX_NUM];
backenemy = new Enemy[MAX_NUM];
enemyNormal = new Enemy[4];
enemyGreen = new Enemy[4];
level = 1;
menuSelect = 1;
maxEnemy = 3;
maxBullet = 3;
//add by johnson
timeCount = 0;
//maxShowEnemy =10;
ifTimer = false;
homeWall = false;
pauseBack = false;
liveCount = 0;
width = getWidth();
height = getHeight();
initLevel();
loadAnimator.getnownum(3);
for (int i = 0; i < MAX_NUM; i++) {
enemy[i] = new Enemy(enemyGroup[i]);
}
for (int i = 0; i < MAX_NUM; i++) {
backenemy[i] = enemy[i];
}
for (int i = 0; i < 4; i++) {
enemyNormal[i] = new Enemy(0);
}
for (int i = 0; i < 4; i++) {
enemyGreen[i] = new Enemy(2);
}
loadAnimator.getnownum(4);
/* for ( int i = 0; i < maxEnemy; i ++ ){
// enemy[i] = new Enemy(0);
enemy[i].alive = true;
enemyAlive[i] = true;
}*/
//add by johnson
for (int i = maxEnemy; i < maxShowEnemy; i++) {
enemyAlive[i] = false;
}
for (int i = 0; i < maxBullet; i++) {
bulletAlive[i] = false;
bullet[i] = new Bullet();
}
life = 3;
gameStatus = 1; //2; //1--title 2--intro 3--game 4--outro 5--game over
gameSubStatus = 1;
title_w = 0;
Font ft = Font.getDefaultFont();
fontHeight = ft.getHeight();
fontWidth = 40;
loadAnimator.getnownum(5);
paused = false;
ictimer.timeCounter = 0;
//initial the mark
totalMark = 0;
sessionMark = 0;
normalNum = 0;
redNum = 0;
greenNum = 0;
superNum = 0;
bonusMark = 0;
// Load the background image
try {
//logo = Image.createImage("/ic_logo.png");
//ic = Image.createImage("/interscape.png");
bombImage = Image.createImage("/explode.png");
helpImage = Image.createImage("/help.png");
}
catch (Exception exception) {
System.out.println(exception);
}
loadAnimator.getnownum(6);
setBeginSound();
sD = new Sound[2];
setSound("dynamite.wav", 0);
setSound("fire.wav", 1);
// Load the title image
try {
logo1 = Image.createImage("/type1.png");
logo2 = Image.createImage("/type2.png");
logo3 = Image.createImage("/smile.png");
}
catch (Exception exception) {
System.out.println(exception);
}
loadAnimator.getnownum(7);
loadAnimator.isover();
Thread currentThread = Thread.currentThread();
int gameSpeed = 100;
try {
// This ends when animationThread is set to null, or when
// it is subsequently set to a new thread; either way, the
// current thread should terminate
while (currentThread == animationThread) {
/* if(paused1){
// System.out.println("pause here");
try {
wait();
}
catch (Exception ex) {}
}
else{*/
if (gameStatus == 3) {
gameSpeed = 70;
}
else {
gameSpeed = 50;
}
long startTime = System.currentTimeMillis();
repaint(0, 0, getWidth(), getHeight());
serviceRepaints();
long timeTaken = System.currentTimeMillis() - startTime;
//System.out.println("timeTaken="+timeTaken);
if (timeTaken < gameSpeed) {
synchronized (this) {
wait(gameSpeed - timeTaken);
}
}
}
// }
}
catch (InterruptedException e) {
}
}
protected void paint(Graphics g) {
switch (gameStatus) {
case 1: //title
titlePaint(g);
break;
case 2: //intro
introPaint(g);
break;
case 3: //game
gamePaint(g);
break;
case 4: //result
resultPaint(g);
break;
case 5: //game over
default:
break;
}
// repaint(0, 0, getWidth(), getHeight());
}
public void keyPressed(int keyCode) {
int j = getGameAction(keyCode);
switch (gameStatus) {
case 1: //title
switch (keyCode) {
case -7:
paused1 = true;
parent.showOption();
break;
default:
break;
}
case 2: //Game Select
if (gameSubStatus == 3) {
switch (j) {
case Canvas.LEFT:
case Canvas.UP:
if (gameSelect > 1) {
gameSelect--;
}
else {
gameSelect = 2;
}
break;
case Canvas.RIGHT:
case Canvas.DOWN:
if (gameSelect < 2) {
gameSelect++;
}
else {
gameSelect = 1;
}
break;
case Canvas.FIRE:
if (gameSelect == 1) {
gameSubStatus = 4;
}
if (gameSelect == 2) {
gameSubStatus = 5;
}
default:
break;
}
}
else if (gameSubStatus == 6) {
switch (j) {
case Canvas.LEFT:
if (passPos > 1) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -