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

📄 gamemenu.java

📁 利用j2me所开发的一个角色扮演类游戏
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
						}
					}
				}
			} else if (currentMenuItemY == menuStartY + 24) {
				if (menuSelect == 0) {
					menuSelect = 1;
					com_Ok = new Command("返回", Command.OK, 0);
					com_Exit = new Command("清空记录", Command.EXIT, 0);
					this.addCommand(com_Ok);
					this.addCommand(com_Exit);
					this.setCommandListener(this);
				} else if (menuSelect == 2) {
					menuSelect = 0;
					currentMenuItemY = menuStartY;
				}
			} else if (currentMenuItemY == menuStartY + 24 * 2) {
				currentMenuItemY = menuStartY;
				menuSelect = 2;

			} else if (currentMenuItemY == menuStartY + 24 * 3) {
				menuSelect = 3;
				com_Ok = new Command("返回", Command.OK, 0);
				this.addCommand(com_Ok);
				this.setCommandListener(this);
			} else if (currentMenuItemY == menuStartY + 24 * 4) {
				menuSelect = 4;
				com_Ok = new Command("返回", Command.OK, 0);
				this.addCommand(com_Ok);
				this.setCommandListener(this);
			} else if (currentMenuItemY == menuStartY + 24 * 5) {
				menuSelect = 5;
				com_Ok = new Command("返回", Command.OK, 0);
				this.addCommand(com_Ok);
				this.setCommandListener(this);
			}

			else if (currentMenuItemY == menuStartY + 24 * (menuStr.length - 1)) {
				gameMain.exitGame();
			}
		}
	}

	private void showSorce(Graphics g) {
		g.setColor(255, 255, 255);
		g.fillRect(0, 0, this.getWidth(), this.getHeight());
		g.setColor(0x00FF0000);
		int tempShowX;// 保存信息从什么地方开始显示的位置坐标
		int tempShowY;
		Font font;
		font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD,
				Font.SIZE_LARGE);
		tempShowX = this.getWidth() / 2;
		tempShowY = 10;
		g.setFont(font);
		g.drawString("高分榜", tempShowX - 30, tempShowY, 0);
		tempShowY += font.getHeight();
		String[] names = score.getNames();
		int[] values = score.getValues();
		String result = "";
		for (int i = 0; i < names.length; i++) {
			result = (i + 1) + " " + names[i] + " - "
					+ GameCenter.asLongString(Integer.toString(values[i]), 6)
					+ "\n";
			g.drawString(result, tempShowX - 50, tempShowY, 0);
			tempShowY += font.getHeight() + 3;
		}
		this.flushGraphics();
	}

	private void showSettings(Graphics g) throws Exception {
		g.setColor(255, 255, 255);
		g.fillRect(0, 0, this.getWidth(), this.getHeight());
		g.setColor(0x00FF0000);
		g.drawImage(GameCenter.createImage("/menu.png"), 0, 0, 0);
		int tempShowX;// 保存信息从什么地方开始显示的位置坐标
		int tempShowY;
		Font font;
		font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD,
				Font.SIZE_LARGE);
		tempShowX = this.getWidth() / 2;
		tempShowY = 10;
		g.setFont(font);
		g.drawString("选项", tempShowX - 25, tempShowY, 0);
		tempShowY += font.getHeight();
		font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN,
				Font.SIZE_MEDIUM);
		g.setFont(font);
		int tempWidth = 120;
		int tempHeight = 18;
		int currentMenuY = menuStartY;
		int tempj = 0;
		menuSettingI = this.settings.sound;
		while (menuSetting.length - 1 >= tempj) {
			if (currentMenuItemY == currentMenuY) {
				drawFlashRound(g, tempWidth, tempHeight, currentMenuY,
						menuSetting[menuSettingI][tempj], isFlash);
				isFlash = false;
			} else {
				drawNotFlashRound(g, tempWidth, tempHeight, currentMenuY,
						menuSetting[menuSettingI][tempj]);
			}
			currentMenuY += 24;
			tempj++;
		}
		this.flushGraphics();
	}

	private void showGameRules(Graphics g) {
		g.setColor(255, 255, 255);
		g.fillRect(0, 0, this.getWidth(), this.getHeight());
		g.setColor(0x00FF0000);
		int tempShowX;// 保存信息从什么地方开始显示的位置坐标
		int tempShowY;
		Font font;
		font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD,
				Font.SIZE_LARGE);
		tempShowX = this.getWidth() / 2;
		tempShowY = 10;
		g.setFont(font);
		g.drawString("游戏规则说明", tempShowX - 42, tempShowY, 0);
		tempShowY += font.getHeight();
		font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
				Font.SIZE_MEDIUM);
		g.setFont(font);
		String result = "本游戏共8关,每一关的任务相同,都是玩家控制董永在地图上寻找七仙女,并且与七仙女相接触,则进入下一关,每一关都有时间限制,玩家必须要在规定的时间内完成,否则任务失败。操作方法:向左走-左方向键,向右走-右方向键,向下走-下方向键,向上走-上方向键,使用炸弹-菜单键。";
		int tempLength = result.length() / 20;
		for (int i = 0; i <= tempLength; i++) {
			g.drawString(result.substring(0, 19), 12, tempShowY, 0);
			result = result.substring(19);
			tempShowY += font.getHeight() + 3;
		}
		g.drawString(result, 10, tempShowY, 0);
		this.flushGraphics();
	}

	private void showGameBG(Graphics g) {
		g.setColor(255, 255, 255);
		g.fillRect(0, 0, this.getWidth(), this.getHeight());
		g.setColor(0x00FF0000);
		int tempShowX;// 保存信息从什么地方开始显示的位置坐标
		int tempShowY;
		Font font;
		font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD,
				Font.SIZE_LARGE);
		tempShowX = this.getWidth() / 2;
		tempShowY = 10;
		g.setFont(font);
		g.drawString("游戏背景", tempShowX - 42, tempShowY, 0);
		tempShowY += font.getHeight();
		font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
				Font.SIZE_MEDIUM);
		g.setFont(font);
		String result = "王母娘娘有七个女儿,七仙女私下凡间,爱上了秀才董永,但是这是有违天命的事情,于是董永和七仙女向各路神仙请求声援,在众神的向玉皇大帝求情的情况下,玉皇大帝设计了一个迷宫,只有董永能够连续破8关,就许诺把七仙女嫁给他。游戏玩家就要是扮演董永的角色就完成这一任务。";
		int tempLength = result.length() / 20;
		for (int i = 0; i <= tempLength; i++) {

			if (result.length() > 19) {
				g.drawString(result.substring(0, 19), 12, tempShowY, 0);
				result = result.substring(19);
			} else {
				g.drawString(result.substring(0, result.length() - 1), 12,
						tempShowY, 0);
				result = result.substring(result.length() - 1);
			}

			tempShowY += font.getHeight() + 3;
		}
		g.drawString(result, 10, tempShowY, 0);
		this.flushGraphics();
	}

	private void showGameCr(Graphics g) {
		g.setColor(255, 255, 255);
		g.fillRect(0, 0, this.getWidth(), this.getHeight());
		g.setColor(0x00FF0000);
		int tempShowX;// 保存信息从什么地方开始显示的位置坐标
		int tempShowY;
		Font font;
		font = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD,
				Font.SIZE_LARGE);
		tempShowX = this.getWidth() / 2;
		tempShowY = 10;
		g.setFont(font);
		g.drawString("版权", tempShowX - 42, tempShowY, 0);
		tempShowY += font.getHeight();
		font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
				Font.SIZE_MEDIUM);
		g.setFont(font);
		g.drawString("开发商:****科技有限公司", 12, tempShowY, 0);
		tempShowY += font.getHeight() + 3;
		g.drawString("2007****科技有限公司保留所有权利。", 12, tempShowY, 0);
		this.flushGraphics();
	}

	public void run() {
		Graphics g = this.getGraphics();
		while (isShowMenu) {
			if (menuSelect == 0) {
				try {
					keyControl();
				} catch (MediaException e) {

					e.printStackTrace();
				}
				showMenu(g);
				tempi++;
				if (tempi > 4)
					tempi = 0;

			} else if (menuSelect == 1) {
				showSorce(g);
			} else if (menuSelect == 2) {

				try {
					keyControl();
					showSettings(g);
				} catch (Exception e) {

					e.printStackTrace();
				}
				
				tempi++;
				if (tempi > 4)
					tempi = 0;

			} else if (menuSelect == 3) {
				showGameRules(g);
			} else if (menuSelect == 4) {
				showGameBG(g);
			} else if (menuSelect == 5) {
				showGameCr(g);
			}
			try {
				Thread.sleep(200);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

	}

	public void commandAction(Command c, Displayable d) {
		if (menuSelect == 1) {
			if (c.getCommandType() == Command.EXIT) {
				try {
					score.reset();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		this.removeCommand(com_Ok);
		this.removeCommand(com_Exit);
		menuSelect = 0;
	}

}

⌨️ 快捷键说明

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