import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.InputStream;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.rms.RecordStore;
/**
* <p>Title: 游戏的画布</p>
*
* <p>Description: 负责绘制游戏的画面,接受用户的按键事件</p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: wodead</p>
*
* @author wodead
* @version 1.0
*/
public class Main extends GameCanvas implements Runnable {
//屏幕显示状态
public static final int STATUS_MAINMENU = 0;
public static final int STATUS_MISSION_SELECTING = 1;
public static final int STATUS_MISSION_RUNNING = 2;
public static final int STATUS_ABOUT = 3;
//任务状态
public static final int MISSION_PAUSE = 0;
public static final int MISSION_RUNNING = 1;
public static final int MISSION_FAIL = 2;
public static final int MISSION_COMPLETED = 3;
//游戏元素代号
public static final int FLOOR_HOT = 1;
public static final int FLOOR_ICE = 2;
public static final int FLOOR_TARGET = 3;
public static final int TOOL_BUCKET = 4;
public static final int TOOL_TORCH = 5;
public static final int TOOL_HAMMER = 6;
public static final int TOOL_WRENCH_CW = 7;
public static final int TOOL_WRENCH_CCW = 8;
public static final int TOOL_BOMB = 9;
public static final int TOOL_FAN_UP = 10;
public static final int TOOL_FAN_RIGHT = 11;
public static final int TOOL_FAN_DOWN = 12;
public static final int TOOL_FAN_LEFT = 13;
public static final int TOOL_LASER_UP = 14;
public static final int TOOL_LASER_RIGHT = 15;
public static final int TOOL_LASER_DOWN = 16;
public static final int TOOL_LASER_LEFT = 17;
public static final int TOOL_MIRROR_CW = 18;
public static final int TOOL_MIRROR_CCW = 19;
public static final int STUFF_BOMB = 25;
public static final int STUFF_FAN_UP = 26;
public static final int STUFF_FAN_RIGHT = 27;
public static final int STUFF_FAN_DOWN = 28;
public static final int STUFF_FAN_LEFT = 29;
public static final int STUFF_LASER_UP = 30;
public static final int STUFF_LASER_RIGHT = 31;
public static final int STUFF_LASER_DOWN = 32;
public static final int STUFF_LASER_LEFT = 33;
public static final int STUFF_MIRROR_CW = 34;
public static final int STUFF_MIRROR_CCW = 35;
public static final int STUFF_STONE = 36;
public static final int LASER = 64;
//当前屏幕显示状态
public int status;
//任务的当前执行状态
public static int missionStatus;
//游戏循环线程
private volatile Thread thread;
//副菜单显示状态
private static boolean subMenuVisible;
//主菜单当前选中的菜单项索引
private int mainMenuIndex;
//任务的页号
private int missionPageNum;
//当前选中的任务索引
private int missionSelectedIndex;
//副菜单当前选中的菜单项索引
private static int subMenuIndex;
//光标行位置
private int cursorRow;
//光标列位置
private int cursorColumn;
//主菜单菜单项的图片
private Image[] mainMenuItems = new Image[5];
//副菜单菜单项的图片
private static Image[] subMenuItems;
//游戏中需要使用的图片
public static Image[] word_numbers = new Image[10];
public static Image word_start;
public static Image word_continue;
public static Image word_setting;
public static Image word_about;
public static Image word_quit;
public static Image word_mission;
public static Image word_success;
public static Image word_failure;
public static Image word_back;
public static Image word_retry;
public static Image word_nextMission;
public static Image word_mainMenu;
public static Image image_logo;
public static Image image_hand;
public static Image image_arrow;
public static Image image_cup;
public static Image image_invalid;
public static Image image_explode;
public static Image[] image_floors = new Image[2];
public static Image image_hot;
public static Image image_ice;
public static Image image_target;
public static Image[] image_tools = new Image[16];
public static Image image_bomb;
public static Image image_mirror;
public static Image image_laser;
public static Image image_fan;
public static Image image_stone;
public static Image image_broking;
public static Image image_dweep;
public static Image image_firing;
public static Image image_description;
public static Image image_toolbar;
public static Image image_infobar;
public static Image image_menubar;
//任务开始的时间
private long startTime;
//一些动画
private Sprite iceFloor;
private Sprite hotFloor;
private Sprite targetFloor;
//存储按键信息
private int keyPressed;
//任务描述的显示位置,用于实现跑马灯效果
private int descriptionX;
//关于的文本
private static final String[] about = {"作者","wodead","版权","wodead,playxp@sohu.com","声明","创意、部分图片源于", "dexterity"};
//使用的字体
private Font font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_SMALL);
//一个增量用于实现闪现效果
private int incr;
//任务的总数
public static int missionCount;
//玩家记录
private static byte[] record;
//选中的工具索引
public static int selectedToolIndex = -1;
//地图信息
private static byte[] missionData = new byte[120];
//当前任务号
public static int missionNum;
//任务描述
public static String description;
//地面上的元素
public static int[][] base = new int[12][10];
//物体元素
public static Stuff[][] stuffs = new Stuff[12][10];
//道具包中的道具
public static int[] tools = new int[9];
//地面风格
public static int floor = 0;
//精灵
public static Dweep dweep;
//精灵初始行位置
public static int initRow;
//精灵初始列位置
public static int initColumn;
//道具包中预置的工具
public static byte[] initTools;
static Player[] players = new Player[5];
static int playersCount;
static Player player_win;
static Player nowPlayer;
/**
* 构造一个游戏任务界面
*/
public Main() {
super(false);
try {
// 全屏显示
setFullScreenMode(true);
for (int i = 0; i < players.length; i++) {
try {
players[playersCount] = Manager.createPlayer(getClass()
.getResourceAsStream(i + ".mid"), "audio/midi");
playersCount++;
} catch (Exception e) {
}
}
nowPlayer = players[0];
player_win = Manager.createPlayer(getClass().getResourceAsStream(
"win.mid"), "audio/midi");
// 初始化图片资源
// LOGO
image_logo = Image.createImage("/logo.png");
image_dweep = Image.createImage("/dweep.png");
// 文字和数字
Image words = Image.createImage("/words.png");
Image others = Image.createImage("/images.png");
image_stone = Image.createImage("/stone.png");
image_explode = Image.createImage("/explode.png");
image_fan = Image.createImage("/fan.png");
Image mirror = Image.createImage("/mirror.png");
image_laser = Image.createImage("/laser.png");
image_firing = Image.createImage("/firing.png");
image_toolbar = Image.createImage("/toolbar.png");