ImageVerifierCode 换一换
格式:DOC , 页数:62 ,大小:337.54KB ,
资源ID:2864378      下载积分:5 金币
验证码下载
登录下载
邮箱/手机:
验证码: 获取验证码
温馨提示:
支付成功后,系统会自动生成账号(用户名为邮箱或者手机号,密码是验证码),方便下次登录下载和查询订单;
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

开通VIP
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.zixin.com.cn/docdown/2864378.html】到电脑端继续下载(重复下载【60天内】不扣币)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  
声明  |  会员权益     获赠5币     写作写作

1、填表:    下载求助     索取发票    退款申请
2、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
3、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
4、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
5、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前自行私信或留言给上传者【天****】。
6、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
7、本文档遇到问题,请及时私信或留言给本站上传会员【天****】,需本站解决可联系【 微信客服】、【 QQ客服】,若有其他问题请点击或扫码反馈【 服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【 版权申诉】”(推荐),意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:4008-655-100;投诉/维权电话:4009-655-100。

注意事项

本文(JAVA专业课程设计五子棋内附完整代码.doc)为本站上传会员【天****】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4008-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

JAVA专业课程设计五子棋内附完整代码.doc

1、JAVA课程设计设计题目:五子棋游戏一. 简明介绍五子棋1. 五子棋起源五子棋,又被称为“连五子、五子连、串珠、五目、五目碰、五格、五石、五法、五联、京棋”。五子棋相传起源于四千多年前尧帝时期,比围棋历史还要悠久,可能早在“尧造围棋”之前,民间就已经有五子棋游戏。相关早期五子棋文史资料和围棋有相同之处,因为古代五子棋棋具和围棋是完全相同。2.现在五子棋标准棋盘(图所表示)3.五子棋棋子五子棋采取两种颜色棋子,黑色棋子和白色棋子,和围棋相同,4.五子棋规则五子棋就是五个棋子连在一起就算赢,黑棋先行,下棋下在棋盘交叉线上,因为黑棋先行,优势太大,所以对黑棋设了禁手,又要求了“三手交换”,就是黑棋下

2、第 2 手棋,盘面第 3 着棋以后,白方在应白 2 之前,如感觉黑方棋形不利于己方,可出交换,即执白棋一方变为执黑棋一方。和“五手两打法”,就是黑棋在下盘面上关键第 5 手时,必需下两步棋,让白方在这两步棋中任选一步,然后再续下。不过通常爱好者不需要遵照这么多规则。二.程序步骤 三.代码设计和分析main方法创建了ChessFrame类一个实例对象(cf),并开启屏幕显示显示该实例对象。public class FiveChessAppletDemo public static void main(String args) ChessFrame cf = new ChessFrame(); c

3、f.show();用类ChessFrame创建五子棋游戏主窗体和菜单import java.awt.*;import java.awt.event.*;import java.applet.*;import javax.swing.*;import java.io.PrintStream;import javax.swing.JComponent;import javax.swing.JPanel;class ChessFrame extends JFrame implements ActionListener private String strsize=标准棋盘,改善棋盘,扩大棋盘;pri

