资源描述:
《java项目实例源代码斗地主》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、总共七个类packagecom;importjava.awt.Point;importjava.awt.event.MouseEvent;importjava.awt.event.MouseListener;importjavax.swing.ImageIcon;importjavax.swing.JLabel;publicclassCardextendsJLabelimplementsMouseListener{Mainmain;//Main类的引用Stringname;//图片url名字booleanup;//是否正反面boolean
2、canClick=false;//是否可被点击booleanclicked=false;//是否点击过publicCard(Mainm,Stringname,booleanup){this.main=m;this.name=name;this.up=up;if(this.up)this.turnFront();else{this.turnRear();}this.setSize(71,96);this.setVisible(true);this.addMouseListener(this);}//正面publicvoidturnFront
3、(){this.setIcon(newImageIcon("images/"+name+".gif"));this.up=true;}//反面publicvoidturnRear(){this.setIcon(newImageIcon("images/rear.gif"));this.up=false;}@OverridepublicvoidmouseClicked(MouseEvente){//TODOAuto-generatedmethodstubif(canClick){Pointfrom=this.getLocation();in
4、tstep;//移动的距离if(clicked)step=-20;else{step=20;}clicked=!clicked;//反向//当被选中的时候,向前移动一步/后退一步Common.move(this,from,newPoint(from.x,from.y-step));}}publicvoidmouseEntered(MouseEventarg0){}publicvoidmouseExited(MouseEventarg0){}publicvoidmousePressed(MouseEventarg0){}publicvoid
5、mouseReleased(MouseEventarg0){}}packagecom;publicenumCardType{c1,//单牌。c2,//对子。c3,//3不带。c4,//炸弹。c31,//3带1。c32,//3带2。c411,//4带2个单,或者一对c422,//4带2对c123,//连子。c1122,//连队。c111222,//飞机。c11122234,//飞机带单排.c1112223344,//飞机带对子.c0//不能出牌}packagecom;importjava.awt.Point;importjava.util.
6、ArrayList;importjava.util.Collections;importjava.util.Comparator;importjava.util.List;importjava.util.concurrent.Delayed;publicclassCommon{//判断牌型publicstaticCardTypejugdeType(Listlist){//因为之前排序过所以比较好判断intlen=list.size();//单牌,对子,3不带,4个一样炸弹if(len<=4){//如果第一个和最后个相同,说明全
7、部相同if(list.size()>0&&Common.getValue(list.get(0))==Common.getValue(list.get(len-1))){switch(len){case1:returnCardType.c1;case2:returnCardType.c2;case3:returnCardType.c3;case4:returnCardType.c4;}}//双王,化为对子返回if(len==2&&Common.getColor(list.get(1))==5)returnCardType.c2;//当第一
8、个和最后个不同时,3带1if(len==4&&((Common.getValue(list.get(0))==Common.getValue(list.get(len-2)))
9、
10、Common