JAVA实现五子棋设计源代码.docVIP

  • 9
  • 0
  • 约7.98千字
  • 约 12页
  • 2017-09-15 发布于江西
  • 举报
JAVA实现五子棋设计源代码

五子棋java实现代码 package wuziqi1; import java.applet.*; import java.applet.Applet; import java.awt.*; import java.awt.Color; import java.awt.event.*; public class wuziqi extends Applet implements ActionListener,MouseListener, MouseMotionListener,ItemListener { int color_Qizi=0;/////////////////////////////旗子的颜色标识 0:白子 1:黑子 int gamestart=0;///////////////////////////////游戏开始标志 0未开始 1游戏中 int gamebody[][]=new int[16][16]; ////设置棋盘棋子状态 0 无子 1 白子 2 黑子 Button b1=new Button(游戏开始); Button b2=new Button(重置游戏); Button b3=new Button(退出游戏); Label lblWin=new Label();////////////////////状态标签 Checkbox ckbHB[]=new Checkbox[2];/////////////起始复选框 CheckboxGroup ckgHB=new CheckboxGroup();////////复选框组 public void init() { resize(420,360); setLayout(null); addMouseListener(this); add(b1); b1.setBounds(330,100,70,30); b1.addActionListener(this); add(b2); b2.setBounds(330,140,70,30); b2.addActionListener(this); add(b3); b3.setBounds(330,180,70,30); b3.addActionListener(this); ckbHB[0]=new Checkbox(白子先,ckgHB,false); ckbHB[0].setBounds(330,30,70,30); ckbHB[1]=new Checkbox(黑子先,ckgHB,false); ckbHB[1].setBounds(330,60,70,30); add(ckbHB[0]); add(ckbHB[1]); ckbHB[0].addItemListener(this); ckbHB[1].addItemListener(this); add(lblWin); lblWin.setBounds(330,280,70,30); setBackground(Color.gray); setBounds(100,100,320,280); setVisible(true); start(); } public void itemStateChanged(ItemEvent e) { if (ckbHB[0].getState()) ////////////////////////判断黑子先还是白子先 { color_Qizi=0; } else { color_Qizi=1; } } public void actionPerformed(ActionEvent e) { if (e.getSource()==b1)/////////////////////////////////开始游戏 { Game_start(); } else if(e.getSource()==b3)/////////////////////////////退出游戏 { Game_stop(); } else////e.getSource()==b2//////////////////////////////重新开始 { Game_re();

文档评论(0)

1亿VIP精品文档

相关文档