欢迎来到天天文库
浏览记录
ID:18241430
大小:46.50 KB
页数:12页
时间:2018-09-15
《13格的五子棋代码》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、package作业;importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.Container;importjava.awt.FlowLayout;importjava.awt.Graphics;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.MouseAdapter;importjava.awt.event.MouseEvent;importjavax.swing.JBut
2、ton;importjavax.swing.JFrame;importjavax.swing.JLabel;publicclasswuziqiextendsJFrame{intx=0,y=0;//初始化坐标的两个参数//初始化棋盘九个落棋位置intchequer[][];{chequer=newint[13][13];for(inti=0;i<13;i++)for(intj=0;j<13;j++)chequer[i][j]=0;}intlocation=0;//初始化坐标位置booleanstart=true,redplay=true,success=false;//初始化重
3、新开始,下棋,胜利//初始化棋盘九个落棋位置ints[]=newint[155],jj[]=newint[155];//初始化棋局位置,棋子信息JButtonjbutton1,jbutton2;//定义重新开始红队先下,重新开始蓝队先下两个按钮JLabeljlabel;//定义标签publicwuziqi(){Containerc=getContentPane();//给容器赋值istheTibetanPlateaupoly.Centercityonlyapopulationofoveronemillion.Xiningislocatedinthe"Tangfangudao"
4、andtheancient"SilkRoad"road,istheLoessPlateauandtheTibetanPlateau,agriculturalandpastoralareasand,inconjunctionwiththeMinistryofcultureandIslamicculture11c.setLayout(newFlowLayout());jbutton1=newJButton("重新开始红队先下");c.add(jbutton1);jbutton2=newJButton("重新开始蓝队先下");c.add(jbutton2);jlabel=newJL
5、abel();c.add(jlabel,BorderLayout.SOUTH);//增加鼠标监听器addMouseListener(newMouseAdapter(){publicvoidmousePressed(MouseEventevent){if(event.isAltDown()){repaint();}//获得鼠标点击的坐标x=event.getPoint().x;y=event.getPoint().y;System.out.println("坐标是:"+x+","+y+";");intlocation=location(x,y);//用a保存坐标的信息Syste
6、m.out.println("location="+location);//一方胜利或平局就重新开始if(success){jlabel.setForeground(Color.RED);jlabel.setText(""+"游戏已结束,请重新开始"+"");}//棋局还没结束,继续下棋istheTibetanPlateaupoly.Centercityonlyapopulationofoveronemillion.Xiningislocatedinthe"Tangfangudao"andtheancient"SilkRoad"road,istheLoessPlateauan
7、dtheTibetanPlateau,agriculturalandpastoralareasand,inconjunctionwiththeMinistryofcultureandIslamicculture11else{//如果先前一位置上已有一棋子,在此位置上再有一棋子就提醒另选位置重新下棋if(s[location]==1){jlabel.setForeground(Color.RED);jlabel.setText(""+"此位置有棋子,请另选位置重新下棋"+"");}//如果此位置是第一次有
此文档下载收益归作者所有