刚写的五子棋,求高手帮我把判断输赢的功能加进去 跪谢了!
import java.awt.*;
import java.awt.event.*;
//创建棋盘的类
class ChessPad extends Panel implements MouseListener,ActionListener
{
int x=-1,y=-1,chesscolour=1; //chesscolour存放棋子颜色
Button button=new Button("重新开局");
TextField text_1=new TextField("请黑棋下子");
//int Chesscolour[][]=new int[19][19]; 构造存放下子颜色的数组,以备实现判断输赢
//int i=0,j=0;
ChessPad()
{ setSize(440,440);
setLayout(null);
setBackground(Color.orange);
addMouseListener(this);
add(button);
button.setBounds(10,3,60,26);
button.addActionListener(this);
add(text_1);
text_1.setBounds(90,3,90,24);
text_1.setEditable(false);
}
public void paint(Graphics g) //绘制棋盘方格
{ for(int i=30;i<=410;i=i+20) //画横线
{ g.drawLine(30,i,410,i);
}
for(int j=30;j<=410;j=j+20) //画竖线
{ g.drawLine(j,30,j,410);
}
}
//*********************************************************************
public void mousePressed(MouseEvent e) //当按下鼠标左键时下棋子
{ if(e.getModifiers()==InputEvent.BUTTON1_MASK)
{ x=(int)e.getX(); //x,y存放按下鼠标时的坐标位置
y=(int)e.getY();
ChessPoint_black chesspoint_black=new ChessPoint_black(this);
ChessPoint_white chesspoint_white=new ChessPoint_white(this);
int a=(x+10)/20,b=(y+10)/20;
//20为棋盘方格边长.a=(x+10)/20,b=(y+10)/20和后面的a*20-9,b*20-9 配合使用 实现当鼠标点击在方格
//的范围内时,在这个方格指定的位置下棋子
if(x/15<2||y/15<2||x/15>26||y/15>26) //方法体为空,使在棋盘之外不能下棋子
{}
else
{
if(chesscolour==1) //棋子颜色时1对应下黑棋
{ this.add(chesspoint_black);
chesspoint_black.setBounds(a*20-8,b*20-8,16,16);
//i=(x-30)/20; //下子坐标转化为数组地址,用以存放颜色
//j=(y-30)/20;
//Chesscolour[i][j]=chesscolour;
chesscolour=chesscolour*(-1);
text_1.setText("请白棋下子");
}
else if(chesscolour==-1) //棋子颜色时-1对应下白棋
{ this.add(chesspoint_white);
chesspoint_white.setBounds(a*20-8,b*20-8,16,16);
chesscolour=chesscolour*(-1);
text_1.setText("请黑棋下子");
}
}
}
}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseClicked(MouseEvent e){}
public void actionPerformed(ActionEvent e) //实现重新开具
{ this.removeAll();
chesscolour=1;
add(button);
button.setBounds(10,3,60,26);
add(text_1);
text_1.setBounds(90,3,90,24);
text_1.setText("请黑棋下子");
}
}
class ChessPoint_black extends Canvas implements MouseListener //黑棋的类
{ ChessPad chesspad=null; //棋子所在棋盘
ChessPoint_black(ChessPad p)
{ setSize(16,16);
chesspad=p;
addMouseListener(this);