資源簡介
內(nèi)容索引:JAVA源碼,游戲娛樂,五子棋
基于GUI的Java五子棋游戲源碼,可人機(jī)對戰(zhàn),用java swing做的,運(yùn)行時需要修改圖片的路徑。
制作思路:
用按鈕做棋子,用圖片填充每個按鈕。
設(shè)置棋盤為24*24的,五子棋FiveChessGame類,繼承了JFrame,并且添加了時間監(jiān)聽,五子棋的棋子chess,用JButton表示,五子棋棋子chess對應(yīng)的棋子標(biāo)識,用于標(biāo)記棋子的狀態(tài)。 1表示黑棋,-1表示白棋,默認(rèn)0表示無棋子,點(diǎn)擊棋子時設(shè)置棋子的圖標(biāo)setOnChessIcon。 根據(jù)判斷該位置的棋子是否有棋子,和棋子顏色設(shè)置棋子圖標(biāo)
測試棋子的方法showChess。用于將chessInt數(shù)組內(nèi)容打印到控制臺,以便觀看。

代碼片段和文件信息
package?FiveChessGame;
//download?by?http://www.codefans.net
import?javax.swing.*;
import?java.awt.*;
import?java.awt.event.*;
public?class?AboutDialog?extends?JDialog?implements?ActionListener?{
private?static?final?long?serialVersionUID?=?1L;
boolean?restartflag?=?false;
public?AboutDialog(Jframe?jframe)?{
//?TODO?Auto-generated?constructor?stub
super(jframe?“關(guān)于“?true);
this.setLayout(new?GridLayout(41));
JButton?closeButton?=?new?JButton(“關(guān)閉“);
JLabel?label1?=?new?JLabel(“單機(jī)版五子棋v1.0“);
JLabel?label2=new?JLabel(“Made?by?MYlitBoY“);
JLabel?label3=new?JLabel(“Made:2010.6.7-6.86.23-6.25“);
closeButton.addActionListener(this);
closeButton.setActionCommand(“Close“);
this.add(label1);
this.add(label2);
this.add(label3);
this.add(closeButton);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setLocation(400?350);
this.setSize(260?300);
this.pack();
this.setResizable(false);
this.setVisible(true);
}
public?boolean?getButtonPrassed()?{
return?restartflag;
}
public?void?actionPerformed(ActionEvent?arg0)?{
if?(arg0.getActionCommand()?==?“Close“)?{
this.dispose();
this.toBack();
}?
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-08-15?09:39??GUI版Java五子棋源碼,可人機(jī)對戰(zhàn)\
?????文件?????????562??2018-08-15?09:39??GUI版Java五子棋源碼,可人機(jī)對戰(zhàn)\下載說明.txt
評論
共有 條評論