51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 1883|回复: 0
打印 上一主题 下一主题

基于Nokia手机的移动游戏开发步步通(三)

[复制链接]
  • TA的每日心情
    慵懒
    2015-1-8 08:46
  • 签到天数: 2 天

    连续签到: 1 天

    [LV.1]测试小兵

    跳转到指定楼层
    1#
    发表于 2007-11-14 16:36:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    二、实现游戏的步骤

      下图显示的是一个游戏MIDlet在成功安装和运行之后用户界面状态的典型的变化流程。我们想通过一个游戏者的视角来阐述开发移动游戏的过程。


    图3 用户界面状态图表

      1 开始游戏

      在用户启动MIDlet之后,将显示游戏特定的闪动屏幕。闪动屏幕是FullCanvas的一个实例。它可用于显示一个公司的标志或者用动画形式介绍游戏。除了End键以外的所有键盘事件(MIDlet可用的)都可以跳过闪动屏幕并显示主菜单。还应该设置一个时间限定,能够在一定的时间过后自动跳出闪动屏幕进入游戏屏幕。
    GameMIDlet类是游戏的基本类;它处理MIDlet的生命周期并且处理游戏显示。下面的代码是闪动屏幕和游戏MIDlet类的构架。

    //Skeleton for the base class of game
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    public class GameMIDlet extends MIDlet {
     private Display display = null;
     //Splash screen that starts the application
     private SplashFullCanvas splash;
     public GameMIDlet() {
      splash = new SplashFullCanvas(this);
     }
     protected void startApp() throws MIDletStateChangeException {
      if (display == null) {
       display = Display.getDisplay(this);
      }
      //splash screen to the display
      setDisplayable(splash);
     }
     protected void pauseApp() {
    }

     protected void destroyApp(boolean p0)
     throws MIDletStateChangeException {
     }

     public void setDisplayable(Displayable dl) {
      display.setCurrent(dl);
     }
    }

    //Skeleton for the splash screen in Nokia Java Game
    import javax.microedition.lcdui.*;
    import java.util.Timer;
    import java.util.TimerTask;
    import com.nokia.mid.ui.*;

    public class SplashFullCanvas extends FullCanvas {
     private GameMIDlet parent = null;
     private MainMenu menu = null;
     private Timer timer = null;
     public SplashFullCanvas(GameMIDlet parent) {
      this.parent = parent;
      menu = new MainMenu(
       Resources.getString(Resources.ID_GAME_NAME),
       List.IMPLICIT, parent);
       startTimer();
     }
    protected void paint(Graphics g) {
     //Do the splash screen here
    }
    protected void keyPressed(int keyCode) {
     timer.cancel();
     timer = null;
     //All key events received set the main menu to the screen
     parent.setDisplayable(menu);
    }

    //Timer for the splash screen. Main menu is set to the display
    //after 5 seconds.
    private void startTimer() {
     TimerTask task =new TimerTask() {
      public void run() {
       parent.setDisplayable(menu);
      }
     };
     timer = new Timer();
     timer.schedule(task, 5000);
    }
    }

      2 主菜单(MainMenu)屏幕

      主菜单是包含游戏特定选项的固有目录("Continue"、"New game"、"Options"、"High scores"、"Instructions"、"About"和"Exit game")。"Continue"只有在游戏被暂停的时候才能被显示。当"Continue"显示的时候,它必须是目录列表的第一个元素。主菜单的标题必须是游戏的名称。下面的代码是主菜单的框架。

    //Skeleton for the main menu
    import javax.microedition.lcdui.*;
    public class MainMenu extends List implements CommandListener {
     private GameMIDlet parent = null;
     private GameFullCanvas game = null;
     public MainMenu(String p0, int p1, String[] p2, Image[] p3,
     GameMIDlet parent) {
      super(p0, p1, p2, p3);
      init(parent);
     }
     public MainMenu(String p0, int p1, GameMIDlet parent) {
      super(p0, p1);
      init(parent);
     }
     public void init(GameMIDlet parent) {
      this.parent = parent;
      this.setCommandListener(this);
      //if game paused then "Continue" should be available in
      //selection list
      if (game != null && game.isPaused()) {
       if(!(this.getString(0).equals(
        new String(Resources.getString(
         Resources.ID_GAME_CONTINUE))))) {
          this.insert(0,
           Resources.getString(Resources.ID_GAME_CONTINUE),
           null);
         }
         this.setSelectedIndex(0,true);
        }
       else {
        //These must be with or without icons
        this.append(Resources.getString(Resources.ID_GAME_NEW), null);
        this.append(Resources.getString(Resources.ID_GAME_OPTIONS),null);
        this.append(Resources.getString(
         Resources.ID_GAME_HIGHSCORES), null);
        this.append(Resources.getString(
        Resources.ID_GAME_INSTRUCTIONS), null);
        this.append(Resources.getString(Resources.ID_GAME_ABOUT), null);
        this.append(Resources.getString(Resources.ID_GAME_EXIT), null);
       }
      }
      public void commandAction(Command p0, Displayable p1) {
       List lis = (List) p1;
       String selected =
       lis.getString(lis.getSelectedIndex());
       if (selected.equals(Resources.getString(Resources.ID_GAME_NEW))) {
        game = new GameFullCanvas(parent, this);
        parent.setDisplayable(game);
       }
       else if (selected.equals(
        Resources.getString(Resources.ID_GAME_OPTIONS))) {
         parent.setDisplayable(
          new OptionList(Resources.getString(Resources.ID_GAME_OPTIONS),
           List.IMPLICIT,
           parent, this));
        }
       else if (selected.equals(
        Resources.getString(Resources.ID_GAME_HIGHSCORES))) {
         parent.setDisplayable(new HighScore(parent, this));
        }
       else if (selected.equals(
        Resources.getString(Resources.ID_GAME_INSTRUCTIONS))) {
         parent.setDisplayable(
          new Instructions(
           Resources.getString(Resources.ID_GAME_INSTRUCTIONS),parent,this));
        }
       else if (selected.equals(
        Resources.getString(Resources.ID_GAME_ABOUT))) {
         parent.setDisplayable(
          new About(
           Resources.getString(Resources.ID_GAME_ABOUT),
           parent,
           this));
        }
       else if (selected.equals(
        Resources.getString(Resources.ID_GAME_EXIT))) {
         parent.notifyDestroyed();
       }
       else if (selected.equals(
        Resources.getString(Resources.ID_GAME_CONTINUE))) {
         if (game != null) {
          game.gameContinue();
          parent.setDisplayable(game);
       }
      }
     }
    }
    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-5-1 19:24 , Processed in 0.072377 second(s), 27 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表