⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mygamecanvas.java

📁 一个小游戏.可以在手机上用的
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 *
 * </p>
 * <p>
 * Copyright: Copyright (c) 2005
 * </p>
 * <p>
 * Company:
 * </p>
 * 非作者授权,请勿用于商业用途。
 * @author bruce.fine@gmail.com
 * @version 1.0
 */

import javax.microedition.lcdui.*;

// import com.nokia.mid.ui.DirectUtils;

import java.io.*;
import java.util.*;

public final class MyGameCanvas extends MyCanvas {
	//
	//
	static Image imageFire = null;
	static Anim animFire = null;
	//
	static Image imageSuc = null;
	static Image imageFailuer = null;
	static Image imageX = null;

	//
	int nPowerCMax = 1;
	int nBombNumCMax = 1;

	// Anim animBullet = null;
	Anim animLisa = null;
	Anim animSaving = null;
	Anim animZZ = null;
	Anim animMouse = null;
	Anim animBf = null;

	//
	Anim animHead = null;
	Anim animBody = null;
	Anim animEnd = null;
	//
	Image imageWugong = null;
	Image imageBf = null;
	static Image imageCi = null;

	//
	static MyGameCanvas instance;

	//
	static final short SN_TEXT_NUM_PER_ROW = 7;
	static short SN_TEXT_ROWS_NUM_MAX = 0;
	static short SN_TEXT_TOP_Y = 0;
	static short SN_CHAR_WIDTH = 0;
	static short SN_CHAR_HEIGHT = 0;
	static short SN_TEXT_TOP_X = 0;
	static short SN_TEXT_DIS = 0;

	// GLOBAL
	/*
	 * 状态管理
	 */
	static final byte SB_STATE_LOADING = 0;
	static final byte SB_STATE_SPLASH = 1;
	static final byte SB_STATE_MENU = 2;
	static final byte SB_STATE_GAMEING = 3;
	static final byte SB_STATE_STORY_TELLING = 4;

	/**
	 * bState状态管理器
	 */
	static byte sbState = SB_STATE_LOADING;
	static byte sbStateToLoad = SB_STATE_LOADING;

	// 键盘
	static int snKeyCodePressed = 0;
	static int snKeyCodeReleased = 0;

	// Font
	static Font font = null;

	static int snLevelOpened = 0;

	// ------------------------------------------------------------------------------------------
	// SPLASH 控制管理
	// ------------------------------------------------------------------------------------------
	static int nSlpashTimerC = 0;

	// ------------------------------------------------------------------------------------------
	// LOADING 控制管理
	// ------------------------------------------------------------------------------------------
	// static int nLoadingTimerC = 0;

	// ------------------------------------------------------------------------------------------
	// MENU 控制管理
	// ------------------------------------------------------------------------------------------
	String[] strrTextShows = null;
	String[] strrTextForAbout = null;
	String[] strrTextForHelp = null;

	int nPointerStrrTextShow = 0;

	String[] strrMenu = { "开始游戏", "帮助", "关于", "退出" };

	int nPointerStrrMenu = 0;

	boolean isStrrMenuButtonClicked = false;

	//
	static Image imageUp = null;
	static Image imageDown = null;
	static Image imageLeft = null;
	static Image imageRight = null;

	//

	// ------------------------------------------------------------------------------------------
	// GAME 控制管理

	boolean isGameWin = false;
	boolean isMenuInGameWorked = false;
	boolean isFoorsMenuWorked = false;
	boolean isScriptWorking = false;
	boolean isKeyReponseMenu = false;

	//
	String[] strMenuFoors = { "状态", "道具", "帮助" };

	int nPStrMenuFoors = 0;

	String[] strrFoos = { "蜂蜜", "水果", "蜂王浆", "甘露", "灵芝草", "人参" };

	/**
	 * 
	 * num_foos 分别有: 补血:蜂蜜,水果,蜂王浆 补气:灵芝草,人参,甘露
	 * 
	 */
	int[] num_foos = new int[] { 10, 10, 10, 10, 10, 10 };
	int nPStrrFoos = 0;
	int nStarPointer = 0;
	int nPoundPointer = 3;

	// 这个也需要记录

	// 非BOSS场景
	String[] strrMenuInGame = { "继续游戏", "回主菜单", "退出游戏" };
	String[] strrMenuInGameResultFailur = { "重新游戏", "回主菜单", "退出游戏" };
	String[] strrMenuInGameResultWin = { "继续挑战", "回主菜单", "退出游戏" };
	// BOSS场景
	String[] strrMenuInGameBOSS = { "继续游戏", "回主菜单", "退出游戏" };

	int nPorintStrrMenuInGame = 0;

	//
	short nMapId = 0;

	//
	boolean isMenuInGameForState = false;

	// 地图控制区域
	// static Image[] imageTiles = null;

	// 地图绝对坐标
	static int snWindowX = 0;
	static int snWindowY = 0;
	//
	static int snMapWidth = 0;
	static int snMapHeight = 0;

