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

📄 wordsearch20.java

📁 Source code for j2me game WordSearch
💻 JAVA
字号:
package wordSearch20;import java.util.*;import javax.microedition.midlet.*;import javax.microedition.lcdui.*;/** * This is the main class of the wordSearch game. * * @author Jeremiah McLeod http://www.xdebugx.net */public class wordSearch20 extends MIDlet implements CommandListener {   Random myRandom;  private Command myExitCommand = new Command("Exit", Command.EXIT, 99);  private Command mySolveCommand = new Command("Solve", Command.SCREEN, 1);  private Command myNewGameCommand = new Command("New Game", Command.SCREEN, 1);  private Command myGoCommand = new Command ("Go",Command.SCREEN, 1);   //* the the canvas that all of the game will be drawn on.   //*/  mainCanvas myCanvas;  /**   * the thread that advances the animation   */  GameThread myGameThread;  //-----------------------------------------------------  //    initialization and game state changes  /**   * Initialize the canvas and the commands.   */  public wordSearch20() {    myCanvas = new mainCanvas(this);    myCanvas.addCommand(myExitCommand);    myCanvas.addCommand(myGoCommand);    myCanvas.setCommandListener(this);    myRandom= new Random();  }  void setSolveCommand() {    myCanvas.removeCommand(myNewGameCommand);    myCanvas.addCommand(mySolveCommand);  }  void setNewGameCommand() {    myCanvas.removeCommand(mySolveCommand);    myCanvas.addCommand(myNewGameCommand);  }  //----------------------------------------------------------------  //  implementation of MIDlet  /**   * Start the application.   */  public void startApp() throws MIDletStateChangeException {    myGameThread = new GameThread(myCanvas);    myCanvas.start();    myGameThread.go();  }  /**   * stop and throw out the garbage.   */  public void destroyApp(boolean unconditional)      throws MIDletStateChangeException {    myGameThread.requestStop();    myGameThread = null;    myCanvas = null;    System.gc();  }  public void pauseApp() {    myGameThread.pause();  }  //----------------------------------------------------------------  //  implementation of CommandListener  /*   * Respond to a command issued on the Canvas.   */  public void commandAction(Command c, Displayable s) {    int p,t;    if(c == mySolveCommand) {      myCanvas.removeCommand(mySolveCommand);      myCanvas.addCommand(myNewGameCommand);  	 	for (p=0;p<10;p++)	  	 	myCanvas.wordFound[p]=true;	      } else if(c == myNewGameCommand) {      myCanvas.removeCommand(myNewGameCommand);      myCanvas.addCommand(mySolveCommand);     	myCanvas.newGame ();    } else if(c == myExitCommand) {      try {	destroyApp(false);	notifyDestroyed();      } catch (MIDletStateChangeException ex) {      }    }    else if (c==myGoCommand && mainCanvas.myImagesLoaded==true) {	mainCanvas.go=true;	myCanvas.removeCommand(myGoCommand);	myCanvas.addCommand(mySolveCommand);	}  }public int getRandomInt(int upper) {    int retVal = myRandom.nextInt() % upper;    if(retVal < 0) {      retVal += upper;    }    return(retVal);  }}

⌨️ 快捷键说明

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