//第 1 页
import java.awt.*;
import java.awt.event.*;
import java.util.Arrays;
import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.net.*;
import java.io.*;
import java.io.Serializable;
import java.net.Socket;
public class BoardPanel extends JPanel{
private static Image white = null;
private static Image black = null;
private static int xp; //放置棋子的位置X坐标
private static int yp; //放置棋子的位置y坐标
private Cursor handCursor;
private Cursor defaultCursor;
protected static int board[][]; //记录每一个黑棋或者白棋棋子的位置
private int color=1; //记录选手的棋子的颜色1=black 2=white
int STEPCOUNTER=0;
int BASE=5;
int DEEPTH=3;
int MINDEEPTH=3;
int MAX1=5;
long INVALID=9000000;
int chessBoard[][];
//绘制出棋盘x和y轴方向的棋盘线上的字数标号
String line="a b c d e f g h i j k l m n o";
char [] rowNum1={'1','2','3','4','5','6','7','8','9'};
char [] rowNum2={'1','0','1','1','1','2','1','3','1','4','1','5'};
public BoardPanel(){
try{
handCursor=new Cursor(12);
defaultCursor= new Cursor(0);
board=new int[15][15];
jbInit();
}
catch(Exception e){
e.printStackTrace();
}
}
//绘制整个棋盘界面
public void paint(Graphics gc){
super.paint(gc);
gc.setColor(Color.blue);
gc.drawString(line,25,15);
for(int i=0;i<9;i++){
gc.drawChars(rowNum1,i,1,10,35+i*30);
}
// 第 2 页
for(int i=9,j=0;i<15;i++,j+=2){
gc.drawChars(rowNum2,j,2,10,35+i*30);
}
//绘制棋盘
for(int i=0;i<15;i++){
gc.drawLine(30,30+i*30,450,30+i*30); //绘制棋盘的行线
gc.drawLine(30+i*30,30,30+i*30,450);//绘制棋盘的列线
}
gc.drawLine(25,25,455,25);
gc.drawLine(25,25,25,455);
gc.drawLine(25,455,455,455);
gc.drawLine(455,25,455,455);
//当窗体被重画时,将绘制出棋盘重画之前的状态
for(int i=0;i<15;i++){
for(int j=0;j<15;j++){
xp=16+i*30;
yp=16+j*30;
if(board[i][j]==1){
gc.setColor(Color.black);
gc.fillOval(xp,yp,28,28);
}
if(board[i][j]==2){
gc.setColor(Color.white);
gc.fillOval(xp,yp,28,28);
}
}
}
}
private void jbInit() throws Exception {
this.addMouseMotionListener(new ChessWZQ_this_mouseMotionAdapter(this));
this.addMouseListener(new ChessWZQ_this_mouseAdapter(this));
}
public int getColor(){
return color;
}
public v
oid setColor(int cr){
color=cr;
}
/**
*当窗体更新时,清空棋盘
*/
public void clearBoard(){
for(int i=0;i<15;i++){
for(int j=0;j<15;j++)
board[i][j]=0;
//第 3 页
}
repaint();
}
//鼠标点击事件处理方法
void this_mouseClicked(MouseEvent e){
int x=0,y=0;
if(color==0){
return;
}
x=e.getX();
y=e.getY();
//判断单击的位置是否在合法的范围内
if(x>20&;&;x<460&;&;y>20&;&;y<460&;&;(x%30<10||x%30>20)&;&;(y%30<10||y%30>20)){
if(ChessWZQ.beginFlag==false){
ChessWZQ.label6.setText("You may not do that");
return;
}
xp=x/30*30-14;
yp=y/30*30-14;
if(x%30>20){
xp+=30;
}
if(y%30>20){
yp+=30;
}
x=xp/30;y=yp/30;
if(board[x][y]!=0){
return;
}
//客户端的棋盘
board[xp/30][yp/30]=color;
Graphics g=this.getGraphics();
if(color==1){//设置画笔为黑色
g.setColor(Color.black);
}
if(color==2){//设置画笔为白色
g.setColor(Color.white);
}
//在单击位置绘制棋子
g.fillOval(xp,yp,28,28);
ChessWZQ.beginFlag=false;
if(ChessWZQ.ptocFlag==false){
Message msg=new Message();
msg