【发布时间】:2014-10-25 17:31:14
【问题描述】:
我最近一直在开发这款 Java 游戏。我试图添加带有音频剪辑的音乐,但它不起作用,所以我取出了我的主代码并删除了主代码,因为我不再需要它了。所有代码与我实现音乐之前的代码相同,但现在弹出这条消息,不允许我运行我的游戏:
错误:在类中找不到主要方法 com.illuminationsco.GoNerdGo.Entities.Obstacles,请定义 主要方法为:public static void main(String[] args)
当我尝试放回 main 时,它根本不运行!
如果有人可以帮助我,那就太好了!
这是我的代码:
Bully bully = new Bully();
Nerd nerd = new Nerd();
static BufferedImage[] sprites;
public static float x, y, velX = 5.5f, velY = 5.5f;
public static int whatObstacle = 5;
public static int basketBall = 6;
public static int lava = 2;
public static int trash = 1;
public static boolean trashOpen = false;
public Rectangle getBounds() {
return null;
}
public Obstacles() {
int width = 100;
int height = 100;
int columns = 2;
int rows = 2;
BufferedImage spriteSheet = null;
try {
spriteSheet = ImageIO.read(new File(
"res/Images/ObstacleSpriteSheet.png"));
} catch (IOException e) {
e.printStackTrace();
}
sprites = new BufferedImage[rows * columns];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
sprites[(i * columns) + j] = spriteSheet.getSubimage(i * width,
j * height, width, height);
}
}
}
public void tick() {
if (whatObstacle >= basketBall && Game.gos == null) {
x += velX;
y += velY;
}
if (x <= 0 || x >= 800 - 35) {
velX *= -1;
}
if (y <= 425 || y >= 600 - 35) {
velY *= -1;
}
}
public void render(Graphics g) {
if (whatObstacle >= basketBall) {
// Displaying basketball
g.drawImage(sprites[3], (int) x, (int) y, null);
Rectangle basketballRect = new Rectangle((int) x, (int) y, 35, 35);
if (nerd.getFeetBounds().intersects(basketballRect)) {
Game.setOverGameState(Game.GameOverlayState.BullyWins);
}
if (bully.getFeetBounds().intersects(basketballRect)) {
Game.setOverGameState(Game.GameOverlayState.NerdWins);
}
// Displaying lava pool
} else if (whatObstacle >= lava) {
g.drawImage(sprites[2], (int) x, (int) y, null);
Rectangle lavaRect = new Rectangle((int) x + 5, (int) y + 7, 80, 19);
if (nerd.getFeetBounds().intersects(lavaRect)) {
Game.setOverGameState(Game.GameOverlayState.BullyWins);
}
if (bully.getFeetBounds().intersects(lavaRect)) {
Game.setOverGameState(Game.GameOverlayState.NerdWins);
}
// Displaying trash can
} else if (whatObstacle == trash) {
if (trashOpen) {
g.drawImage(sprites[1], (int) x, (int) y, null);
} else {
g.drawImage(sprites[0], (int) x, (int) y, null);
}
Rectangle trashRect = new Rectangle((int) x, (int) y, 60, 97);
if (bully.getBounds().intersects(trashRect)) {
Game.setOverGameState(Game.GameOverlayState.BullyWins);
Obstacles.trashOpen = true;
}
}
}
【问题讨论】:
-
简单,把
main方法放回去就好了。 -
您是否阅读了您发布的错误消息?它已经告诉你该怎么做。 ;)
-
我试过了,但它根本没有运行