资源描述:
《java实现五子棋设计源代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、五子棋java实现代码packagewuziqi1;importjava.applet.*;importjava.applet.Applet;importjava.awt.*;importjava.awt.Color;importjava.awt.event.*;publicclasswuziqiextendsAppletimplementsActionListener,MouseListener,MouseMotionListener,ItemListener{intcolor_Qizi=0;///////////
2、//////////////////旗子的颜色标识0:白子1:黑子intgamestart=0;///////////////////////////////游戏开始标志0未开始1游戏中intgamebody[][]=newint[16][16];////设置棋盘棋子状态0无子1白子2黑子Buttonb1=newButton("游戏开始");Buttonb2=newButton("重置游戏");Buttonb3=newButton("退出游戏");LabellblWin=newLabel("");//////////
3、//////////状态标签CheckboxckbHB[]=newCheckbox[2];/////////////起始复选框CheckboxGroupckgHB=newCheckboxGroup();////////复选框组publicvoidinit(){resize(420,360);setLayout(null);addMouseListener(this);add(b1);b1.setBounds(330,100,70,30);b1.addActionListener(this);add(b2);b2.se
4、tBounds(330,140,70,30);b2.addActionListener(this);add(b3);b3.setBounds(330,180,70,30);b3.addActionListener(this);ckbHB[0]=newCheckbox("白子先",ckgHB,false);ckbHB[0].setBounds(330,30,70,30);ckbHB[1]=newCheckbox("黑子先",ckgHB,false);ckbHB[1].setBounds(330,60,70,30);ad
5、d(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();}publicvoiditemStateChanged(ItemEvente){if(ckbHB[0]
6、.getState())////////////////////////判断黑子先还是白子先{color_Qizi=0;}else{color_Qizi=1;}}publicvoidactionPerformed(ActionEvente){if(e.getSource()==b1)/////////////////////////////////开始游戏{Game_start();}elseif(e.getSource()==b3)/////////////////////////////退出游戏{Game_sto
7、p();}else////e.getSource()==b2//////////////////////////////重新开始{Game_re();}}publicvoidmouseClicked(MouseEvente){intx1,y1;x1=e.getX();y1=e.getY();if(e.getX()<20
8、
9、e.getX()>300
10、
11、e.getY()<20
12、
13、e.getY()>300){return;}if(x1%20>10){x1+=20;}if(y1%20>10){y1+=20;}x1=x1/20
14、*20;y1=y1/20*20;set_Qizi(x1,y1);}publicvoidmousePressed(MouseEvente){}publicvoidmouseEntered(MouseEvente){}publicvoidmouseExited(MouseEvente){}publicvoidmouseReleased(MouseE