4、vate String strmode=人机对战,人人对战;public static boolean iscomputer=true,checkcomputer=true;private int width,height;private ChessModel cm;private MainPanel mp;结构五子棋游戏主窗体public ChessFrame() this.setTitle(五子棋游戏); cm=new ChessModel(1); mp=new MainPanel(cm); Container con=this.getContentPane(); con.add(mp,C

5、enter); this.setResizable(false); this.addWindowListener(new ChessWindowEvent(); MapSize(14,14); JMenuBar mbar = new JMenuBar(); this.setJMenuBar(mbar); JMenu gameMenu = new JMenu(游戏); mbar.add(makeMenu(gameMenu, new Object 开局, null,棋盘,null,模式, null, 退出 , this); JMenu lookMenu =new JMenu(外观); mbar.a

6、dd(makeMenu(lookMenu,new Object 类型一,类型二,类型三 ,this); JMenu helpMenu = new JMenu(版本); mbar.add(makeMenu(helpMenu, new Object 相关 , this);结构五子棋游戏主菜单public JMenu makeMenu(Object parent, Object items, Object target) JMenu m = null; if(parent instanceof JMenu) m = (JMenu)parent; else if(parent instanceof S

7、tring) m = new JMenu(String)parent); else return null; for(int i = 0; i items.length; i+) if(itemsi = null) m.addSeparator(); else if(itemsi = 棋盘) JMenu jm = new JMenu(棋盘); ButtonGroup group=new ButtonGroup(); JRadioButtonMenuItem rmenu; for (int j=0;jstrsize.length;j+) rmenu=makeRadioButtonMenuItem

8、(strsizej,target); if (j=0) rmenu.setSelected(true); jm.add(rmenu); group.add(rmenu); m.add(jm); else if(itemsi = 模式) JMenu jm = new JMenu(模式); ButtonGroup group=new ButtonGroup(); JRadioButtonMenuItem rmenu; for (int h=0;hstrmode.length;h+) rmenu=makeRadioButtonMenuItem(strmodeh,target); if(h=0) rm

9、enu.setSelected(true); jm.add(rmenu); group.add(rmenu); m.add(jm); else m.add(makeMenuItem(itemsi, target); return m;结构五子棋游戏菜单项public JMenuItem makeMenuItem(Object item, Object target) JMenuItem r = null; if(item instanceof String) r = new JMenuItem(String)item); else if(item instanceof JMenuItem) r

10、 = (JMenuItem)item; else return null; if(target instanceof ActionListener) r.addActionListener(ActionListener)target); return r;结构五子棋游戏单选按钮式菜单项public JRadioButtonMenuItem makeRadioButtonMenuItem( Object item, Object target) JRadioButtonMenuItem r = null; if(item instanceof String) r = new JRadioButt

11、onMenuItem(String)item); else if(item instanceof JRadioButtonMenuItem) r = (JRadioButtonMenuItem)item; else return null; if(target instanceof ActionListener) r.addActionListener(ActionListener)target); return r; public void MapSize(int w,int h) setSize(w * 24, h * 27); if(this.checkcomputer) this.is

