📄 mainmenu.java
字号:
//
// Copyright 2002 Nokia Corporation
//
// THIS SOURCE CODE IS PROVIDED 'AS IS', WITH NO WARRANTIES WHATSOEVER,
// EXPRESS OR IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY, FITNESS
// FOR ANY PARTICULAR PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE
// OR TRADE PRACTICE, RELATING TO THE SOURCE CODE OR ANY WARRANTY OTHERWISE
// ARISING OUT OF ANY PROPOSAL, SPECIFICATION, OR SAMPLE AND WITH NO
// OBLIGATION OF NOKIA TO PROVIDE THE LICENSEE WITH ANY MAINTENANCE OR
// SUPPORT. FURTHERMORE, NOKIA MAKES NO WARRANTY THAT EXERCISE OF THE
// RIGHTS GRANTED HEREUNDER DOES NOT INFRINGE OR MAY NOT CAUSE INFRINGEMENT
// OF ANY PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OWNED OR CONTROLLED
// BY THIRD PARTIES
//
// Furthermore, information provided in this source code is preliminary,
// and may be changed substantially prior to final release. Nokia Mobile
// Phones Ltd. retains the right to make changes to this source code at
// any time, without notice. This source code is provided for informational
// purposes only.
//
// Third-party brands and names are the property of their respective
// owners. Java(TM) and J2ME(TM) are registered trademarks of
// Sun Microsystems Inc.
//
// A non-exclusive, non-transferable, worldwide, limited license is hereby
// granted to the Licensee to download, print, reproduce and modify the
// source code. The licensee has the right to market, sell, distribute and
// make available the source code in original or modified form only when
// incorporated into the programs developed by the Licensee. No other
// license, express or implied, by estoppel or otherwise, to any other
// intellectual property rights is granted herein.
//
import javax.microedition.lcdui.*;
// The main menu is shown after the splash screen, or when the
// game screen has been temporarily paused (using the 'Back' command
// or a softkey in the (Canvas or FullCanvas) game screen).
// The main menu allows the user to start a new game, to continue
// playing an existing (paused) game, to change game settings,
// to find the instructions on how to play, etc.
class MainMenu
extends List
implements CommandListener
{
private final BlitzMIDlet midlet;
private final Dictionary dict;
private boolean hasContinue = false;
MainMenu(BlitzMIDlet midlet, Dictionary dict, GameEffects gameEffects, boolean cont)
{
super("DropShip", List.IMPLICIT);
this.midlet = midlet;
this.dict = dict;
// The default main menu items are:
// - New game
// - Settings
// - Instructions
// - High Score
//
// There is one main menu item that may or may not be present:
// - Continue:
// It is added when a game starts (to handle game pauses),
// and is removed when a game ends (see methods addContinue
// and deleteContinue below).
//
// Exit is added as sofkey Command and not as a menu item.
// add default menu items
append(dict.getString(Dictionary.LABEL_NEWGAME), null);
if (gameEffects.hasSoundCapability() ||
gameEffects.hasVibrationCapability())
{
// The Settings item is only added if the device has Sound
// and Vibration support, otherwise having a Settings menu
// to change their values is useless.
append(dict.getString(Dictionary.LABEL_SETTINGS), null);
}
append(dict.getString(Dictionary.LABEL_INSTRUCTIONS), null);
append(dict.getString(Dictionary.LABEL_HISCORE), null);
addCommand(new Command(dict.getString(Dictionary.LABEL_EXIT),
Command.EXIT, 1));
setCommandListener(this);
if (cont) addContinue();
}
void addContinue()
{
// add Continue to the list of menu items, if not already present
if (!hasContinue)
{
insert(0, dict.getString(Dictionary.LABEL_CONTINUE), null);
hasContinue = true;
}
}
void deleteContinue()
{
// remove 'Continue' from the list of menu items, if present
if (hasContinue)
{
this.delete(0);
hasContinue = false;
}
}
void selectContinue()
{
if (hasContinue)
{
this.setSelectedIndex(0, true);
}
}
public void commandAction(Command command, Displayable d)
{
if (command == List.SELECT_COMMAND)
{
String selected = getString(getSelectedIndex());
if (selected.equals(dict.getString(Dictionary.LABEL_CONTINUE)))
{
midlet.mainMenuContinue();
}
else if (selected.equals(dict.getString(Dictionary.LABEL_NEWGAME)))
{
midlet.mainMenuNewGame(false);
}
else if (selected.equals(
dict.getString(Dictionary.LABEL_SETTINGS)))
{
midlet.mainMenuSettings();
}
else if (selected.equals(dict.getString(Dictionary.LABEL_HISCORE)))
{
midlet.mainMenuHiScore();
}
else if (selected.equals(
dict.getString(Dictionary.LABEL_INSTRUCTIONS)))
{
midlet.mainMenuInstructions();
}
}
else
{
// the application code only adds one command: Exit
midlet.mainMenuExit();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -