Commit 724d0994 authored by YuFan Jia's avatar YuFan Jia 💤
Browse files

Merge branch 'Front' into 'Back'

feat(menu): add menu

See merge request !11
parents aaf8cdfd 3f87e927
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -174,6 +174,5 @@ public class ChessBoardPanel extends JPanel {

    public void autoZoom(int width, int height) {// zoom
        this.setSize(chessBoard[0][0].getPreferredSize());
        System.out.println("board\t" + this.getWidth() + "\t" + this.getHeight());
    }
}
 No newline at end of file
+13 −0
Original line number Diff line number Diff line
@@ -38,12 +38,24 @@ public class GameCore {
    }

    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 restart() {
        for (int i = 0; i != 8; ++i) {
            for (int j = 0; j != 8; ++j) {
                gamePanel.setChess(i, j, ChessPiece.EMPTY);
            }
        }
        intializeChess();
        currentPlayer = ChessPiece.BLACK;
        countScore();
    }

    public void swapPlayer() {// 交换玩家
        countScore();
        if (this.currentPlayer == ChessPiece.BLACK) {
@@ -51,6 +63,7 @@ public class GameCore {
        } else {
            this.currentPlayer = ChessPiece.BLACK;
        }
        ChessGameUI.thisStatus.setCurrentPlayer(currentPlayer);
        // todo:complete status panel
        // statusPanel.setPlayerText(currentPlayer.name());
        // statusPanel.setScoreText(blackScore, whiteScore);
+13 −12
Original line number Diff line number Diff line
@@ -6,36 +6,37 @@ import javax.swing.*;
/**
 * @author uint44t
 */
public class BasicBackground extends JFrame {
public class BasicBackground {
	public static ChessGameUI thisChessGameUI;
	public static StartMenuUI thisStartMenuUI;
	public static JFrame backFrame;

	public BasicBackground() {
		initComponents();
		thisChessGameUI = new ChessGameUI();
		thisStartMenuUI = new StartMenuUI();
		changePanel(thisChessGameUI);
		changePanel(thisStartMenuUI);
	}

	public void changePanel(JPanel o) {
		this.add(o);
	public static void changePanel(JPanel o) {
		backFrame.add(o);
		o.updateUI();
	}

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY
		// //GEN-BEGIN:initComponents

		backFrame = new JFrame();
		// ======== basic ========
		{
			this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
			this.setVisible(true);
			this.setTitle("Othello");
			this.setName("backFrame");
			Container basicContentPane = this.getContentPane();
			backFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
			backFrame.setVisible(true);
			backFrame.setTitle("Othello");
			backFrame.setName("backFrame");
			Container basicContentPane = backFrame.getContentPane();
			basicContentPane.setPreferredSize(new Dimension(700, 500));
			this.pack();
			this.setLocationRelativeTo(null);
			backFrame.pack();
			backFrame.setLocationRelativeTo(null);
		}
		// JFormDesigner - End of component initialization //GEN-END:initComponents
	}
+12 −0
Original line number Diff line number Diff line
@@ -67,6 +67,12 @@ public class ChessGameUI extends JPanel {
		}
	}

	private void menuBUttonActionPerformed() {
		JOptionPane.showConfirmDialog(null, "Are you sure to exit to menu?", "Waring", 2);
		BasicBackground.backFrame.remove(BasicBackground.thisChessGameUI);
		BasicBackground.changePanel(BasicBackground.thisStartMenuUI);
	}

	// private void cheatListener(ItemEvent e) {// 上面出发后弹出的选项卡的触发事件
	// String select = e.getItem().toString();
	// if (cheatOnOff.isSelected()) {
@@ -89,6 +95,7 @@ public class ChessGameUI extends JPanel {
	JComboBox cheat = new JComboBox();
	JRadioButton cheatOnOff = new JRadioButton();
	JPanel center;
	JButton menuButton = new JButton();

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY
@@ -159,6 +166,11 @@ public class ChessGameUI extends JPanel {
				undoButton.addActionListener(e -> undoButtonActionPerformed());
				bottomButtons.add(undoButton);

				// menubutton
				menuButton.setText("Menu");
				menuButton.addActionListener(e -> menuBUttonActionPerformed());
				bottomButtons.add(menuButton);

				// ---- cheatOnOff ----
				cheatOnOff.setText("Cheat");
				cheatOnOff.addActionListener(e -> cheatOnOffButtonActionPerformed());
+21 −19
Original line number Diff line number Diff line

package GameUI;

import java.awt.*;
import java.util.prefs.BackingStoreException;

import javax.swing.*;
/*
 * Created by JFormDesigner on Fri Dec 03 22:18:40 CST 2021
 */
import javax.swing.text.Position.Bias;
import javax.swing.plaf.basic.BasicHTML;

/**
 * @author uint44t
@@ -22,15 +16,18 @@ public class StartMenuUI extends JPanel {
	}

	private void newGaemButtonActionPerformed() {
		// .changePanel(BasicBackground.thisChessGameUI);
		BasicBackground.backFrame.remove(BasicBackground.thisStartMenuUI);
		BasicBackground.changePanel(BasicBackground.thisChessGameUI);
		BasicBackground.thisChessGameUI.thisGameCore.restart();
	}

	private void loadButtonActionPerformed() {
		// TODO add your code here
		new FileChooser(true);
		// todo: add import methord
	}

	private void exitButtonActionPerformed() {
		// TODO add your code here
		BasicBackground.backFrame.dispose();
	}

	private void initComponents() {
@@ -40,7 +37,7 @@ public class StartMenuUI extends JPanel {
		label1 = new JLabel();
		buttons = new JPanel();
		panel2 = new JPanel();
		label6 = new JLabel();
		label2 = new JLabel();
		panel5 = new JPanel();
		newGaemButton = new JButton();
		label5 = new JLabel();
@@ -55,11 +52,11 @@ public class StartMenuUI extends JPanel {

		// ======== title ========
		{
			title.setLayout(new CardLayout(20, 40));
			title.setLayout(new CardLayout());

			// ---- label1 ----
			label1.setText("Othello");
			label1.setFont(new Font("Sitka Banner", Font.BOLD, 48));
			label1.setFont(new Font("Sitka Banner", Font.BOLD, 60));
			label1.setHorizontalAlignment(SwingConstants.CENTER);
			label1.setEnabled(false);
			label1.setVisible(false);
@@ -73,11 +70,11 @@ public class StartMenuUI extends JPanel {

			// ======== panel2 ========
			{
				panel2.setLayout(new BoxLayout(panel2, BoxLayout.Y_AXIS));
				panel2.setLayout(new BoxLayout(panel2, BoxLayout.PAGE_AXIS));

				// ---- label6 ----
				label6.setText("  ");
				panel2.add(label6);
				// ---- label2 ----
				label2.setText(" ");
				panel2.add(label2);

				// ======== panel5 ========
				{
@@ -85,6 +82,7 @@ public class StartMenuUI extends JPanel {

					// ---- newGaemButton ----
					newGaemButton.setText("New Game");
					newGaemButton.setFont(buttonsStandard);
					newGaemButton.addActionListener(e -> newGaemButtonActionPerformed());
					panel5.add(newGaemButton);
				}
@@ -92,6 +90,7 @@ public class StartMenuUI extends JPanel {

				// ---- label5 ----
				label5.setText(" ");
				label5.setFont(buttonsStandard);
				panel2.add(label5);

				// ======== panel4 ========
@@ -100,6 +99,7 @@ public class StartMenuUI extends JPanel {

					// ---- loadButton ----
					loadButton.setText("Load");
					loadButton.setFont(buttonsStandard);
					loadButton.addActionListener(e -> loadButtonActionPerformed());
					panel4.add(loadButton);
				}
@@ -115,6 +115,7 @@ public class StartMenuUI extends JPanel {

					// ---- exitButton ----
					exitButton.setText("Exit");
					exitButton.setFont(buttonsStandard);
					exitButton.addActionListener(e -> exitButtonActionPerformed());
					panel6.add(exitButton);
				}
@@ -122,7 +123,7 @@ public class StartMenuUI extends JPanel {
			}
			buttons.add(panel2);
		}
		add(buttons, BorderLayout.CENTER);
		add(buttons, BorderLayout.SOUTH);
		// JFormDesigner - End of component initialization //GEN-END:initComponents
	}

@@ -131,7 +132,7 @@ public class StartMenuUI extends JPanel {
	private JLabel label1;
	private JPanel buttons;
	private JPanel panel2;
	private JLabel label6;
	private JLabel label2;
	private JPanel panel5;
	private JButton newGaemButton;
	private JLabel label5;
@@ -140,5 +141,6 @@ public class StartMenuUI extends JPanel {
	private JLabel label4;
	private JPanel panel6;
	private JButton exitButton;
	Font buttonsStandard = new Font("\u6977\u4f53", Font.PLAIN, 20);
	// JFormDesigner - End of variables declaration //GEN-END:variables
}
Loading