java应用技术实训报告

上传人:shaoy****1971 文档编号:108895479 上传时间:2019-10-25 格式:DOC 页数:24 大小:399KB
返回 下载 相关 举报
java应用技术实训报告_第1页
第1页 / 共24页
java应用技术实训报告_第2页
第2页 / 共24页
java应用技术实训报告_第3页
第3页 / 共24页
java应用技术实训报告_第4页
第4页 / 共24页
java应用技术实训报告_第5页
第5页 / 共24页
点击查看更多>>
资源描述

《java应用技术实训报告》由会员分享,可在线阅读,更多相关《java应用技术实训报告(24页珍藏版)》请在金锄头文库上搜索。

1、Java应用技术实训报告题 目 五子棋小游戏 起讫日期 2008 年 6月 23日至 2008 年7月4日所在院系 软件学院 学生姓名 索明宇 专 业 应用化学+软件 班 级 05-1 学 号 20 指导教师 李伯林 职称 讲师 所在单位 软件学院 2008年 7 月 4 日一总体设计本系统共包括6个java源文件1类之间的关系如图1所示。ChessAutoplayScanSortJudgeEvaluate图1主类与其它类之间关系2java源文件及其功能如表1.1所示。表1.1 java源文件及其功能序号文件名主要功能备注1Chess本程序的主函数初始化棋盘2Autoplay实现电脑可以自动下

2、棋分为8种情况3Scan扫描整个棋盘记录连在一起的黑白棋子数为判断胜负服务4Sort实现人与电脑有次序的下棋黑棋白棋有序的下5Judge判断人与电脑的胜负可以在文本框中显示胜负结果6Evaluate电脑估计为电脑下棋提供帮助二、详细设计1Chess主类(1)成员变量见表2.1表2.1 Chess成员变量描述变量类型名称控制棋子颜色inti重新开局ButtonButton请黑棋下子TextFieldtext_1请白棋下子TextFieldtext_2这是第+i+步TextFieldtext_3(2)方法见表2.2表2.2 Chess方法名功能备注ChessPad()初始化棋盘设置棋盘颜色,Voi

3、d paint (Graphics g)对棋子等图像进行初始化设置棋子大小,颜色等public void mousePressed(MouseEvent e)鼠标的实践监听单击实践public void paint(Graphics g)画出图像控制图像的大小范围public void mousePressed(MouseEvent e)处理按下鼠标的事件选中下棋的位置public void mouseReleased(MouseEvent e)处理鼠标离开的事件本步下棋结束public void mouseExited(MouseEvent e)处理鼠标离开棋盘时鼠标离开组件不实现任何事件p

4、ublic void mouseClicked(MouseEvent e)处理发生单击的事件实现下棋以及重新开始游戏(3)源代码见文件Chess.javaimport java.awt.*;import java.awt.event.*;class ChessPad extends Panel implements MouseListener,ActionListener int array=new int1919; Scan scanp=new Scan(); Scan scanc=new Scan(); AutoPlay autoPlay=new AutoPlay(); Evaluate

5、evaluatep=new Evaluate(); Evaluate evaluatec=new Evaluate(); Sort sort=new Sort(); int i=0; int x=-1,y=-1,棋子颜色=1; Button button=new Button(重新开局); TextField text_1=new TextField(请黑棋下子), text_2=new TextField(), text_3=new TextField(); ChessPad() setSize(440,440); setLayout(null);setBackground(Color.pi

6、nk); addMouseListener(this);add(button);button.setBounds(10,5,60,26); button.addActionListener(this); add(text_1); text_1.setBounds(90,5,90,24); add(text_2); text_2.setBounds(290,5,90,24); add(text_3); text_3.setBounds(200,5,80,24); for(int i=0;i19;i+) for(int j=0;j19;j+) arrayij=0; for(int i=0;i19;

7、i+) for(int j=0;j19;j+) for(int h=0;h5;h+) scanp.shapeijh=0; scanc.shapeijh=0; text_1.setEditable(false); text_2.setEditable(false); public void paint(Graphics g) for (int i=40;i=400;i=i+20) g.drawLine(40,i,400,i); for(int j=40;j=400;j=j+20) g.drawLine(j,40,j,400); g.fillOval(97,97,6,6); g.fillOval(

8、337,97,6,6); g.fillOval(97,337,6,6); g.fillOval(337,337,6,6); g.fillOval(217,217,6,6); public void mousePressed(MouseEvent e) int a=0,b=0; if(e.getModifiers()=InputEvent.BUTTON1_MASK) x=(int)e.getX();y=(int)e.getY(); ChessPoint_blackchesspoint_black=new ChessPoint_black(this); ChessPoint_white chess

9、point_white=new ChessPoint_white(this); i+; text_3.setText(这是第+i+步); if(x+5)/202|(y+5)/2019|(y-5)/2019) else a=(x+10)/20;b=(y+10)/20; if(arrayb-2a-2=0&棋子颜色=1) this.add(chesspoint_black); chesspoint_black.setBounds(a*20-9,b*20-9,18,18); 棋子颜色=棋子颜色*(-1); arrayb-2a-2=1; if (Judge.judge(array,1)text_1.se

10、tText(黑棋赢!);棋子颜色=2;removeMouseListener(this); else text_1.setText(); if(i2&棋子颜色=-1) scanp.scan(array,1); scanc.scan(array,-1); sort.sort(scanp.shape); sort.sort(scanc.shape); evaluatep.evaluate(scanp.shape); evaluatec.evaluate(scanc.shape); 棋子颜色=棋子颜色*(-1); this.add(chesspoint_white); if(evaluatep.ma

11、xevaluatec.max) text_2.setText(evaluatep.max_x+ +evaluatep.max_y+ +evaluatep.max); chesspoint_white.setBounds(evaluatep.max_y+2)*20-9,(evaluatep.max_x+2)*20-9,18,18); arrayevaluatep.max_xevaluatep.max_y=-1; text_1.setText(请黑棋下子); for(int i=0;i19;i+) for(int j=0;j19;j+) for(int h=0;h5;h+) scanp.shapeijh=0; scanc.shapeijh=0;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 总结/报告

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号