下载
加入VIP
  • 专属下载特权
  • 现金文档折扣购买
  • VIP免费专区
  • 千万文档免费下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 java桌游小游戏代码

java桌游小游戏代码.doc

java桌游小游戏代码

魏子豪
2017-12-12 0人阅读 举报 0 0 暂无简介

简介:本文档为《java桌游小游戏代码doc》,可适用于综合领域

java桌游小游戏代码*在某类桌面游戏中有三种职业战士法师和弓箭手。他们都具有生命这一特征此外还有各自的属性如:战士拥有力量法师拥有智力弓箭手拥有敏捷角色在N×N的棋盘上移动移动可以横向一格或者竖向一格他们之间可以互相战斗当某个角色移到的目的坐标点上已有角色时则触发战斗由于兵种间的相克关系有战士对法师必输法师对弓箭手必输弓箭手对战士必输而当两个角色职业相同时谁的特定属性与生命的乘积大则谁赢。续将上述棋类以用户图形界面的形式表现出来应具备以下功能:棋盘和棋子的可视化表现可移动棋子并进行战斗*更进一步的棋子并不能无限制的移动感兴趣的同学可以在上述基础上发挥想象力规定移动规则设计计算机方的AI等。(*为选作内容)*importjavaawt*importjavaawtevent*importjavaxswing*importjavaxswingevent*classCharacterextendsJButtonimplementsActionListener{publicstaticintpressNum=,sideTurn=,firRow,firCol,secRow,secColpublicstaticStringnames={"jpg","jpg","jpg","jpg","jpg","jpg","jpg"},txt={{"","","",""},{"","战士","法师","弓箭手"},{"","战士","法师","弓箭手"}}publicstaticIconicons={{newImageIcon(names),newImageIcon(names),newImageIcon(names),newImageIcon(names)},{newImageIcon(names),newImageIcon(names),newImageIcon(names),newImageIcon(names)},{newImageIcon(names),newImageIcon(names),newImageIcon(names),newImageIcon(names)}}intside,style,life,powCharacter(){super()}Character(Charactera){super(txtasideastyle,iconsasideastyle)JButton的图案可根据实际改动。side=asidestyle=astylelife=alifepow=apow}publicvoidchangeC(Charactera){side=asidestyle=astylelife=alifepow=apow}publicintgetStyle(){returnstyle}publicintgetLife(){returnlife}publicintgetPow(){returnpow}publicstaticbooleanfight(Charactera,Characterb){if((astyle==bstyle)||(astyle==bstyle))returntrueelseif((astyle==bstyle)(alife*apow>blife*bpow))returntrueelsereturnfalse}publicvoidactionPerformed(ActionEvente){pressNuminti=,j=CharactertempCif(sideTurn==){if(pressNum==){for(i=i<ZhuoYouGameNi)for(j=j<ZhuoYouGameNj)if(egetSource()==ZhuoYouGamechaij){firRow=ifirCol=j}if((ZhuoYouGamechafirRowfirColside)!=)pressNum}else{for(i=i<ZhuoYouGameNi)for(j=j<ZhuoYouGameNj)if(egetSource()==ZhuoYouGamechaij){secRow=isecCol=j}if(((firRow==secRow)(firCol==secCol))||((firRow==secRow)(firCol==secCol))||((firRow==secRow)(firCol==secCol))||((firRow==secRow)(firCol==secCol))){if(ZhuoYouGamechasecRowsecColstyle==){tempC=newCharacter(ZhuoYouGamechafirRowfirCol)ZhuoYouGamechafirRowfirColchangeC(ZhuoYouGamechasecRowsecCol)ZhuoYouGamechasecRowsecColchangeC(tempC)ZhuoYouGamechafirRowfirColsetText(txtZhuoYouGamechafirRowfirColsideZhuoYouGamechafirRowfirColstyle)ZhuoYouGamechafirRowfirColsetIcon(iconsZhuoYouGamechafirRowfirColsideZhuoYouGamechafirRowfirColstyle)ZhuoYouGamechasecRowsecColsetText(txtZhuoYouGamechasecRowsecColsideZhuoYouGamechasecRowsecColstyle)ZhuoYouGamechasecRowsecColsetIcon(iconsZhuoYouGamechasecRowsecColsideZhuoYouGamechasecRowsecColstyle)pressNum=sideTurn=}elseif(ZhuoYouGamechasecRowsecColside==){firRow=secRowfirCol=secColpressNum}else{if(fight(ZhuoYouGamechafirRowfirCol,ZhuoYouGamechasecRowsecCol)){ZhuoYouGamechasecRowsecColchangeC(ZhuoYouGamechafirRowfirCol)ZhuoYouGamechasecRowsecColsetText(txtZhuoYouGamechasecRowsecColsideZhuoYouGamechasecRowsecColstyle)ZhuoYouGamechasecRowsecColsetIcon(iconsZhuoYouGamechasecRowsecColsideZhuoYouGamechasecRowsecColstyle)}ZhuoYouGamechafirRowfirColchangeC(newblank())ZhuoYouGamechafirRowfirColsetText(txtZhuoYouGamechafirRowfirColsideZhuoYouGamechafirRowfirColstyle)ZhuoYouGamechafirRowfirColsetIcon(iconsZhuoYouGamechafirRowfirColsideZhuoYouGamechafirRowfirColstyle)pressNum=sideTurn=}}else{if(ZhuoYouGamechasecRowsecColside==){firRow=secRowfirCol=secColpressNum}elsepressNum=}}}else{if(pressNum==){for(i=i<ZhuoYouGameNi)for(j=j<ZhuoYouGameNj)if(egetSource()==ZhuoYouGamechaij){firRow=ifirCol=j}if(ZhuoYouGamechafirRowfirColside!=)pressNum}else{for(i=i<ZhuoYouGameNi)for(j=j<ZhuoYouGameNj)if(egetSource()==ZhuoYouGamechaij){secRow=isecCol=j}if(((firRow==secRow)(firCol==secCol))||((firRow==secRow)(firCol==secCol))||((firRow==secRow)(firCol==secCol))||((firRow==secRow)(firCol==secCol))){if(ZhuoYouGamechasecRowsecColstyle==){tempC=newCharacter(ZhuoYouGamechafirRowfirCol)ZhuoYouGamechafirRowfirColchangeC(ZhuoYouGamechasecRowsecCol)ZhuoYouGamechasecRowsecColchangeC(tempC)ZhuoYouGamechafirRowfirColsetText(txtZhuoYouGamechafirRowfirColsideZhuoYouGamechafirRowfirColstyle)ZhuoYouGamechafirRowfirColsetIcon(iconsZhuoYouGamechafirRowfirColsideZhuoYouGamechafirRowfirColstyle)ZhuoYouGamechasecRowsecColsetText(txtZhuoYouGamechasecRowsecColsideZhuoYouGamechasecRowsecColstyle)ZhuoYouGamechasecRowsecColsetIcon(iconsZhuoYouGamechasecRowsecColsideZhuoYouGamechasecRowsecColstyle)pressNum=sideTurn=}elseif(ZhuoYouGamechasecRowsecColside==){firRow=secRowfirCol=secColpressNum}else{if(fight(ZhuoYouGamechafirRowfirCol,ZhuoYouGamechasecRowsecCol)){ZhuoYouGamechasecRowsecColchangeC(ZhuoYouGamechafirRowfirCol)ZhuoYouGamechasecRowsecColsetText(txtZhuoYouGamechasecRowsecColsideZhuoYouGamechasecRowsecColstyle)ZhuoYouGamechasecRowsecColsetIcon(iconsZhuoYouGamechasecRowsecColsideZhuoYouGamechasecRowsecColstyle)}ZhuoYouGamechafirRowfirColchangeC(newblank())ZhuoYouGamechafirRowfirColsetText(txtZhuoYouGamechafirRowfirColsideZhuoYouGamechafirRowfirColstyle)ZhuoYouGamechafirRowfirColsetIcon(iconsZhuoYouGamechafirRowfirColsideZhuoYouGamechafirRowfirColstyle)pressNum=sideTurn=}}else{if(ZhuoYouGamechasecRowsecColside==){firRow=secRowfirCol=secColpressNum}elsepressNum=}}}}}classZhanShiextendsCharacter{ZhanShi(){side=style=life=pow=life=(int)(life*Mathrandom())pow=(int)(pow*Mathrandom())}}classFaShiextendsCharacter{FaShi(){side=style=life=pow=life=(int)(life*Mathrandom())pow=(int)(pow*Mathrandom())}}classGongJianShouextendsCharacter{GongJianShou(){side=style=life=pow=life=(int)(life*Mathrandom())pow=(int)(pow*Mathrandom())}}classZhanShiextendsCharacter{ZhanShi(){side=style=life=pow=life=(int)(life*Mathrandom())pow=(int)(pow*Mathrandom())}}classFaShiextendsCharacter{FaShi(){side=style=life=pow=life=(int)(life*Mathrandom())pow=(int)(pow*Mathrandom())}}classGongJianShouextendsCharacter{GongJianShou(){side=style=life=pow=life=(int)(life*Mathrandom())pow=(int)(pow*Mathrandom())}}classblankextendsCharacter{blank(){side=style=life=pow=}}publicclassZhuoYouGameextendsJFrame{publicstaticintN=publicstaticCharacterchaZhuoYouGame(intn){super("桌游小游戏")inti,j,mContainerc=getContentPane()csetLayout(newGridLayout(n,n))cha=newCharacternnfor(i=i<ni)for(j=j<nj){if(ij<n){m=(int)(*Mathrandom())if(m==)chaij=newZhanShi()elseif(m==)chaij=newFaShi()elsechaij=newGongJianShou()}elseif(ij>n){m=(int)(*Mathrandom())if(m==)chaij=newZhanShi()elseif(m==)chaij=newFaShi()elsechaij=newGongJianShou()}elsechaij=newblank()chaij=newCharacter(chaij)chaijaddActionListener(chaij)cadd(chaij)}setSize(,)setVisible(true)}publicstaticvoidmain(Stringargs){ZhuoYouGamegame=newZhuoYouGame(N)}}

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

文档小程序码

使用微信“扫一扫”扫码寻找文档

1

打开微信

2

扫描小程序码

3

发布寻找信息

4

等待寻找结果

我知道了
评分:

/14

java桌游小游戏代码

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利