我正在编写一个java游戏。这几乎已经完成,但它给了我一个错误(我不明白它为什么会发生,代码似乎没问题)。 错误。
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: projetofinal.ProjetoFinalv2.movimento
at projetofinal.ProjetoFinalv2.main(ProjetoFinalv2.java:26)
C:\Users\Francisco\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 2 seconds)
以下是代码:
package projetofinal;
import java.util.Scanner;
import java.util.Random;
public class ProjetoFinalv2 {
static char[][] tabuleiro;
static int x, y, jogadorX, jogadorY, pontos;
static char direction;
static boolean inGame = true;
public static void main(String[] args) {
x = 5;
y = 5;
tabuleiro = new char[x][y];
jogadorX = 0;
jogadorY = 4;
pontos = 7;
quadro();
while(inGame == true)
{
customcreator();
Scanner scan = new Scanner(System.in);
String resposta = scan.nextLine();
movimento(resposta.charAt(0));
}
}
public static void placePot()
{
boolean notDone = true;
while(notDone)
{
int tabX = random(0, 4);
int tabY = random(0, 4);
if(tabuleiro[tabX][tabY] == '.')
{
tabuleiro[tabX][tabY] = 'P';
notDone = false;
}
}
}
public static boolean bomba(int x, int y)
{
if(tabuleiro[x][y] == 'B')
{
return true;
}
else
{
return false;
}
}
public static boolean win()
{
if(tabuleiro[jogadorX][jogadorY] == 'F')
{
return true;
}
else
{
return false;
}
}
public static boolean gameover()
{
if(pontos > 0)
{
return false;
}
else
{
return true;
}
}
public static int potepoints(int x, int y)
{
if(tabuleiro[x][y] == 'P')
{
return random(3,5);
}
else
{
return -1;
}
}
public static void quadro()
{
for(int linha = 0; linha < x; linha++)
{
for(int vertical = 0; vertical < y; vertical++)
{
tabuleiro[linha][vertical] = '.';
}
}
//Por as bombas na posição correta
for(int i = quantos(); i>0; i--)
{
boolean tab = true;
while(tab)
{
int tabX = random(1, 3);
int tabY = random(1, 2);
if(tabuleiro[tabX][tabY] != 'B')
{
tabuleiro[tabX][tabY] = 'B';
tab = false;
}
}
}
//Mete o pote que da pontos
placePot();
}
public static void tabuleirocreator()
{
playercreator();
for(int linha = 0; linha < y; linha++)
{
for(int vertical = 0; vertical < x; vertical++)
{
System.out.print(tabuleiro[vertical][linha]);
}
System.out.print("\n");
}
}
public static void playercreator()
{
tabuleiro[jogadorX][jogadorY] = 'J';
}
public static void customcreator()
{
tabuleiro[0][4] = 'I';
tabuleiro[4][0] = 'F';
tabuleirocreator();
}
public static int random(int min, int max)
{
Random generator = new Random();
int Num = generator.nextInt((max - min) + 1) + min;
return Num;
}
public static int quantos()
{
return random(2, 3);
}
}
//Ciclo do jogo
public static void movimento(char newDirection)
{
if(newDirection == 'w' || newDirection == 'W')
{
if(jogadorY > 0)
{
tabuleiro[jogadorX][jogadorY] = '.';
jogadorY -= 1;
pontos--;
}
}
else
{
if(newDirection == 'a' || newDirection == 'A')
{
if(jogadorX > 0)
{
tabuleiro[jogadorX][jogadorY] = '.';
jogadorX -= 1;
pontos--;
}
}
else
{
if(newDirection == 's' || newDirection == 'S')
{
if(jogadorY < 4)
{
tabuleiro[jogadorX][jogadorY] = '.';
jogadorY += 1;
pontos--;
}
}
else
{
if(newDirection == 'd' || newDirection == 'D')
{
if(jogadorX < 4)
{
tabuleiro[jogadorX][jogadorY] = '.';
jogadorX += 1;
pontos--;
}
}
else
{
System.out.println("Wrong direction!");
}
}
}
}
if(bomba(jogadorX, jogadorY))
{
pontos = 0;
}
int tab = potepoints(jogadorX, jogadorY);
if(tab != -1)
{
pontos += tab;
}
if(win())
{
System.out.println("You won");
inGame = false;
}
if(gameover())
{
System.out.println("Game Over");
inGame = false;
}
}
//////////////////////////////////////////////////////////////
我是java中的小伙伴(我最近开始学习)所以,如果问题不好,我很抱歉。
答案 0 :(得分:-1)
该消息告诉您编译器找不到projetofinal.ProjetoFinalv2.movimento
的定义,第26行的符号为movimento(resposta.charAt(0));
。但movimento
未在类中定义。类定义以}
的孤立方法定义之前的右括号(movimento
)结束。这不仅使调用者无法访问方法定义,而且在类之外定义方法或变量也是完全违法的。