English 中文(简体)
我如何规划游戏的不同阶段?
原标题:How do I program different stages of a game?

我制造了两部分的机动游戏。 第一是缓慢的,第二是快速的。 第二次处决是在第一次完成后进行的。

I was thinking of running the game in a game loop and separating the two stages in the loop:

MainGameLoop:
while (running) {
 while (!FirstStage.isDone) {
  FirstStage.run(); 
 }
 while (!SecondStage.isDone) {
  SecondStage.run();
 }
}

这是正确的模式吗? 是否有任何既定的游戏规划模式/由我咨询?

最佳回答

游戏使用“国家机器”。 很容易与外界合作并扩展。

while(true)
{
    switch(game_state)
    {  
       case SLOW_STUFF: // whatver
             if(move_on):  game_state = FAST_STUFF; // or something like this.
             break;
       case FAST_STUFF:  // whatever..
       // then also...
       case GAME_OVER:
       case WAIT_FOR_START:
       case QUIT:
          // save state..
          return;
     etc

    }
}
问题回答

In theory, it s correct. But in practice, your app will be event-driven, and will probably not have it s own loop, but utilize the system s event loop, such as on Android. This is often implicit. So at the completion of the first stage, an event will be fired (a method will be called), which sets a state indicating the second stage is running.





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签