Warning: Undefined array key "night" in /www/wwwroot/dhaomu.com/wp-content/themes/b2/header.php on line 18

Java技术围棋游戏代码

Java技术: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);setBackground(Color.orange);

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)

{
if(e.getModifiers()==InputEvent.BUTTON1_MASK)

{
x=(int)e.getX();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;

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("请黑棋下子");

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)

{
this.removeAll();棋子颜色=-1;

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)

{
if(e.getModifiers()==InputEvent.BUTTON3_MASK)

{
chesspad.remove(this);

chesspad.棋子颜色=1;

chesspad.text_2.setText("");chesspad.text_1.setText("请黑棋下子");

}

}

public void mouseReleased(MouseEvent e)

{
}

public void mouseEntered(MouseEvent e)

{
}

public void mouseExited(MouseEvent e)

{
}

public void mouseClicked(MouseEvent e)

{
if(e.getClickCount()>2)

chesspad.remove(this);

}
温馨提示:
1.本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:duhaomu@163.com,我们将第一时间处理!
2.资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。
3.所有资源仅限于参考和学习,版权归原作者所有,更多请阅读网站声明

给TA赞赏
共{{data.count}}人
人已赞赏
编程技巧

织梦教程dede:channelartlist调用排除指定typeid栏目数据的方法

2023-10-31 0:00:00

编程技巧

Java技术五子棋游戏代码

2023-11-2 0:00:00

0 条回复 A文章作者 M管理员

Warning: Trying to access array offset on value of type null in /www/wwwroot/dhaomu.com/wp-content/themes/b2/functions.php on line 3914

Warning: Trying to access array offset on value of type null in /www/wwwroot/dhaomu.com/wp-content/themes/b2/functions.php on line 3914
----《》
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索