	//
	static byte[][] snsTiles = null;
	// static boolean[][] sisTilesNull = null;
	static int snTilesWidthNum = 0;
	static int snTilesHeightNum = 0;

	static int snMapX = 0;

	static int snMapY = 0;

	static int snTilesWidthNumInScreen = 0;

	static int snTilesHeightNumInScreeen = 0;

	static int snMapAreaWidthInScreen = 0;

	static int snMapAreaHeightInScreen = 0;

	// 滚动屏幕
	static boolean isScrollMapLeft = false;

	static boolean isScrollMapRight = false;

	static boolean isScrollMapUp = false;

	static boolean isScrollMapDown = false;

	//
	static Image imageSps = null;

	static Image imageBox = null;

	static Vector vecticUnits = null;

	// static Image imageRabit = null;

	static Image imageSaving = null;

	static Image imageZZ = null;

	static Image imageMouse = null;

	static Image imageBall = null;

	static Image imageDoor = null;

	static Image imageMap = null;

	// static MyImage[] myImage1d = null;

	static Image imageBomb = null;

	Anim animBomb = null;

	//

	int nTimerForDynTiles = 0;

	static final int SN_TIMER_FOR_DYN_TILES_MAX = 2;

	int nPointerDynTiles = 0;

	static final int SN_DYN_TILES_MAX = 3;

	//
	NPC npcLisa = null;

	CPC cpc = null;

	CPC cpc2 = null;

	// 数据控制,各种任务,对话等的标志位
	/***************************************************************************
	 * 门是否被开启 是否找到钥匙
	 * 
	 */
	byte[] data1D = null;

	short[][] dataxy2d = null;

	// 道具

	// 任务用的道具
	int[] num_foos_task = null;

	int n_money = 0;

	// 对话控制
	//
	short nDialogWindowX = 0;

	short nDialogWindowY = 0;

	short nDialogWindowWidth = 0;

	short nDialogWindowHeight = 0;

	short nDialogWindowTextX = 0;

	short nDialogWindowTextY = 0;

	short nFontHeight = 0;

	short nFontDisY = 2;

	//

	boolean isDialogWorking = false;

	int page = 0;

	static final int ROW = 2;

	int lastpage = 0;

	String[] strDialog1D = null;

	//
	// 天气系统
	// 天气状况是否打开
	int nRainOrSnow = 0; // 0 -> null, 1 -> rain, 2 -> snow

	int[][] nRainOrSnowXY = null;

	//
	static boolean isStoryModeWorking = false;

	String[] strStory = null;

	short nLine = 0;

	short nLineMax = 0;

	short nLengthMax = 0;

	short nTimerStory = 0;

	short nTimerStoryMax = 0;

	Random random = null;

	//
	int nTileWidth = Consts.SN_TILE_WIDTH;

	int nTileHeight = Consts.SN_TILE_HEIGHT;

	int nTileWidthForCalc = nTileWidth * 10;

	int nTileHeightForCalc = nTileHeight * 10;

	//

	//

	public void initStory() {

		strStory = new String[] { "Lisa是太阳神", "的第7个女儿,", "她聪明伶俐,生", "活在梦幻之地的",
				"幽幽山谷中。她", "拥有魔法,却爱", "心十足,她心灵", "美好,却不屈服", "于黑暗。一天怪",
				"怪之森的恶魔", "Bruce偷走了月", "亮和星星,太阳", "不得不加班工作", ",天使传信给",
				"Lisa,让她带着", "父亲给她的泡泡", "魔法前去与怪怪", "之森的恶魔", "Bruce战斗,夺",
				"回月亮和星星。" };
		nLine = (short) -SN_TEXT_ROWS_NUM_MAX;
		nLineMax = (short) (strStory.length);
		nTimerStoryMax = 10;
		nTimerStory = 0;
	}

	public void initDialog() {
		page = 0;
		isDialogWorking = true;
		strDialog1D = new String[] { "我就是传说中的上帝", ",现在赐予你力量,", "杀死 Bruce,人们",
				"为你祈福." };
		if (strDialog1D.length % ROW == 0) {
			lastpage = (strDialog1D.length / ROW) - 1;

		} else {
			lastpage = (strDialog1D.length / ROW);
		}
	}

	public void freeStrDialog() {
		if (isScriptWorking) {
			isScriptDialogWorked = true;
		}

		isDialogWorking = false;
		strDialog1D = null;
		lastpage = 0;
		page = 0;
	}

	// 对话控制结束
	/**
	 * 内部资源管理类实例
	 */

	LoadingGameRes loadingGameRes = null;

	static int nGameScore = 0;

	/**
	 * 构造
	 */
	public MyGameCanvas() {

		instance = this;
		isFivePressed = false;
		font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
				Font.SIZE_MEDIUM);
		random = new Random();
		//

