bombman.java~1~

来自「基于J2ME的手机游戏软件。可以控制游戏人物在地图上上下左右行走;可以在地图上放」· JAVA~1~ 代码 · 共 136 行

JAVA~1~
136
字号
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Command;
import java.io.IOException;

public class BombMan extends MIDlet implements CommandListener
{
	private Displayable currentScreen;
	private Splash splash;
	private GameScreen gameScreen;
	private List gameMenu;
	private Command select;
	
	public BombMan()
	{
		splash = new Splash(this);
		gameScreen = new GameScreen(this);
		select = new Command("Select",Command.OK,1);
		String[] choice = {"liwei","zhengtian"};
		gameMenu = new List("GameMenu",List.IMPLICIT,choice,null);
		gameMenu.addCommand(select);
		gameMenu.setCommandListener(this);
	}
	
	public void startApp() throws MIDletStateChangeException
	{
		if(currentScreen == null)
		{
			activateDisplayable(splash);
		}
		else
		{
			activateDisplayable(currentScreen);
		}
	}
	
	public void pauseApp()
	{
		if(gameScreen.getState() == GameScreen.STATE_PLAYING)
		{
			gameScreen.pause();
		}
		if(currentScreen != splash)
		{
			activateGameMenu();
		}
	}
	
	public void destroyApp(boolean cond) throws MIDletStateChangeException
	{
		
	}
	
	public void activateDisplayable(Displayable dis)
	{
		currentScreen = dis;
		Display.getDisplay(this).setCurrent(dis);
	}  
	
	public void activateGameScreen()
	{
		activateDisplayable(gameScreen);
		if(gameScreen.getState() == GameScreen.STATE_INIT 
				|| gameScreen.getState() == GameScreen.STATE_END)
		{
			gameScreen.start();
		}
	}
	
	private void initGameMenu()
	{
		gameMenu.deleteAll();
		if(gameScreen.getState() == GameScreen.STATE_PLAYING)
		{
			gameMenu.append("Resume Game",null);
		}
		gameMenu.append("Start New Game",null);
		gameMenu.append("High Score",null);
		gameMenu.append("About",null);
		gameMenu.append("Exit",null);
	}
	
	public void activateGameMenu()
	{
		initGameMenu();
		currentScreen = gameMenu;
		activateDisplayable(currentScreen);
	}
	
	public void close()
	{
		try
		{
			destroyApp(true);
			notifyDestroyed();
		}
		catch(Exception e)
		{
			
		}
	}
	
	public void commandAction(Command cnd,Displayable dis)
	{
		if(cnd == select && dis == gameMenu)
		{
			String sel = gameMenu.getString(gameMenu.getSelectedIndex());
			if(sel == "Start New Game")
			{
				activateGameScreen();
				gameScreen.startNewGame();
			}
			else if(sel == "Resume Game")
			{
				activateGameScreen();
				gameScreen.resume();
			}
			else if(sel == "High Score")
			{
				System.out.println("high score");
			}
			else if(sel == "About")
			{
				System.out.println("about");
			}
			else if(sel == "Exit")
			{
				close();
			}
		}
	}
}

⌨️ 快捷键说明

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