📄 app.java
字号:
/*
* Copyright (C) 2005-2006 Leopardo.f
*
* This file is part of M-SuDoKu, a J2ME version of SuDoKu.
*
* M-SuDoKu is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* M-SuDoKu is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with M-SuDoKu; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA. Or, visit http://www.gnu.org/copyleft/gpl.html
*/
package MSuDoKu;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
* Main M-SuDoKu class
* @author Leopardo.f
*/
public class App extends MIDlet implements CommandListener {
private Display display;
private Command menuCommand, okCommand;
private PuzzleView pv;
private PuzzleModel pm;
private String[] saStringTable;
private MainMenu menu = null;
private LevelMenu levelMenu = null;
private InputMenu inputMenu = null;
private BackgroundMenu backgroundMenu = null;
private Alert alert = null;
private PuzzleStore ps;
/** Creates a new instance of App */
public App() {
ps = new PuzzleStore();
pv = new PuzzleView (ps.getBack());
pm = new PuzzleModel (this, pv, ps);
saStringTable = Utils.getStringTable();
// menu = new MainMenu (this, saStringTable);
// levelMenu = new LevelMenu (this, Utils.getLevel(), saStringTable);
// inputMenu = new InputMenu (this, Utils.getInput(), saStringTable);
// backgroundMenu = new BackgroundMenu (this, Utils.getBackground(), saStringTable);
// alert = new Alert (Utils.sAppName);
// alert.setTimeout (Alert.FOREVER);
// alert.setType (AlertType.INFO);
// Use the following for SE & anything else
menuCommand = new Command(saStringTable[Utils.MENU], Command.OK, 1);
// Use the following for S40, S60
// menuCommand = new Command(saStringTable[Utils.MENU], Command.BACK, 1);
okCommand = new Command("OK", Command.OK, 1);
pv.addCommand (menuCommand);
pv.setCommandListener (this);
// Start clean-up thread
/*
new Thread (new Runnable()
{
public void run()
{
while (true)
{
System.gc();
try
{
Thread.sleep (30000);
} catch (InterruptedException ie) {}
}
}
}).start();
*/
}
/**
* Called when game is started
*/
public void startApp() {
display = Display.getDisplay(this);
// display.setCurrent (pv);
new SplashScreen (display, pv, 2000);
}
/**
* Called when game is paused
*/
public void pauseApp() {
}
/**
* Called when game is about to be destroyed
*/
public void destroyApp(boolean unconditional) {
pm.prepareForExit();
}
/**
* Responds to a commands issued on any Screen
* @param c the Command originator of the event
* @param s Displayable
*/
public void commandAction(Command c, Displayable s) {
if (c == menuCommand)
{
if (menu == null)
menu = new MainMenu (this, saStringTable);
display.setCurrent (menu);
} else if (c == okCommand)
{
// display.setCurrent (pv);
pv.removeCommand (okCommand);
pv.addCommand (menuCommand);
pv.repaintBoard();
pv.repaint();
}
}
/**
* Shows the About Alert
*/
public void showAbout()
{
// alert.setString ("FreeMem:" + Runtime.getRuntime().freeMemory() + "\n" + Utils.getAbout());
// alert.setString (Utils.getAbout());
// display.setCurrent (alert, pv);
showAlert (Utils.getAbout(), pv);
}
/**
* Shows the Help Alert
*/
public void showHelp()
{
// alert.setString (Utils.getHelp());
// display.setCurrent (alert, pv);
showAlert (Utils.getHelp(), pv);
}
/**
* Shows the game grid
*/
public void showBoard()
{
display.setCurrent (pv);
}
/**
* Shows the game grid
*/
public void showSolution()
{
pv.removeCommand (menuCommand);
display.setCurrent (pv);
/*
try
{
Thread.sleep (500);
} catch (InterruptedException ie) {}
*/
pv.showSolution();
pv.addCommand (okCommand);
}
/**
* Shows the level choice menu
*/
public void showLevel()
{
if (levelMenu == null)
levelMenu = new LevelMenu (this, Utils.getLevel(), saStringTable);
levelMenu.setCurrentLevel (pm.getLevel());
display.setCurrent (levelMenu);
}
/**
* Shows the input mode choice menu
*/
public void showInput()
{
if (inputMenu == null)
inputMenu = new InputMenu (this, Utils.getInput(), saStringTable);
inputMenu.setCurrentInput (pm.getInputMode());
display.setCurrent (inputMenu);
}
/**
* Shows the background image choice menu
*/
public void showBackground()
{
if (backgroundMenu == null)
backgroundMenu = new BackgroundMenu (this, Utils.getBackground(), saStringTable);
display.setCurrent (backgroundMenu);
}
/**
* Called when a change of background has been requested
* @param n the index of the chosen background
*/
public void changeBackground (int n)
{
// n = 0 (first element in menu) means No Background
pv.setBackground ((byte) (n - 1));
display.setCurrent (pv);
}
/**
* Called when a restart for the given level has been requested
* @param nLevel the level of the new game
*/
public void restartRequested (byte nLevel)
{
if (pm.getLevel() == nLevel)
{
display.setCurrent (pv);
return;
}
pv.deleteAll(); /*JDB*/
byte b = pv.getBackground();
pv = null;
pv = new PuzzleView (b);
pm.restart (pv, nLevel);
pv.addCommand (menuCommand);
pv.setCommandListener (this);
display.setCurrent (pv);
}
/**
* Called when the user has changed input mode
* @param im the new input mode
*/
public void changeInputMode (byte im)
{
pm.setInputMode (im);
display.setCurrent (pv);
}
/**
* Called when a restart for the current level has been requested
*/
public void restartRequested()
{
pv.deleteAll(); /*JDB*/
byte b = pv.getBackground();
pv = null;
pv = new PuzzleView (b);
pm.restart (pv);
pv.addCommand (menuCommand);
pv.setCommandListener (this);
display.setCurrent (pv);
}
/**
* Called when the current puzzle has been solved
* @param yLevel the current level
* @param yCurr the current puzzle
* @param yMax the maximum number of puzzles available for any level
* @param lDuration the game duration in millisec
*/
public void notifySolved (byte yLevel, byte yCurr, byte yMax, long lDuration)
{
// alert.setString (Utils.getCongrats() + getDurationString (lDuration, Utils.getTime()));
/* Deleted with v0.8.0
if (yCurr == yMax - 1)
alert.setString (alert.getString() + Utils.getPuzzlesOver());
*/
pv.deleteAll(); /*JDB*/
byte b = pv.getBackground();
pv = null;
pv = new PuzzleView (b);
pv.addCommand (menuCommand);
pv.setCommandListener (this);
pm.updatePuzzle (pv);
// display.setCurrent (alert, pv);
showAlert (Utils.getCongrats() + getDurationString (lDuration, Utils.getTime()), pv);
}
/**
* Returns the string translation of the game duration in milliseconds
* @param l game duration in milliseconds
* @param sa String array for the "Hour/Minute/Second" thing in the given locale
*/
protected String getDurationString (long l, String[] sa)
{
long lTemp;
String sReturn;
lTemp = l / 1000;
sReturn = (lTemp % 60) + " " + sa[2];
if (lTemp < 60)
return sReturn;
lTemp = lTemp / 60;
sReturn = (lTemp % 60) + " " + sa[1] + " " + sReturn;
if (lTemp < 60)
return sReturn;
lTemp = lTemp / 60;
sReturn = lTemp + " " + sa[0] + " " + sReturn;
return sReturn;
}
/**
* Called to skip the current puzzle
*/
public void skip()
{
pv.deleteAll(); /*JDB*/
byte b = pv.getBackground();
pv = null;
pv = new PuzzleView (b);
pv.addCommand (menuCommand);
pv.setCommandListener (this);
pm.updatePuzzle (pv);
display.setCurrent (pv);
}
/**
* Called when exit from application has been requested
*/
public void exitRequested()
{
destroyApp (true);
notifyDestroyed();
}
/**
* Called when exit from application has been requested
*/
private void showAlert (String s, Displayable d)
{
if (alert == null)
{
alert = new Alert (Utils.sAppName);
alert.setTimeout (Alert.FOREVER);
alert.setType (AlertType.INFO);
}
alert.setString (s);
display.setCurrent (alert, d);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -