Commit aaf8cdfd authored by 林修诚's avatar 林修诚
Browse files
parent 1ecfc386
Loading
Loading
Loading
Loading
+17 −146
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@ import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.io.FileNotFoundException;

import Components.ChessBoardPanel;
import GameUI.ChessGameUI;
@@ -24,7 +26,6 @@ public class GameCore {
    private String exportPath;
    private int panelWidth;
    private int panelHeight;
    private CheatStatus cs;

    public GameCore(int rows, int cols) {
        this.gamePanel = new ChessBoardPanel(rows, cols);
@@ -33,7 +34,7 @@ public class GameCore {
        blackScore = 2;
        whiteScore = 2;
        ChessGameUI.thisStatus.setScore(blackScore, whiteScore);
        this.cs = CheatStatus.Off;

    }

    private void intializeChess() {// 初始化放棋
@@ -82,19 +83,18 @@ public class GameCore {
        // todo 在这里更新scorebar的分数
    }

    public void readFileData(String fileName) {// 读存档
    public void readFileData(String filePath) throws FileNotFoundException {
        // todo: read date from file
        List<String> fileData = new ArrayList<>();
        try {
            FileReader fileReader = new FileReader(fileName);
            BufferedReader bufferedReader = new BufferedReader(fileReader);
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                fileData.add(line);
            }
            fileData.forEach(System.out::println);
        } catch (IOException e) {
            e.printStackTrace();
        BufferedReader br = new BufferedReader(new FileReader(filePath));
        Scanner in = new Scanner(br);
        String str = in.nextLine();
        in.close();
        this.gamePanel.readGame(str);
        countScore();
        if (str.substring(64).equals("b")) {
            currentPlayer = ChessPiece.BLACK;
        } else {
            currentPlayer = ChessPiece.WHITE;
        }
    }

@@ -112,7 +112,7 @@ public class GameCore {
    }

    public boolean canClick(int row, int col) {// 可以被点击
        return gamePanel.canClickGrid(row, col, currentPlayer) || this.cs == CheatStatus.On;
        return gamePanel.canClickGrid(row, col, currentPlayer) || ChessGameUI.thisCheatModeStatus == CheatStatus.On;
    }

    public void undo() {// 撤销
@@ -131,7 +131,7 @@ public class GameCore {
        return ChessPiece.EMPTY;
    }

    public void setImportpath(String importPath) {
    public void setImportpath(String importPath) throws FileNotFoundException {
        this.importPath = importPath;
        System.out.println(this.importPath);
        readFileData(importPath);
@@ -151,132 +151,3 @@ public class GameCore {
        return gamePanel;
    }
}
 No newline at end of file
// =======
// package Core;

// import java.io.BufferedReader;
// import java.io.FileReader;
// import java.io.IOException;
// import java.util.ArrayList;
// import java.util.List;

// import Components.ChessBoardPanel;
// import GameUI.ChessGameUI;
// import Model.ChessPiece;

// public class GameCore {
// private ChessBoardPanel gamePanel;// 棋盘
// private int blackScore;// 字面意思
// private int whiteScore;
// private ChessPiece currentPlayer;// 当前该谁下棋
// private String importPath;
// private String exportPath;
// private int panelWidth;
// private int panelHeight;

// public GameCore(int rows, int cols) {
// this.gamePanel = new ChessBoardPanel(rows, cols);
// this.currentPlayer = ChessPiece.BLACK;
// intializeChess();
// blackScore = 2;
// whiteScore = 2;
// ChessGameUI.thisStatus.setScore(blackScore, whiteScore);
// }

// private void intializeChess() {// 初始化放棋
// gamePanel.setChess(3, 3, ChessPiece.BLACK);
// gamePanel.setChess(4, 4, ChessPiece.BLACK);
// gamePanel.setChess(3, 4, ChessPiece.WHITE);
// gamePanel.setChess(4, 3, ChessPiece.WHITE);
// }

// public void swapPlayer() {// 交换玩家
// countScore();
// currentPlayer = (currentPlayer == ChessPiece.BLACK) ? ChessPiece.WHITE :
// ChessPiece.BLACK;
// ChessGameUI.thisStatus.setCurrentPlayer(currentPlayer);
// ChessGameUI.thisStatus.setScore(blackScore, whiteScore);
// // todo:complete status panel
// // statusPanel.setPlayerText(currentPlayer.name());
// // statusPanel.setScoreText(blackScore, whiteScore);
// }

// public void zoom(int outerWidth, int outHeight) {// 缩放
// panelWidth = outerWidth;
// panelHeight = outHeight;
// gamePanel.autoZoom(panelWidth, panelHeight);
// // todo complete zoom
// }

// public void countScore() {// 计分
// // todo: modify the countScore method
// }

// public void readFileData(String fileName) {// 读存档
// // todo: read date from file
// List<String> fileData = new ArrayList<>();
// try {
// FileReader fileReader = new FileReader(fileName);
// BufferedReader bufferedReader = new BufferedReader(fileReader);
// String line;
// while ((line = bufferedReader.readLine()) != null) {
// fileData.add(line);
// }
// fileData.forEach(System.out::println);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }

// public void writeDataToFile(String fileName) {// 写存档
// // todo: write data into file
// }

// public boolean canClick(int row, int col) {// 可以被点击
// // todo
// return gamePanel.canClickGrid(row, col, currentPlayer);
// }

// public void undo() {// 撤销
// // todo
// }

// private ChessPiece checkWinner() {// 检测胜者
// // todo(用ChessPiece.EMPTY表示平局)
// return null;
// }

// private boolean canMove() {// 当前玩家有处可下
// // todo
// return true;
// }

// public void setImportpath(String importPath) {
// this.importPath = importPath;
// System.out.println(this.importPath);
// readFileData(importPath);
// }

// public void setExportPath(String exportPath) {
// this.exportPath = exportPath;
// System.out.println(this.exportPath);
// writeDataToFile(exportPath);
// }

// public ChessPiece getCurrentPlayer() {
// return currentPlayer;
// }

// public ChessBoardPanel getGamePanel() {// 应该没啥用
// return gamePanel;
// }

// public int getRows() {
// return 8;
// }

// public int getCols() {
// return 8;
// }
// }
// >>>>>>> Front
+22 −6
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ package GameUI;

import java.awt.*;
import java.awt.event.*;
import java.io.FileNotFoundException;
import java.text.DecimalFormat;

import javax.swing.*;
@@ -35,24 +36,25 @@ public class ChessGameUI extends JPanel {
		return thisCheatModeStatus;
	}

	private void importButtonActionPerformed() {// import按钮触发事件
	private void importButtonActionPerformed() throws FileNotFoundException {// import按钮触发事件
		String tem = new FileChooser(true).Path();
		if (tem != null)
			thisGameCore.setImportpath(tem);
	}

	private void exportButtonActionPerformed() {// export按钮触发事件
	private void exportButtonActionPerformed() throws FileNotFoundException {// export按钮触发事件
		String tem = new FileChooser(false).Path();
		if (tem != null)
		if (tem != null) {
			thisGameCore.setImportpath(tem);
		}
	}

	private void restartButtonActionPerformed() {// restart按钮触发事件
		new ChessGameUI();
	}

	private void undoButtonActionPerformed() {// undo按钮触发事件
		// TODO add your code here
		thisGameCore.undo();
	}

	private void cheatOnOffButtonActionPerformed() {// cheat单选按钮被按下的触发事件
@@ -125,12 +127,26 @@ public class ChessGameUI extends JPanel {

				// ---- importButton ----
				importButton.setText("Import");
				importButton.addActionListener(e -> importButtonActionPerformed());
				importButton.addActionListener(e -> {
					try {
						importButtonActionPerformed();
					} catch (FileNotFoundException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				});
				bottomButtons.add(importButton);

				// ---- exportButton ----
				exportButton.setText("Export");
				exportButton.addActionListener(e -> exportButtonActionPerformed());
				exportButton.addActionListener(e -> {
					try {
						exportButtonActionPerformed();
					} catch (FileNotFoundException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				});
				bottomButtons.add(exportButton);

				// ---- restartButton ----