Проблема в том, что во-первых, как сказано в заголовке, не загружается сохраненная игра, а загружается игра, которая сейчас находится на доске, на новую доску.
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());
}
}
Я попробовал использовать функцию «Просмотр», которая делает эти (это::...) тип-ш... но тогда она запрашивала сторону доски в качестве представление функции делает...
Проблема в том, что во-первых, как сказано в заголовке, не загружается сохраненная игра, а загружается игра, которая сейчас находится на доске, на новую доску. [code]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()); } } [/code] Я попробовал использовать функцию «Просмотр», которая делает эти (это::...) тип-ш... но тогда она запрашивала сторону доски в качестве представление функции делает...