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

📄 seagame.java

📁 为毕业设计而只做的JAVA版的手机游戏,游戏名:海底探险
💻 JAVA
字号:
//SeaGame.java;
//功能:完成菜单的定义及初始化;
//类名:SeaGame 
//作者:石明华
//完成日期:2007-03-01

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class SeaGame extends MIDlet implements CommandListener {

	private Form styForm,saveForm;
	private TextBox tbox,nbox;
	
	private Command exitCommand;
	private Command backCommand;
	private Command enterCommand;
	private Command saveCommand;
	private Command nextCommand;
	private Command OKCommand;
	
	public NewGame n;
	
	private int a,b;
	
	
	public ViewWindowCanvas v;
	public SeaGame() {
		// TODO Auto-generated constructor stub
		exitCommand = new Command("Exit",Command.EXIT,1);
		backCommand = new Command("Back",Command.BACK,1);
		enterCommand = new Command("Enter",Command.OK,1);
		saveCommand = new Command("Save",Command.OK,1);
		nextCommand = new Command("Next",Command.OK,1);
		OKCommand = new Command("OK",Command.OK,1);
		v = new ViewWindowCanvas();
		v.addCommand(exitCommand);
		v.addCommand(enterCommand);
		v.setCommandListener(this);
		v.mainList.addCommand(exitCommand);
		v.mainList.addCommand(backCommand);
		v.mainList.setCommandListener(this);
		
		n = new NewGame();
		n.addCommand(backCommand);
		n.addCommand(exitCommand);
		n.addCommand(saveCommand);
		n.setCommandListener(this);

		styForm = new Form("游戏背景");
		styForm.addCommand(exitCommand);
		styForm.addCommand(backCommand);
		styForm.setCommandListener(this);
		
		saveForm = new Form("保存游戏进度");
		saveForm.addCommand(saveCommand);
		saveForm.setCommandListener(this);
		
		tbox = new TextBox("请输入游戏主角的移动速度(0-9)","",1,2);
		tbox.addCommand(nextCommand);
		tbox.setCommandListener(this);
		
		nbox = new TextBox("请输入同屏怪物的移动速度(0-9)","",1,2);
		nbox.addCommand(OKCommand);
		nbox.setCommandListener(this);
		
		Display.getDisplay(this).setCurrent(v);
	}

	protected void destroyApp(boolean arg0) //throws MIDletStateChangeException 
	{
		// TODO Auto-generated method stub
	}

	protected void pauseApp() {
		// TODO Auto-generated method stub
	}

	protected void startApp() //throws //MIDletStateChangeException 
	{
		// TODO Auto-generated method stub
	}

	public void commandAction(Command c,Displayable d){
		if(d.equals(v.mainList)){
			if(c == List.SELECT_COMMAND){
				if(d.equals(v.mainList)){
					switch(((List)d).getSelectedIndex()){
					case 0:
						n.isgo(1);
						n = new NewGame();
						
						n.addCommand(exitCommand);
						n.addCommand(saveCommand);
						n.addCommand(backCommand);
						n.setCommandListener(this);
						Display.getDisplay(this).setCurrent(n);
						break;
					case 1:
						styForm.deleteAll();
						styForm.append(story);
						Display.getDisplay(this).setCurrent(styForm);
						break;
					case 2:
						styForm.deleteAll();
						styForm.append(rules);
						Display.getDisplay(this).setCurrent(styForm);
						break;
					case 3:
						tbox.setString("");
						Display.getDisplay(this).setCurrent(tbox);
						break;
					case 4:
						n.clearw();
						Display.getDisplay(this).setCurrent(n);
						n.loadGame();
						break;
					case 5:
						n.showScroe();
						styForm.deleteAll();
						for(int i=1;i<=+n.data[0];i++)
						styForm.append(" "+i+"、"+n.data[i+1]+" ");
						Display.getDisplay(this).setCurrent(styForm);
						break;	
					}
				}
			}
		}
		if(c == enterCommand){
			v.clear();
			Display.getDisplay(this).setCurrent(v.mainList);
		}
		if(c == backCommand){
			Display.getDisplay(this).setCurrent(v.mainList);
		}
		
		if(c == exitCommand){
			destroyApp(false);
			notifyDestroyed();
		}

		if(c == saveCommand){
			n.saveGame();
		}
		
		if(c == nextCommand){
			nbox.setString("");
			 a = getNum(tbox.getString());
			Display.getDisplay(this).setCurrent(nbox);
		}
		
		if(c == OKCommand){
			 b = getNum(nbox.getString());
			Display.getDisplay(this).setCurrent(v.mainList);
			n.setPara(a,b);
		}
	}
	protected int getNum(String str){
		int num = 0;
		if(str.equals("0")){
			num = 0;
		}else if(str.equals("1")){
			num = 1;
		}else if(str.equals("2")){
			num = 2;
		}else if(str.equals("3")){
			num = 3;
		}else if(str.equals("4")){
			num = 4;
		}else if(str.equals("5")){
			num = 5;
		}else if(str.equals("6")){
			num = 6;
		}else if(str.equals("7")){
			num = 7;
		}else if(str.equals("8")){
			num = 8;
		}else if(str.equals("9")){
			num = 9;
		}else{
			num = 0;
		}
		return num;
	}
	private final static String story = "  游戏是从一个海边的小村庄开始,主人公杰克从一个断了手臂的海贼得知宝藏的事情,于是他就带上自己的匕首踏上了他的寻宝之旅";
	private final static String rules = "  游戏控制由键盘上的四个方向键、功击键(数字1键)、确定及退出6个键来完成,玩家必须在第一关打怪使得分值达到10分以上才能进入第二关,在第二关必须分值达到30分才能进入第三关";
}

⌨️ 快捷键说明

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