java蜘蛛纸牌学年论文文档格式.docx
- 文档编号:8633088
- 上传时间:2023-05-12
- 格式:DOCX
- 页数:30
- 大小:21.53KB
java蜘蛛纸牌学年论文文档格式.docx
《java蜘蛛纸牌学年论文文档格式.docx》由会员分享,可在线阅读,更多相关《java蜘蛛纸牌学年论文文档格式.docx(30页珍藏版)》请在冰点文库上搜索。
JRadioButtonMenuItemjRMItemHard=newJRadioButtonMenuItem("
高级:
四花色"
JMenuItemjItemEixt=newJMenuItem("
退出"
JMenuItemjItemValid=newJMenuItem("
显示可行操作"
/**
**构造函数,生成JMenuBar的图形界面
*/
publicSpiderMenuBar(Spiderspider)
{
this.main=spider;
**初始化“游戏”菜单
jNewGame.add(jItemOpen);
jNewGame.add(jItemPlayAgain);
jNewGame.add(jItemValid);
jNewGame.addSeparator();
jNewGame.add(jRMItemEasy);
jNewGame.add(jRMItemNormal);
jNewGame.add(jRMItemHard);
jNewGame.add(jItemExit);
ButtonGroupgroup=newButtonGroup();
group.add(jRMItemEasy);
group.add(jRMItemNormal);
group.add(jRMItemHard);
jHelp.add(jItemAbout);
this.add(jNewGame);
this.add(jHelp);
//为组建添加事件监听并实现
//“开局”
jItemOpen.addActionListener(newjava.awt.event.ActionListener(){
publicvoidactionPerformed(java.awt.event.ActionEvente){
main.newGame();
}
});
//“重新发牌”
jItemPlayAgain.addActionListener(new
java.awt.event.ActionListener(){
if(main.getC()<
60){
main.deal();
}
//"
jItemValid.addActionListener(newjava.awt.event.ActionListener(){
newShow().start();
jItemExit.addActionListener(newjava.awt.event.ActionListener(){
main.dispose();
System.exit(0);
}
简单级别"
默认已选
jRMItemEasy.setSelected(true);
jRMItemEasy.addActionListener(new
main.setGrade(Spider.EASY);
main.initCards();
中级"
jRMItemNormal.addActionListener(new
main.setGrade(Spider.MATURAL);
高级"
jRMItemHard.addActionListener(new
main.setGrade(Spider.HARD);
jNewGame.addMenuListener(newjavax.swing.event.MenuListener(){
publicvoidmenuSelected(javax.swing.event.MenuEvente){
jItemPlayAgain.setEnabled(true);
else{
jItemPlayAgain.setEnabled(false);
publicvoidmenuDeselected(javax.swing.event.MenuEvente){}
publicvoidmenuCanceled(javax.swing.event.MenuEvente){}
jItemAbout.addActionListener(newjava.awt.event.ActionListener(){
newAboutDialog();
**线程:
显示可以执行的操作
classShowextendsThread
publicvoidrun(){
main.showEnableOperator();
}
//第二段
classPKCardextendsJLabelimplementsMouseListener,MouseMotionListener
{//纸牌的位置
Pointpoint=null;
PointinitPoint=null;
intvalue=0;
inttype=0;
Stringname=null;
Containerpane=null;
booleancanMove=false;
booleanisFront=false;
PKCardpreviousCard=null;
publicvoidmouseClicked(MouseEventarg0){}
publicvoidflashCard(PKCardcard){
//启动flash线程
newFlash(card).start();
//不停的获得下一张牌,直到完成
if(main.getNextCard(card)!
=null){
card.flashCard(main.getNextCard(card));
classFlashextendsThread
{
privatePKCardcard=null;
publicFlash(PKCardcard){
this.card=card;
/*
**线程的run()方法
**位纸牌的正面设置白色图片
publicvoidrun(){
booleanis=false;
ImageIconicon=newImageIcon("
images/white.gif"
for(inti=0;
i<
4;
i++){
try{
Thread.sleep(200);
catch(InterruptedExceptione){
e.printStackTrace();
if(is){
this.card.turnFront();
is=!
is;
this.card.setIcon(icon);
//根据当前外观将card的UI属性重置
card.updateUI();
**点击鼠标
publicvoidmousePressed(MouseEventmp){
point=mp.getPoint();
main.setNA();
this.previousCard=main.getPreviousCard(this);
**释放鼠标
publicvoidmouseRelesed(MouseEventmr){
Pointpoint=((JLabel)mr.getSource()).getLocation();
//判断可行列
intn=this.whichColumnAvailable(point);
if(n==-1||n==this.whichColumnAvailable(this.initPoint))
this.setNextCardLocation(null);
main.table.remove(this.getLocation());
this.setLocation(this.initPoint);
main.table.put(this.initPoint,this);
return;
point=main.getLastCardLocation(n);
booleanisEmpty=false;
PKCardcard=null;
if(point==null){
point=main.getGroundLabelLocation(n);
isEmpty=true;
card=(PKCard)main.table.get(point);
if(isEmpty||(this.value+1==card.getCardValue())){
point.y+=40;
if(isEmpty)point.y-=20;
this.setNextCardLocation(point);
point.y-=20;
this.setLocation(point);
main.table.put(point,this);
this.initPoint=point;
if(this.previousCard!
this.previousCard.turnFront();
this.previousCard.setCanMove(true);
this.setCanMove(true);
card=(PKCard)main.table.get(point);
if(card.getCardValue()==1){
point.y-=240;
if(card!
=null&
&
card.isCardCanMove()){
main.haveFinish(n);
/*
**方法:
放置纸牌
*/
publicvoidsetNextCardLocation(Pointpoint){
PKCardcard=main.getNextCard(this);
card.setNextCardLocation(null);
main.table.remove(card.getLocation());
card.setLocation(card.initPoint);
main.table.put(card.initPoint,card);
point=newpoint(point);
point.y+=20;
card.setNextCardLocation(point);
card.setLocation(point);
main.table.put(card.getLocation(),card);
card.initPoint=card.getLocation();
/**
**返回值:
int
判断可用列
publicintwhichCoumnAvailable(Pointpoint){
intx=point.x;
inty=point.y;
inta=(x-20)/101;
intb=(x-20)%101;
if(a!
=9){
if(b>
30&
b<
=71){
a=-1;
elseif(b>
71){
a++;
=-1){
Pointp=main.getLastCardLocation(a);
if(p==null)p=main.getGroundLabelLocation(a);
b=y-p.y;
if(b<
=-96||b>
=96){
returna;
publicvoidmouseEntered(MouseEventarg0){}
publicvoidmouseExited(MouseEventarg0){}
**用鼠标拖动纸牌
publicvoidmouseDragged(MouseEventarg0){
if(canMove){
intx=0;
inty=0;
Pointp=arg0.getPoint();
x=p.x-point.x;
y=p.y-point.y;
this.moving(x,y);
void
移动(x,y)个位置
publicvoidmoving(intx,inty){
Pointp=this.getLocation();
//将组件移动到容器中指定的顺序索引
pane.setComponentZOrder(this,1);
//在Hashtable中保存新的节点信息
main.table.remove(p);
p.x+=x;
p.y+=y;
this.setLocation(p);
main.table.put(p,this);
=null)card.moving(x,y);
}
publicvoidmouseMoved(MouseEventarg0){}
**构造函数
publicPKCard(Stringname,Spiderspider){
super();
this.type=newInteger(name.substring(0,1)).intValue();
this.value=newInteger(name.substring
(2)).intValue();
this.name=name;
this.pane=this.main.getContentPane();
this.addMouseListener(this);
this.addMouseMotionListener(this);
this.setIcon(newImageIcon("
images/rear.gif"
));
this.setSize(71,96);
this.setVisible(true);
令纸牌显示正面
publicvoidturnFront(){
images/"
+name+"
.gif"
this.isFront=true;
令纸牌显示背面
publicvoidturnRear(){
this.isFront=false;
this.canMove=false;
将纸牌移动到点point
publicvoidmoveto(Pointpoint){
判断纸牌是否能移动
publicvoidsetCanMove(booleancan){
this.canMove=can;
PKCardcard=main.getPreviusCard(this);
card.isCardFrot()){
if(!
can){
card.setCanMove(can);
if(this.value+1==card.getCardValue()&
this.type==card.getCardType()){
card.setCanMove(false);
boolean
判断card是否是正面
publicbooleanisCardFront(){
returnthis.isFront;
返回是否能够移动
publicbooleanisCardCanMove(){
returnthis.canMove;
获得card的内容值
publicintgetCanValue(){
returnvalue;
获得card的类型
publicintgetCanType(){
returntype;
//第三段
**"
窗口
classAboutDialogextendsJDialog
JPaneljMainPane=newJTabledPane();
privateJPaneljPanel1=newJPanel();
privateJPaneljPanel2=newJPanel();
privateJTextAreajt1=newJTextArea("
将电脑多次分发给你的牌按照相同的花色由大至小排列起来。
直到桌面上的牌全都消失。
"
privateJTextAreajt2=newJTextArea("
该游戏中,纸牌的图片来自于WindowsXP的纸牌游戏,图片权属于原作者所有!
publicAboutDialog()
setTitle("
蜘蛛牌"
setSize(300,200);
setResizable(false);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
Containerc=this.getConten
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 蜘蛛 纸牌 学年 论文