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

7vhp5slm  于 2023-10-18  发布在  Eclipse
关注(0)|答案(1)|浏览(155)

我正在创建一个游戏,我使用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(gambling)上给了我错误,说这个方法对于类型Game是未定义的。由于我使用Eclipse,当出现错误时,它会给我一些指示,并指示我为它创建一个方法。Eclipse创建了方法,下面是方法代码:

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

我应该在里面写些什么?下面是另外两个屏幕的代码:播放屏幕:

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;
}

}

错误的屏幕截图:
https://i.stack.imgur.com/8BamS.png

qacovj5a

qacovj5a1#

你的问题很简单。不需要写appgc=new AppGameContainer(newGame(gamename));,而需要写appgc=new AppGameContainer(new Game(gamename));

相关问题