		SN_CHAR_WIDTH = (short) font.getHeight();
		SN_CHAR_HEIGHT = (short) font.getHeight();
		SN_TEXT_DIS = (short) (font.getHeight() / 6); // 单距
		SN_TEXT_ROWS_NUM_MAX = (short) (Consts.SN_SCREEN_HEIGHT
				/ (SN_CHAR_HEIGHT + SN_TEXT_DIS) - 3);
		SN_TEXT_TOP_X = (short) ((Consts.SN_SCREEN_WIDTH - SN_CHAR_WIDTH
				* SN_TEXT_NUM_PER_ROW) >> 1);
		SN_TEXT_TOP_Y = (short) (SN_CHAR_HEIGHT + SN_TEXT_DIS + SN_CHAR_HEIGHT / 2);
		// INITGLOBAL
		sbState = SB_STATE_SPLASH;

		try {
			int tempWidth = (short) (font.stringWidth("高") * SN_TEXT_NUM_PER_ROW);
			nFontHeight = (short) font.getHeight();
			nFontDisY = 4;
			int nFontDisX = 8;
			nDialogWindowWidth = (short) (tempWidth + nFontDisX * 2);
			nDialogWindowHeight = (short) ((nFontHeight + nFontDisY) * ROW + nFontDisY);

			nDialogWindowX = (short) ((Consts.SN_SCREEN_WIDTH - nDialogWindowWidth) / 2);
			nDialogWindowY = (short) ((Consts.SN_SCREEN_HEIGHT - nDialogWindowHeight) - 1);
			nDialogWindowTextX = (short) (nDialogWindowX + nFontDisX);
			nDialogWindowTextY = (short) (nDialogWindowY + nFontDisY);

		} catch (Exception ex) {
			int tempWidth = (short) (16 * SN_TEXT_NUM_PER_ROW);
			nFontHeight = (short) 16;
			nFontDisY = 4;
			int nFontDisX = 8;
			nDialogWindowWidth = (short) (tempWidth + nFontDisX * 2);
			nDialogWindowHeight = (short) ((nFontHeight + nFontDisY) * ROW + nFontDisY);

			nDialogWindowX = (short) ((Consts.SN_SCREEN_WIDTH - nDialogWindowWidth) / 2);
			nDialogWindowY = (short) ((Consts.SN_SCREEN_HEIGHT - nDialogWindowHeight) - 1);
			nDialogWindowTextX = (short) (nDialogWindowX + nFontDisX);
			nDialogWindowTextY = (short) (nDialogWindowY + nFontDisY);
		}
	}

	/**
	 * 清理资源
	 */
	final void freeAllResource() {
		// All of Resources will be free here
		strrTextShows = null;
		strrTextForHelp = null;
		strrTextForAbout = null;
		//
		imageUp = null;
		imageDown = null;
		imageLeft = null;
		imageRight = null;
		//
		// imageTiles = null;
		//
		imageSps = null;

		vecticUnits = null;
		//
		//
		npcLisa = null;
		cpc = null;
		cpc2 = null;
		imageBox = null;
		// imageRabit = null;
		imageSaving = null;
		imageZZ = null;
		imageMouse = null;
		imageDoor = null;
		imageBomb = null;
		// animBullet = null;
		animBomb = null;
		animLisa = null;
		animSaving = null;
		animZZ = null;
		animBf = null;
		animMouse = null;
		//
		animHead = null;
		animBody = null;
		animEnd = null;
		imageWugong = null;
		imageBf = null;
		vecticUnits = null;
		imageFire = null;
		animFire = null;
		imageSuc = null;
		imageFailuer = null;
		imageX = null;
		//	
	}

	boolean isFivePressed = false;

	/**
	 * 载入
	 */
	final void initResource() {
		switch (sbStateToLoad) {
		case SB_STATE_SPLASH: {
		}
			break;
		case SB_STATE_MENU: {
			try {
				//
				imageUp = Image.createImage("/res/up.png");
				imageDown = Image.createImage("/res/down.png");
				imageLeft = Image.createImage("/res/left.png");
				imageRight = Image.createImage("/res/right.png");
				//
				strrTextForAbout = new String[]{"bruce.fine", "@gmail.com:)"};

				strrTextForHelp = new String[]{"我的梦幻", "炸弹人设计:)"};
				//
				nPointerStrrTextShow = 0;
				nPointerStrrMenu = 0;
				isStrrMenuButtonClicked = false;
				//
				snLevelOpened = RMSSystem.loadLevelOpened();
				// System.out.println("snLevelOpened:" + snLevelOpened);
				if (snLevelOpened > Consts.SN_ABS_MAX_LEVEL) {
					//
					snLevelOpened = Consts.SN_ABS_MAX_LEVEL;
					nMapId = 0;
				} else {
					//
					nMapId = (short) (snLevelOpened + 1);
				}

				//

				initWindowShow(10, 5);

			} catch (Exception ex) {
				ex.printStackTrace();
			}

		}
			break;
		case SB_STATE_GAMEING: {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -