在Java Slick库和lwjgl中运行游戏时遇到问题

时间:2016-05-28 06:55:58

标签: java eclipse lwjgl slick

我正在创建游戏,我正在使用Slick和lwjgl。我的java版本是jdk1.7.0_79。这是我的代码:

package javagame;
 import org.newdawn.slick.AppGameContainer;
 import org.newdawn.slick.GameContainer;
 import org.newdawn.slick.SlickException;
 import org.newdawn.slick.state.GameState;
 import org.newdawn.slick.state.StateBasedGame;
/*
 * First we import the things we need
*/
public class Game extends StateBasedGame{
public static final String gamename="Ham Blaster";
public static final int menu =0;
public static final int play =1;
/*
* Startup things of our game
*/
public Game(String gamename) {
    super(gamename);
    this.addState((GameState) new Menu(menu));
    this.addState((GameState) new Play(play));

}
/*
 * Here we create the two states or screens of our game.
 */
public void initStatesList (GameContainer gc)throws SlickException{
    this.getState(menu).init(gc, this);
    this.getState(play).init(gc, this);
    this.enterState(menu);
}
/*
 * Here we set the display settings and this is going to be our main method.
 */
public static void main(String[]args){
    AppGameContainer appgc;
    try{
        appgc=new AppGameContainer(newGame(gamename));
        appgc.setDisplayMode(640, 360, false);
        appgc.start();
    }catch(SlickException e){
        e.printStackTrace();
    }
}
}

它给了我关于newGame(gamename)的错误,说这个方法对于Game类型是未定义的。因为我正在使用Eclipse,所以当出现错误时它会给我一些指示,并指示我为它创建一个方法。 Eclipse创建了方法,方法代码为:

    private static org.newdawn.slick.Game newGame(String gamename2) {
    // TODO Auto-generated method stub
    return null;
}

我应该在里面写什么? 这里还有其他2个屏幕的代码: 播放屏幕:

package javagame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.state.StateBasedGame;

 public class Play extends Exception {
  public Play(int play){
  }
  public void init (GameContainer gc, StateBasedGame sbg) throws Play {
  }
  /* 
   Render is used to draw things
   */
  public void render (GameContainer gc, StateBasedGame sbg, Graphics g)throws Play {
  }
  /*
   Update is used to update the images in your game
   */
  public void update (GameContainer gc, StateBasedGame sbg, Graphics g, int delta)throws Play{  
  }
  public int getID(){
      return 1;
}
}

菜单屏幕:

package javagame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.state.StateBasedGame;

 public class Menu extends Exception {
  public Menu(int menu) {}
      public void init (GameContainer gc, StateBasedGame sbg) throws Menu {
      }
      public void render (GameContainer gc, StateBasedGame sbg, Graphics g)throws Menu {
      }
      public void update (GameContainer gc, StateBasedGame sbg, Graphics g, int delta)throws Menu{  
      }
      public int getID(){
          return 0;
}

}

错误的屏幕截图:

http://i.stack.imgur.com/8BamS.png

1 个答案:

答案 0 :(得分:0)

你的问题很简单。您需要撰写 // flag for GPS status boolean isGPSEnabled = false; // flag for network status boolean isNetworkEnabled = false; // flag for GPS status boolean canGetLocation = false; try { locationManager = (LocationManager) getActivity() .getSystemService(LOCATION_SERVICE); // getting GPS status isGPSEnabled = locationManager .isProviderEnabled(LocationManager.GPS_PROVIDER); // getting network status isNetworkEnabled = locationManager .isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (!isGPSEnabled && !isNetworkEnabled) { // no network provider is enabled } else { this.canGetLocation = true; if (isNetworkEnabled) { //updates will be send according to these arguments locationManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); Log.d("Network", "Network"); if (locationManager != null) { location = locationManager .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (location != null) { latitude = location.getLatitude(); longitude = location.getLongitude(); } } } // if GPS Enabled get lat/long using GPS Services if (isGPSEnabled) { if (location == null) { locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this); Log.d("GPS Enabled", "GPS Enabled"); if (locationManager != null) { location = locationManager .getLastKnownLocation(LocationManager.GPS_PROVIDER); if (location != null) { latitude = location.getLatitude(); longitude = location.getLongitude(); } } } } } } catch (Exception e) { e.printStackTrace(); }

,而不是撰写appgc=new AppGameContainer(newGame(gamename));