12、computer=true; else this.iscomputer=false; mp.setModel(cm); mp.repaint(); public boolean getiscomputer() return this.iscomputer; public void restart() int modeChess = cm.getModeChess(); if(modeChess = 0) cm = new ChessModel(modeChess); MapSize(cm.getWidth(),cm.getHeight(); public void actionPerforme

13、d(ActionEvent e) String arg=e.getActionCommand(); try if (arg.equals(类型三) UIManager.setLookAndFeel( com.sun.java.swing.plaf.windows.WindowsLookAndFeel); else if(arg.equals(类型二) UIManager.setLookAndFeel( com.sun.java.swing.plaf.motif.MotifLookAndFeel); else UIManager.setLookAndFeel( javax.swing.plaf.

14、metal.MetalLookAndFeel ); SwingUtilities.updateComponentTreeUI(this); catch(Exception ee) if(arg.equals(标准棋盘) this.width=14; this.height=14; cm=new ChessModel(1); MapSize(this.width,this.height); SwingUtilities.updateComponentTreeUI(this); if(arg.equals(改善棋盘) this.width=18; this.height=18; cm=new Ch

15、essModel(2); MapSize(this.width,this.height); SwingUtilities.updateComponentTreeUI(this); if(arg.equals(扩大棋盘) this.width=22; this.height=22; cm=new ChessModel(3); MapSize(this.width,this.height); SwingUtilities.updateComponentTreeUI(this); if(arg.equals(人机对战) this.checkcomputer=true; this.iscomputer

16、=true; cm=new ChessModel(cm.getModeChess(); MapSize(cm.getWidth(),cm.getHeight(); SwingUtilities.updateComponentTreeUI(this); if(arg.equals(人人对战) this.checkcomputer=false; this.iscomputer=false; cm=new ChessModel(cm.getModeChess(); MapSize(cm.getWidth(),cm.getHeight(); SwingUtilities.updateComponent

17、TreeUI(this); if(arg.equals(开局) restart(); if(arg.equals(相关) JOptionPane.showMessageDialog(null, 第一版, 版本,JOptionPane.PLAIN_MESSAGE ); if(arg.equals(退出) System.exit(0);用类ChessModel实现了整个五子棋程序算法关键import java.awt.*;import java.awt.event.*;import java.applet.*;import javax.swing.*;import java.io.PrintStr

18、eam;import javax.swing.JComponent;import javax.swing.JPanel;class ChessModel 要求棋盘宽度、高度、棋盘模式private int width,height,modeChess;要求棋盘方格横向、纵向坐标private int x=0,y=0;棋盘方格横向、纵向坐标所对应棋子颜色,数组arrMapShow只有3个值:1,2,3,-1,其中1代表该棋盘方格上下棋子为黑子,2代表该棋盘方格上下棋子为白子,3代表为该棋盘方格上没有棋子,-1代表该棋盘方格不能够下棋子private int arrMapShow;交换棋手标识,棋

19、盘方格上是否有棋子标识符private boolean isOdd,isExist;public ChessModel() 该结构方法依据不一样棋盘模式(modeChess)来构建对应大小棋盘public ChessModel(int modeChess) this.isOdd=true; if(modeChess = 1) PanelInit(14, 14, modeChess); if(modeChess = 2) PanelInit(18, 18, modeChess); if(modeChess = 3) PanelInit(22, 22, modeChess); 根据棋盘模式构建棋盘

20、大小private void PanelInit(int width, int height, int modeChess) this.width = width; this.height = height; this.modeChess = modeChess; arrMapShow = new intwidth+1height+1; for(int i = 0; i = width; i+) for(int j = 0; j = width+20 | x = height+20 | y 0;计算棋盘上某一方格上八个方向棋子最大值,这八个方向分别是:左、右、上、下、左上、左下、右上、右下pu

21、blic boolean chessExist(int i,int j) if(this.arrMapShowij=1 | this.arrMapShowij=2) return true; return false;判定该坐标位置是否可下棋子public void readyplay(int x,int y) if(badxy(x,y) return; if (chessExist(x,y) return; this.arrMapShowxy=3;在该坐标位置下棋子public void play(int x,int y) if(badxy(x,y) return; if(chessExis

22、t(x,y) this.isExist=true; return; else this.isExist=false; if(getisOdd() setisOdd(false); this.arrMapShowxy=1; else setisOdd(true); this.arrMapShowxy=2; 计算机走棋说明:用穷举法判定每一个坐标点四个方向最大棋子数,最终得出棋子数最大值坐标,下子public void computerDo(int width,int height) int max_black,max_white,max_temp,max=0; setisOdd(true); S

23、ystem.out.println(计算机走棋 .); for(int i = 0; i = width; i+)for(int j = 0; j max) max=max_temp; this.x=i; this.y=j; setX(this.x); setY(this.y); this.arrMapShowthis.xthis.y=2;统计电脑下子后横向坐标public void setX(int x) this.x=x;统计电脑下子后纵向坐标public void setY(int y) this.y=y;获取电脑下子横向坐标public int getX() return this.x

24、;获取电脑下子纵向坐标public int getY() return this.y;计算棋盘上某一方格上八个方向棋子最大值,这八个方向分别是:左、右、上、下、左上、左下、右上、右下public int checkMax(int x, int y,int black_or_white) int num=0,max_num,max_temp=0; int x_temp=x,y_temp=y; int x_temp1=x_temp,y_temp1=y_temp; 判定右边 for(int i=1;ithis.width) break; if(this.arrMapShowx_temp1y_temp

25、1=black_or_white) num+; else break; 判定左边 x_temp1=x_temp; for(int i=1;i5;i+) x_temp1-=1; if(x_temp10) break; if(this.arrMapShowx_temp1y_temp1=black_or_white) num+; else break; if(num5) max_temp=num; 判定上面 x_temp1=x_temp; y_temp1=y_temp; num=0; for(int i=1;i5;i+) y_temp1-=1; if(y_temp10) break; if(this

26、.arrMapShowx_temp1y_temp1=black_or_white) num+; else break; 判定下面 y_temp1=y_temp; for(int i=1;ithis.height) break; if(this.arrMapShowx_temp1y_temp1=black_or_white) num+; else break; if(nummax_temp&num5) max_temp=num; 判定左上方 x_temp1=x_temp; y_temp1=y_temp; num=0; for(int i=1;i5;i+) x_temp1-=1; y_temp1-

27、=1; if(y_temp10 | x_temp10) break; if(this.arrMapShowx_temp1y_temp1=black_or_white) num+; else break; 判定右下方 x_temp1=x_temp; y_temp1=y_temp; for(int i=1;ithis.height | x_temp1this.width) break; if(this.arrMapShowx_temp1y_temp1=black_or_white) num+; else break; if(nummax_temp&num5) max_temp=num; 判定右上方

28、 x_temp1=x_temp; y_temp1=y_temp; num=0; for(int i=1;i5;i+) x_temp1+=1; y_temp1-=1; if(y_temp1this.width) break; if(this.arrMapShowx_temp1y_temp1=black_or_white) num+; else break; 判定左下方 x_temp1=x_temp; y_temp1=y_temp; for(int i=1;ithis.height | x_temp1max_temp&num5) max_temp=num; max_num=max_temp; re

29、turn max_num;判定胜败public boolean judgeSuccess(int x,int y,boolean isodd) int num=1; int arrvalue; int x_temp=x,y_temp=y; if(isodd) arrvalue=2; else arrvalue=1; int x_temp1=x_temp,y_temp1=y_temp; 判定右边胜败 for(int i=1;ithis.width) break; if(this.arrMapShowx_temp1y_temp1=arrvalue) num+; else break; 判定左边胜败

30、 x_temp1=x_temp; for(int i=1;i6;i+) x_temp1-=1; if(x_temp10) break; if(this.arrMapShowx_temp1y_temp1=arrvalue) num+; else break; if(num=5) return true; 判定上方胜败 x_temp1=x_temp; y_temp1=y_temp; num=1; for(int i=1;i6;i+) y_temp1-=1; if(y_temp10) break; if(this.arrMapShowx_temp1y_temp1=arrvalue) num+; el

31、se break; 判定下方胜败 y_temp1=y_temp; for(int i=1;ithis.height) break; if(this.arrMapShowx_temp1y_temp1=arrvalue) num+; else break; if(num=5) return true; 判定左上胜败 x_temp1=x_temp; y_temp1=y_temp; num=1; for(int i=1;i6;i+) x_temp1-=1; y_temp1-=1; if(y_temp10 | x_temp10) break; if(this.arrMapShowx_temp1y_tem

32、p1=arrvalue) num+; else break; 判定右下胜败 x_temp1=x_temp; y_temp1=y_temp; for(int i=1;ithis.height | x_temp1this.width) break; if(this.arrMapShowx_temp1y_temp1=arrvalue) num+; else break; if(num=5) return true; 判定右上胜败 x_temp1=x_temp; y_temp1=y_temp; num=1; for(int i=1;i6;i+) x_temp1+=1; y_temp1-=1; if(y

33、_temp1this.width) break; if(this.arrMapShowx_temp1y_temp1=arrvalue) num+; else break; 判定左下胜败 x_temp1=x_temp; y_temp1=y_temp; for(int i=1;ithis.height | x_temp10) break; if(this.arrMapShowx_temp1y_temp1=arrvalue) num+; else break; if(num=5) return true; return false;赢棋后提醒public void showSuccess(JPane

34、l jp) JOptionPane.showMessageDialog(jp,你赢了,结果, JOptionPane.INFORMATION_MESSAGE);输棋后提醒public void showDefeat(JPanel jp) JOptionPane.showMessageDialog(jp,你输了,结果, JOptionPane.INFORMATION_MESSAGE);用类MainPanel关键完成以下功效:1、构建一个面板,在该面板上画上棋盘;2、处理在该棋盘上鼠标事件(如鼠标左键点击、鼠标右键点击、鼠标拖动等)import java.awt.*;import java.awt

35、.event.*;import java.applet.*;import javax.swing.*;import java.io.PrintStream;import javax.swing.JComponent;import javax.swing.JPanel;class MainPanel extends JPanel implements MouseListener,MouseMotionListener设定棋盘宽度和高度private int width,height; private ChessModel cm;依据棋盘模式设定面板大小MainPanel(ChessModel mm) cm=mm; width=cm.getWidth();

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服