problem is in the first,as said in title, it doesnt load the saved game, it loads the game currently in the board to a new board.
`void carregar(){
String z = board.promptText(“Qual é o nome do ficheiro a carregar?”);
if (z == null || z.isEmpty()) {
return;
}
PositionTrace novoModel = new PositionTrace(model.blackCount, model.whiteCount, model.linha, model.coluna);
Board novoTabuleiro = new Board(quemJoga(), novoModel.linha, novoModel.coluna, 60);
novoTabuleiro.setBackgroundProvider(this::background);
novoTabuleiro.setIconProvider(this::icon);
novoTabuleiro.addMouseListener(this::click);
novoTabuleiro.addAction(“Novo Jogo”, this::action);
novoTabuleiro.addAction(“Aleatório”, this::aleatorio);
novoTabuleiro.addAction(“Gravar”, this::gravar);
novoTabuleiro.addAction(“Carregar”, this::carregar);
novoModel.load(z);
novoTabuleiro.setTitle(quemJoga());
novoTabuleiro.open();
}
void load(String fileName) {
try {
File file = new File(fileName);
Scanner scanner = new Scanner(file);
jogamBrancas = Boolean.parseBoolean(scanner.nextLine());
linha = Integer.parseInt(scanner.nextLine());
coluna = Integer.parseInt(scanner.nextLine());
blackCount = Integer.parseInt(scanner.nextLine());
whiteCount = Integer.parseInt(scanner.nextLine());
positionWhities = new Position[whiteCount];
positionBlackies = new Position[blackCount];
for (int i = 0; i < whiteCount; i++) {
int line = Integer.parseInt(scanner.nextLine());
int col = Integer.parseInt(scanner.nextLine());
positionWhities[i] = new Position(line, col);
}
for (int i = 0; i < blackCount; i++) {
int line = Integer.parseInt(scanner.nextLine());
int col = Integer.parseInt(scanner.nextLine());
positionBlackies[i] = new Position(line, col);
}
scanner.close();
System.out.println("Jogo carregado com sucesso de " + fileName);
} catch (FileNotFoundException e) {
System.out.println("Erro: Arquivo não encontrado.");
} catch (Exception e) {
System.out.println("Erro ao carregar o arquivo: " + e.getMessage());
}
}`
i tried with the funcion i have “view” who does those (this::…) typa sh… but then it would ask for the side of the board as the funcion view does…
Henrique Henriques is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.