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

上传资料

关闭

关闭

关闭

封号提示

内容

首页 我的JAVA五子棋小游戏代码

我的JAVA五子棋小游戏代码.doc

我的JAVA五子棋小游戏代码

ma启姣
2017-09-01 0人阅读 举报 0 0 暂无简介

简介:本文档为《我的JAVA五子棋小游戏代码doc》,可适用于综合领域

我的JAVA五子棋小游戏代码importjavaawt*importjavaawtevent*importjavaappletAppletimportjavaawtColorpublicclassGoBangextendsAppletimplementsActionListener,MouseListener,MouseMotionListener,ItemListener{intcolor=旗子的颜色标识:白子:黑子booleanisStart=false游戏开始标志intbodyArray=newint设置棋盘棋子状态无子白子黑子Buttonb=newButton("游戏开始")Buttonb=newButton("重置游戏")LabellblWin=newLabel("")CheckboxckbHB=newCheckboxCheckboxGroupckgHB=newCheckboxGroup()publicvoidinit(){setLayout()addMouseListener(this)add(b)bsetBounds(,,,)baddActionListener(this)add(b)bsetBounds(,,,)baddActionListener(this)ckbHB=newCheckbox("白子先",ckgHB,false)ckbHBsetBounds(,,,)ckbHB=newCheckbox("黑子先",ckgHB,false)ckbHBsetBounds(,,,)add(ckbHB)add(ckbHB)ckbHBaddItemListener(this)ckbHBaddItemListener(this)add(lblWin)lblWinsetBounds(,,,)gameInit()thisresize(newDimension(,))}publicvoiditemStateChanged(ItemEvente){if(ckbHBgetState())选择黑子先还是白子先{color=}else{color=}}publicvoidactionPerformed(ActionEvente){if(egetSource()==b){gameStart()}else{reStart()}}publicvoidmousePressed(MouseEvente){}publicvoidmouseClicked(MouseEvente){intx,yx=egetX()y=egetY()if(egetX()<||egetX()>||egetY()<||egetY()>){return}if(x>){x=}if(y>){y=}x=x*y=y*setDown(x,y)}publicvoidmouseEntered(MouseEvente){}publicvoidmouseExited(MouseEvente){}publicvoidmouseReleased(MouseEvente){}publicvoidmouseDragged(MouseEvente){}publicvoidmouseMoved(MouseEvente){}publicvoidpaint(Graphicsg){gsetColor(ColorlightGray)gfillDRect(,,,,true)gsetColor(Colorblack)for(inti=i<i){gdrawLine(,*i,,*i)gdrawLine(*i,,*i,)}}publicvoidsetDown(intx,inty)落子{if(!isStart)判断游戏未开始{return}if(bodyArrayxy!=){return}Graphicsg=getGraphics()if(color==)判断黑子还是白子{gsetColor(Colorblack)color=}else{gsetColor(Colorwhite)color=}gfillOval(x,y,,)bodyArrayxy=colorif(gameWin(x,y))判断输赢{lblWinsetText(startColor(color)"赢了!")isStart=false}if(gameWin(x,y))判断输赢{lblWinsetText(startColor(color)"赢了!")isStart=false}if(gameWin(x,y))判断输赢{lblWinsetText(startColor(color)"赢了!")isStart=false}if(gameWin(x,y))判断输赢{lblWinsetText(startColor(color)"赢了!")isStart=false}}publicStringstartColor(intx){if(x==){return"黑子"}else{return"白子"}}publicvoidgameStart()游戏开始{isStart=trueenableGame(false)bsetEnabled(true)}publicvoidgameInit()游戏开始初始化{isStart=falseenableGame(true)bsetEnabled(false)ckbHBsetState(true)for(inti=i<i){for(intj=j<j){bodyArrayij=}}lblWinsetText("")}publicvoidreStart()游戏重新开始{repaint()gameInit()}publicvoidenableGame(booleane)设置组件状态{bsetEnabled(e)bsetEnabled(e)ckbHBsetEnabled(e)ckbHBsetEnabled(e)}publicbooleangameWin(intx,inty)判断输赢横{intx,y,t=x=xy=yfor(inti=i<i){if(x>){break}if(bodyArrayxiy==bodyArrayxy){t=}else{break}}for(inti=i<i){if(x<){break}if(bodyArrayxiy==bodyArrayxy){t=}else{break}}if(t>){returntrue}else{returnfalse}}publicbooleangameWin(intx,inty)判断输赢竖{intx,y,t=x=xy=yfor(inti=i<i){if(x>){break}if(bodyArrayxyi==bodyArrayxy){t=}else{break}}for(inti=i<i){if(x<){break}if(bodyArrayxyi==bodyArrayxy){t=}else{break}}if(t>){returntrue}else{returnfalse}}publicbooleangameWin(intx,inty)判断输赢左斜{intx,y,t=x=xy=yfor(inti=i<i){if(x>){break}if(bodyArrayxiyi==bodyArrayxy){t=}else{break}}for(inti=i<i){if(x<){break}if(bodyArrayxiyi==bodyArrayxy){t=}else{break}}if(t>){returntrue}else{returnfalse}}publicbooleangameWin(intx,inty)判断输赢左斜{intx,y,t=x=xy=yfor(inti=i<i){if(x>){break}if(bodyArrayxiyi==bodyArrayxy){t=}else{break}}for(inti=i<i){if(x<){break}if(bodyArrayxiyi==bodyArrayxy){t=}else{break}}if(t>){returntrue}else{returnfalse}}}

用户评价(0)

关闭

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

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

提示

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

文档小程序码

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

1

打开微信

2

扫描小程序码

3

发布寻找信息

4

等待寻找结果

我知道了
评分:

/13

我的JAVA五子棋小游戏代码

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利