java围棋代码_java围棋游戏源代码//@SuppressWarnings("serial")
class ChessPad extends Panel implements MouseListener,ActionListener
{
int x=-1,y=-1,棋⼦颜⾊=-1;
Button button=new Button("重新开始");
TextField text_1=new TextField("请⿊棋下⼦"),text_2=new TextField();
ChessPad()
{
setSize(440,440);
setLayout(null);ange);
addMouseListener(this);add(button);button.setBounds(10,5,60,26);
button.addActionListener(this);
add(text_1);text_1.setBounds(90,5,90,24);
add(text_2);text_2.setBounds(290,5,90,24);
text_1.setEditable(false);text_2.setEditable(false);
}
public void paint(Graphics g)
{
for(int i=40;i<=380;i=i+20){g.drawLine(40,i,400,i);}
g.drawLine(40,400,400,400);
for(int j=40;j<=390;j=j+20){g.drawLine(j,40,j,400);}
g.drawLine(400,40,400,400);
g.fillOval(97,97,6,6);g.fillOval(377,97,6,6);
g.fillOval(97,97,6,6);g.fillOval(337,337,6,6);
g.fillOval(217,217,6,6);
}
public void mousePressed(MouseEvent e)
{
Modifiers()==InputEvent.BUTTON1_MASK)
{
x=(X();y=(Y();
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;
if(x/20<2||y/20<2||x/20>19||y/20>19){}
else
{
if(棋⼦颜⾊==1)
{
this.add(chesspoint_black);
chesspoint_black.setBounds(a*20-10,b*20-10,20,20);棋⼦颜⾊=棋⼦颜⾊*(-1);
text_2.setText("请⽩棋下⼦");
text_1.setText("");
}
else if(棋⼦颜⾊==-1)
{
this.add(chesspoint_white);
chesspoint_white.setBounds(a*20-10,b*20-10,20,20);棋⼦颜⾊=棋⼦颜⾊*(-1);
text_1.setText("请⿊棋下⼦");
源代码1080p在线
text_2.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)
{
add(button);button.setBounds(10,5,60,26);
add(text_1);text_1.setBounds(90,5,90,24);
text_2.setText("");text_1.setText("请⿊⼦下棋");
add(text_2);text_2.setBounds(290,5,90,24);
}
}
//@SuppressWarnings("serial")
class ChessPoint_black extends Canvas implements MouseListener
{
ChessPad chesspad=null;
ChessPoint_black(ChessPad p)
{
setSize(20,20);chesspad=p;addMouseListener(this);
}
public void paint(Graphics g){g.setColor(Color.black);g.fillOval(0,0,20,20);} public void mousePressed(MouseEvent e)
{
Modifiers()==InputEvent.BUTTON3_MASK)
{
chesspad.棋⼦颜⾊=1;
<_2.setText("");_1.setText("请⿊棋下⼦");
}
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mouseClicked(MouseEvent e)
{
ClickCount()>2)
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。