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

📄 gameview.java

📁 我用WTK不能运行
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	}
	
	//绘制读取界面
	public void DrawLoad() {
//		DrawMap(bufGraphics);
//		bufGraphics.setColor(0xffff00);
		bufGraphics.fillRect(20, 20, Const.SCREEN_WIDTH - 2 * 20, Const.SCREEN_HEIGHT - 2 * 20);
//		this.DrawAlphaRect(0, 0, Const.SCREEN_WIDTH, Const.SCREEN_HEIGHT, 0x89ff00ff, bufGraphics);
		this.DrawAlphaRect(20, 20, Const.SCREEN_WIDTH - 2 * 20, Const.SCREEN_HEIGHT - 2 * 20, 0x89ffff00, bufGraphics);
		bufGraphics.setColor(0xff00ff);
		bufGraphics.drawString("读取记录", Const.SCREEN_WIDTH / 2, 30, Graphics.TOP | Graphics.HCENTER);
		bufGraphics.setColor(0);
		for(int i=1; i<4; i++) {
			bufGraphics.drawString("记录" + i + "      " + save[i-1], 25, 30 + 40 * i, Graphics.TOP | Graphics.LEFT);
		}
		
		this.DrawAlphaRect(20, 20 + (curIndex + 1) * 40, Const.SCREEN_WIDTH - 2 * 20, 40, 0x89ff0000, bufGraphics);
		this.DrawCommand(Const.COMMAND[3], Const.COMMAND[1]);
	}

	// ==========================END=====================
	// =====================相关界面按键处理=====================
	// 事件检测
	public void EventCheck() {
		switch (curScreenState) {
		case Const.GAME_SCENE:
			player.move();
			break;
		case Const.GAME_FIGHT:
			switch (curFightState) {
			case Const.FIGHT_HERO_GO:
				e = (Enemy) enemys.elementAt(enemyIndex);
				if (player.FindEnemy(e)) {
					enemyIndex = 0;
					curFightState = Const.FIGHT_HERO_ATTACK;
				}
				break;
			case Const.FIGHT_HERO_ATTACK:
				curFightState = Const.FIGHT_ENEMY_HURT;
				break;
			case Const.FIGHT_ENEMY_HURT:
				e.hp -= (player.at - e.def);
				if (e.hp <= 0) {
					enemys.removeElement(e);
				}
				curFightState = Const.FIGHT_HERO_RETURN;
				break;
			case Const.FIGHT_HERO_RETURN:
				if (player.BackHome()) {
					curFightState = Const.FIGHT_ENEMY_WAIT;
				}
				for(int i=0; i<enemys.size(); i++) {
					Enemy e = (Enemy)enemys.elementAt(i);
					e.hasAction = true;
				}
				break;
			case Const.FIGHT_ENEMY_WAIT:
				if(enemys.size() <= 0) {
					player.exp += exp;
					String se = "你获得了" + exp + "点经验";
					String[] sa = new String[]{""};
					if(r.nextInt(50) >= 30) {
						int index = r.nextInt(Const.TOOLS_NAME.length);
						String st = "你获得了" + Const.TOOLS_NAME[index];
						player.getTool(index);
						sa = new String[] {se, st};
					} else {
						sa = new String[] {se};
					}
					exp = 0;
					this.SetAlertCount(sa);
					this.GotoAlert();
					break;
				}
				curFightState = Const.FIGHT_ENEMY_GO;
				if(enemyIndex >= enemys.size()) {
					curFightState = Const.FIGHT_HERO_WAIT;
					enemyIndex = 0;
				}
				break;
			case Const.FIGHT_ENEMY_GO :
				e = (Enemy) enemys.elementAt(enemyIndex);
				if(e.FindHero()) {
					enemyIndex++;
					curFightState = Const.FIGHT_ENEMY_ATTACK;
				}
				break;
			case Const.FIGHT_ENEMY_ATTACK :
				curFightState = Const.FIGHT_HERO_HURT;
				break;
			case Const.FIGHT_HERO_HURT :
				player.hp -= ((e.at - player.def) < 0 ? 5 : e.at - player.def);
				if(player.hp <= 0) {
					GotoGameOver();
				}
				curFightState = Const.FIGHT_ENEMY_RETURN;
				break;
			case Const.FIGHT_ENEMY_RETURN :
				if(e.BackHome()) {
					curFightState = Const.FIGHT_ENEMY_WAIT;
				}
			}
			break;
		case Const.FIGHT_HERO_MAGIC_SELECT:
			
			break;
		
		}

	}

	// 处理封面按键事件
	public void MenuKeyEvent() {

		switch (curKey) {
		case Const.KEY_UP:
			curIndex = --curIndex < 0 ? 3 : curIndex;
			break;
		case Const.KEY_DOWN:
			curIndex = ++curIndex > 3 ? 0 : curIndex;
			break;
		case Const.KEY_FIRE:
			switch (curIndex) {
			case 0:
				GotoScene();
				curScreenState = Const.GAME_DIALOG;
				break;
			case 1:
				GotoLoad();
				break;
			case 2:
				GotoHelp();
				break;
			case 3:
				ExitGame();
				break;
			}
			break;
		}
		
	}

	// 处理暂停页面按键
	public void PauseKeyEvent() {
		switch (curKey) {
		case Const.KEY_UP:
			curIndex = --curIndex < 0 ? Const.PAUSE.length - 1 : curIndex;
			break;
		case Const.KEY_DOWN:
			curIndex = ++curIndex > Const.PAUSE.length - 1 ? 0 : curIndex;
			break;
		case Const.KEY_SOFT_LEFT:
		case Const.KEY_FIRE:
			switch (curIndex) {
			case 0:
				curScreenState = Const.GAME_SCENE;
				break;
			case 1:
				curScreenState = Const.GAME_VOL;
				break;
			case 2:
				curScreenState = Const.GAME_SAVE;
				break;
			case 3:
				curScreenState = Const.GAME_LOAD;
				break;
			case 4:
				GotoMenu();
				break;
			}
			curIndex = 0;
			break;
		case Const.KEY_SOFT_RIGHT:
			curScreenState = Const.GAME_SCENE;
			break;
		}

	}
	
	//处理系统界面按键
	public void SystemKeyEvent() {
		switch (curKey) {
		case Const.KEY_UP:
			curIndex = --curIndex < 0 ? Const.SYSTEM.length - 1 : curIndex;
			break;
		case Const.KEY_DOWN:
			curIndex = ++curIndex > Const.SYSTEM.length - 1 ? 0 : curIndex;
			break;
		case Const.KEY_SOFT_LEFT:
		case Const.KEY_FIRE:
			switch (curIndex) {
			case 0:
				curScreenState = Const.GAME_SYSTEM_TOOLS;
				break;
			case 1:
				curScreenState = Const.GAME_TASK;
				break;
			case 2:
				curScreenState = Const.GAME_STATUE;
				break;
			case 3:
				curScreenState = Const.GAME_SCENE;
				break;
			}
			curIndex = 0;
			break;
		case Const.KEY_SOFT_RIGHT:
			curScreenState = Const.GAME_SCENE;
			break;
		}

	}

	// 处理游戏中按键事件
	public void SceneKeyEvent() {
		switch (curKey) {
		case Const.KEY_LEFT:
			player.curAction = Const.HERO_LEFT_FRAME;
			break;
		case Const.KEY_UP:
			player.curAction = Const.HERO_UP_FRAME;
			break;
		case Const.KEY_RIGHT:
			player.curAction = Const.HERO_RIGHT_FRAME;
			break;
		case Const.KEY_DOWN:
			player.curAction = Const.HERO_DOWN_FRAME;
			break;
		case Const.KEY_FIRE:
			GotoFight();
			break;
		case Const.KEY_SOFT_LEFT:
			GotoSystem();
			break;
		case Const.KEY_SOFT_RIGHT:
			GotoPause();
			break;
		}
	}

	// 处理物品按键
	public void ToolsKeyEvent() {

		switch (curKey) {
		case Const.KEY_UP:
			curIndex = --curIndex < 0 ? player.tools.size() - 1
					: curIndex;
			break;
		case Const.KEY_DOWN:
			curIndex = ++curIndex > player.tools.size() - 1 ? 0
					: curIndex;
			break;
		case Const.KEY_SOFT_LEFT:
		case Const.KEY_FIRE:
			Tool t = (Tool)player.tools.elementAt(curIndex);
			player.useTool(t.id);
			curIndex = 0;
			curScreenState = Const.GAME_FIGHT;
			curFightState = Const.FIGHT_ENEMY_WAIT;
			break;
		case Const.KEY_SOFT_RIGHT:
			curScreenState = Const.GAME_FIGHT;
			curIndex = 0;
			break;
		}
		
	}
	
	public void SystemToolsEvent() {
		switch (curKey) {
		case Const.KEY_UP:
			curIndex = --curIndex < 0 ? Const.TOOLS_NAME.length - 1
					: curIndex;
			break;
		case Const.KEY_DOWN:
			curIndex = ++curIndex > Const.TOOLS_NAME.length - 1 ? 0
					: curIndex;
			break;
		case Const.KEY_SOFT_LEFT:
		case Const.KEY_FIRE:
			player.useTool(curIndex);
			curIndex = 0;
			curScreenState = Const.GAME_SCENE;
			break;
		case Const.KEY_SOFT_RIGHT:
			curScreenState = Const.GAME_SCENE;
			curIndex = 0;
			break;
		}
	}

	// 处理帮助
	public void HelpKeyEvent() {
		switch (curKey) {
		case Const.KEY_DOWN:
		case Const.KEY_SOFT_LEFT:
			curIndex = ++curIndex > Const.HELP.length - 1 ? 0 : curIndex;
			break;
		case Const.KEY_UP:
			curIndex = --curIndex < 0 ? Const.HELP.length - 1 : curIndex;
			break;
		case Const.KEY_SOFT_RIGHT:
			curScreenState = Const.GAME_LOGO;
			curIndex = 0;
			break;
		}
	}
	
	//处理状态下的按键
	public void StatueKeyEvent() {
		switch (curKey) {
		case Const.KEY_FIRE:
		case Const.KEY_SOFT_RIGHT:
			curScreenState = Const.GAME_SCENE;
			break;
		case Const.KEY_SOFT_LEFT:
			break;
		}
	}
	
	//处理声音按键
	public void VolKeyEvent() {
		switch (curKey) {
		case Const.KEY_UP:
			curIndex = --curIndex < 0 ? Const.VOL.length - 1
					: curIndex;
			break;
		case Const.KEY_DOWN:
			curIndex = ++curIndex > Const.VOL.length - 1 ? 0
					: curIndex;
			break;
		case Const.KEY_SOFT_LEFT:
		case Const.KEY_FIRE:
			switch(curIndex) {
			case 0:
				if(sound != null) {
					sound.playSound();
				}
				break;
			case 1:
				sound.turnUp();
				break;
			case 2:
				sound.turnDown();
				break;
			case 3:
				sound.stopSound();
				break;
			}
			break;
		case Const.KEY_SOFT_RIGHT:
			curScreenState = Const.GAME_SCENE;
			curIndex = 0;
			break;
		}
	}
	
	//处理保存界面下的按键
	public void SaveKeyEvent() {
		switch (curKey) {
		case Const.KEY_UP:
			curIndex = --curIndex < 0 ? 2 : curIndex;
			break;
		case Const.KEY_DOWN:
			curIndex = ++curIndex > 2 ? 0 : curIndex;
			break;
		case Const.KEY_SOFT_LEFT:
		case Const.KEY_FIRE:
			SaveGame();
			break;
		case Const.KEY_SOFT_RIGHT:
			curScreenState = Const.GAME_SCENE;
			curIndex = 0;
			break;
		}
	}
	
	//处理读取界面中按键事件
	public void LoadKeyEvent() {
		switch (curKey) {
		case Const.KEY_UP:
			curIndex = --curIndex < 0 ? 2 : curIndex;
			break;
		case Const.KEY_DOWN:
			curIndex = ++curIndex > 2 ? 0 : curIndex;
			break;
		case Const.KEY_SOFT_LEFT:
		case Const.KEY_FIRE:
			if(save[curIndex] == "无记录"){
				this.SetAlertCount(new String[]{"当前无记录!"});
				if(player == null || imgMap == null || bgMap == null) {
					GotoScene();
				}
				this.GotoAlert();
			} else {
				LoadGame();
			}
			break;
		case Const.KEY_SOFT_RIGHT:
			curScreenState = Const.GAME_SCENE;
			curIndex = 0;
			break;
		}
	}

	//处理对话中按键事件
	 public void DialogKeyEvent() {
	     switch (curKey)
	     {
	       case Const.KEY_DOWN: // down
	         this.curIndex = ++curIndex > Const.DIALOGS[0][player.curDialogIndex].length - 1 ?
	            Const.DIALOGS[0][player.curDialogIndex].length : curIndex;
	         //对话显示完毕,回到游戏界面
	         if(curIndex==Const.DIALOGS[0][player.curDialogIndex].length)
	         {
	           this.curIndex=0;
	           player.curDialogIndex++;
	           this.curScreenState = Const.GAME_SCENE;
	         }
	         break;
	     }
	  }
	// 处理战斗中按键事件
	public void FightKeyEvent() {
		switch (curFightState) {
		case Const.FIGHT_HERO_WAIT:
			switch (curKey) {
			case Const.KEY_UP:
				curIndex = --curIndex < 0 ? Const.FIGHT_MENU.length - 1
						: curIndex;
				break;
			case Const.KEY_DOWN:
				curIndex = ++curIndex > Const.FIGHT_MENU.length - 1 ? 0
						: curIndex;
				break;
			case Const.KEY_FIRE:
				switch (curIndex) {
				case 0:
					curFightState = Const.FIGHT_HERO_SELECT;
					break;
				case 1:
					curFightState = Const.FIGHT_HERO_MAGIC_SELECT;
					break;
				case 2:
					curScreenState = Const.GAME_TOOLS;
					break;
				case 3:
//					player.curAction = Const.HERO_RIGHT_FRAME;
					if(r.nextInt(50) > 30) {
						curScreenState = Const.GAME_SCENE;
					} 
//					player.curAction = Const.HERO_LEFT_FRAME;
					curFightState = Const.FIGHT_ENEMY_WAIT;
					break;
				}
				curIndex = 0;
				break;

			}
			break;
		case Const.FIGHT_HERO_MAGIC_SELECT:
			switch (curKey) {
			case Const.KEY_UP:
				curIndex = --curIndex < 0 ? player.magic.length - 1 : curIndex;
				break;
			case Const.KEY_DOWN:
				curIndex = ++curIndex > player.magic.length - 1 ? 0 : curIndex;
				break;
			case Const.KEY_SOFT_LEFT:
			case Const.KEY_FIRE:
				curFightState = Const.FIGHT_HERO_MAGIC;
				break;
			case Const.KEY_SOFT_RIGHT:
				curFightState = Const.FIGHT_HERO_WAIT;

⌨️ 快捷键说明

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