資源簡介
這次更新了,實現了悔棋的功能,新手寫的,各位大蝦見諒,這次更新了,實現了悔棋的功能,新手寫的,各位大蝦見諒

代碼片段和文件信息
package?com.itjob;
import?java.awt.Canvas;
import?java.awt.Color;
import?java.awt.Font;
import?java.awt.Graphics;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?java.awt.event.MouseEvent;
import?java.awt.event.MouseListener;
import?java.util.Stack;
import?javax.swing.JButton;
import?javax.swing.JOptionPane;
import?sun.java2d.loops.DrawLine;
/**
?*?棋盤類
?*/
public?class?Board?extends?Canvas?implements?MouseListenerRunnableActionListener
{
private?Huiqi?hq;
private?Huiqi?jbhq;
Stack?stack=new?Stack();
//計算棧存的對象數
int?h=0;
public?JButton?jb=new?JButton(“悔棋“);
private?boolean?hqFlag=false;
private?int?r0g0b0;
private?int?jop=0;
int?count=0;
//定義棋盤中需要控制的點
private?int[][]?point=new?int[10][9];
//定義一個棋子類
private?Man?man=new?Man();
//定義一個提示的類,棋子閃爍
// private?Tishi?ts=new?Tishi();
// private?Thread?t=new?Thread(ts);
//定義當前選中的子
private?int?currrow;
private?int?currcol;
//定義是該那個顏色的棋子走?false是黑棋走,true是紅棋走
private?boolean?flag=false;
//定義是否選中子
private?boolean?selected=false;
public?int?getJop()?{
return?jop;
}
public?void?setJop(int?jop)?{
this.jop?=?jop;
}
public?Board()
{
//this.setBackground(c);改棋盤的背景
this.addMouseListener(this);
jb.addActionListener(this);
this.initPoint();
new?Thread(this).start();
// System.out.println(“Board----“+jb);
}
/**
?*?每一顆棋子的移動規則
?*/
public?void?guize(int?currrowint?currcolint?rowint?col)
{
System.out.println(“----走子位子是“+“(“+row+““+col+“)__“+point[row][col]+“\n“);
//將下棋的位子保存到棧中
hq.setX(currcol);
hq.setY(currrow);
hq.setX1(col);
hq.setY1(row);
hq.setType1(point[this.currrow][this.currcol]);
hq.setType2(point[row][col]);
this.point[row][col]=this.point[this.currrow][this.currcol];
this.point[this.currrow][this.currcol]=0;
this.selected=false;
}
//初始化棋子
public?void?initPoint()
{
for(int?pr=0;pr<10;pr++){
for(int?pc=0;pc<9;pc++)
{
point[pr][pc]=0;
}
}
//黑棋
this.point[0][0]=1;
this.point[0][1]=2;
this.point[0][2]=3;
this.point[0][3]=4;
this.point[0][4]=5;
this.point[0][5]=4;
this.point[0][6]=3;
this.point[0][7]=2;
this.point[0][8]=1;
this.point[2][1]=6;
this.point[2][7]=6;
this.point[3][0]=7;
this.point[3][2]=7;
this.point[3][4]=7;
this.point[3][6]=7;
this.point[3][8]=7;
this.point[6][0]=14;
this.point[6][2]=14;
this.point[6][4]=14;
this.point[6][6]=14;
this.point[6][8]=14;
this.point[7][1]=13;
this.point[7][7]=13;
this.point[9][0]=8;
this.point[9][1]=9;
this.point[9][2]=10;
this.point[9][3]=11;
this.point[9][4]=12;
this.point[9][5]=11;
this.point[9][6]=10;
this.point[9][7]=9;
this.point[9][8]=8;
}
public?void?run()?{
System.out.println(“run“+Thread.currentThread().getName());
while(true){
repaint(this.currcol*50+10?this.currrow*50+10?50?50
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2012-02-03?19:49??xiangqi\
?????文件?????????232??2012-02-03?19:47??xiangqi\.classpath
?????文件?????????383??2012-02-03?19:47??xiangqi\.project
?????目錄???????????0??2012-02-03?19:49??xiangqi\bin\
?????目錄???????????0??2012-02-03?19:49??xiangqi\bin\com\
?????目錄???????????0??2012-02-03?19:49??xiangqi\bin\com\itjob\
?????文件???????15753??2012-02-03?19:47??xiangqi\bin\com\itjob\Board.class
?????文件????????1751??2012-02-03?19:47??xiangqi\bin\com\itjob\Huiqi.class
?????文件????????1577??2012-02-03?19:47??xiangqi\bin\com\itjob\MainGui.class
?????文件????????2481??2012-02-03?19:47??xiangqi\bin\com\itjob\Man.class
?????目錄???????????0??2012-02-03?19:49??xiangqi\images\
?????文件????????1030??2012-02-01?20:48??xiangqi\images\中.GIF
?????目錄???????????0??2012-02-03?19:49??xiangqi\src\
?????目錄???????????0??2012-02-03?19:49??xiangqi\src\com\
?????目錄???????????0??2012-02-03?19:49??xiangqi\src\com\itjob\
?????文件???????29310??2012-02-03?19:22??xiangqi\src\com\itjob\Board.java
?????文件????????1118??2012-02-03?15:23??xiangqi\src\com\itjob\Huiqi.java
?????文件????????1634??2012-02-03?18:45??xiangqi\src\com\itjob\MainGui.java
?????文件????????2563??2012-02-01?16:56??xiangqi\src\com\itjob\Man.java
評論
共有 條評論