资源描述:
《java五子棋程序(源码)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、一个很经典的java五子棋程序(源码)importjava.awt.*;importjava.awt.event.*;importjava.applet.Applet;importjava.awt.Color;publicclassenzitextendsAppletimplementsActionListener,MouseListener,MouseMotionListener,ItemListener{intcolor_Qizi=0;//旗子的颜色标识0:白子1:黑子intintGame_Start=0;//游戏开始标志0未开始1游戏中i
2、ntintGame_Body[][]=newint[16][16];//设置棋盘棋子状态0无子1白子2黑子Buttonb1=newButton("游戏开始");Buttonb2=newButton("重置游戏");LabellblWin=newLabel("");CheckboxckbHB[]=newCheckbox[2];CheckboxGroupckgHB=newCheckboxGroup();publicvoidinit(){setLayout(null);addMouseListener(this);add(b1);b1.setBoun
3、ds(330,50,80,30);b1.addActionListener(this);add(b2);b2.setBounds(330,90,80,30);b2.addActionListener(this);ckbHB[0]=newCheckbox("白子先",ckgHB,false);ckbHB[0].setBounds(320,20,60,30);ckbHB[1]=newCheckbox("黑子先",ckgHB,false);ckbHB[1].setBounds(380,20,60,30);add(ckbHB[0]);add(ckbHB
4、[1]);ckbHB[0].addItemListener(this);ckbHB[1].addItemListener(this);add(lblWin);lblWin.setBounds(330,130,80,30);Game_start_csh();}publicvoiditemStateChanged(ItemEvente){if(ckbHB[0].getState())//选择黑子先还是白子先{color_Qizi=0;}else{color_Qizi=1;}}publicvoidactionPerformed(ActionEvent
5、e){Graphicsg=getGraphics();if(e.getSource()==b1){Game_start();}else{Game_re();}}publicvoidmousePressed(MouseEvente){}publicvoidmouseClicked(MouseEvente){Graphicsg=getGraphics();intx1,y1;x1=e.getX();y1=e.getY();if(e.getX()<20
6、
7、e.getX()>300
8、
9、e.getY()<20
10、
11、e.getY()>300){return;}
12、if(x1%20>10){x1+=20;}if(y1%20>10){y1+=20;}x1=x1/20*20;y1=y1/20*20;set_Qizi(x1,y1);}publicvoidmouseEntered(MouseEvente){}publicvoidmouseExited(MouseEvente){}publicvoidmouseReleased(MouseEvente){}publicvoidmouseDragged(MouseEvente){}publicvoidmouseMoved(MouseEvente){}publicvoi
13、dpaint(Graphicsg){draw_qipan(g);}publicvoidset_Qizi(intx,inty)//落子{if(intGame_Start==0)//判断游戏未开始{return;}if(intGame_Body[x/20][y/20]!=0){return;}Graphicsg=getGraphics();if(color_Qizi==1)//判断黑子还是白子{g.setColor(Color.black);color_Qizi=0;}else{g.setColor(Color.white);color_Qizi=
14、1;}g.fillOval(x-10,y-10,20,20);intGame_Body[x/20][y/20]=color_Qizi+1;if(Gam