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

📄 startform.java

📁 一个非常好的赛车游戏代码
💻 JAVA
字号:

import javax.microedition.lcdui.*;

public class StartForm extends Form
    implements CommandListener
{
  private Game game;
  private Command playCommand;
  private Command garageCommand;
  private Command helpCommand;
  private Command aboutCommand;
  private Command exitCommand;

  public StartForm(Game game)
  {
    super("Micro Racer");
    this.game = game;
    Image image = null;
    try
    {
      image = Image.createImage("/logo.png");
    } catch (Exception ex) {}
    ImageItem item = new ImageItem(null, image,
        ImageItem.LAYOUT_CENTER, null);
    append(item);
    append("Cash: "+game.cs.getCash());
    for (int i=0; i < game.cs.getWeapons().length; i++)
    {
    	append("Weapon#"+(i+1)+": "+game.cs.getWeapons()[i].getName());
	}
    playCommand = new Command("Play", Command.SCREEN, 1);
    garageCommand = new Command("Garage!", Command.SCREEN, 2);
    helpCommand = new Command("Help", Command.SCREEN, 3);
    aboutCommand = new Command("About", Command.SCREEN, 4);
    exitCommand = new Command("Exit", Command.SCREEN, 5);
    addCommand(playCommand);
    addCommand(garageCommand);
    addCommand(helpCommand);
    addCommand(aboutCommand);
    addCommand(exitCommand);
    setCommandListener(this);
  }

  public void commandAction(Command c, Displayable s)
  {
    if (c.equals(playCommand))
    {
      GameCanvas canvas = new GameCanvas(game, this);
      Tracks tracks = new Tracks(game, canvas, this);
      game.getDisplay().setCurrent(tracks);
    }
    if (c.equals(garageCommand))
    {
      game.garage.Login();
   	}
    else if (c.equals(helpCommand))
    {
      String str = "Use left and right navigation key to move the car. Use the fire key to fire a weapon. Pick up power-ups and try to avoid opponents!";
      Alert alert = new Alert("Help", str, null,
          AlertType.INFO);
      alert.setTimeout(Alert.FOREVER);
      game.getDisplay().setCurrent(alert, this);
    }
    else if (c.equals(aboutCommand))
    {
      StringBuffer buf = new StringBuffer();
      buf.append("Developed by David Fox and ");
      buf.append("Roman Verhovsek.\n\n");
      Alert alert = new Alert("About", buf.toString(),
          null, AlertType.INFO);
      alert.setTimeout(Alert.FOREVER);
      game.getDisplay().setCurrent(alert, this);
    }
    else if (c.equals(exitCommand))
    {
      game.exit();
    }
  }
}

⌨️ 快捷键说明

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