收藏 分销(赏)

五子棋JAVA语言专业课程设计方案报告.doc

上传人:二*** 文档编号:4571675 上传时间:2024-09-30 格式:DOC 页数:30 大小:255.04KB
下载 相关 举报
五子棋JAVA语言专业课程设计方案报告.doc_第1页
第1页 / 共30页
亲,该文档总共30页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

1、Java语言程序设计课程设计汇报学 院: 信息科学技术学院 班 级: 软件技术2班 姓 名: 王更新 学 号: 指导老师: 郭韶升 课设时间: -03-17 至-03-26 二O一四 年 三月 二十六 日目 录一、设计要求.2二、设计步骤.2 2.1程序步骤图.2 2.2程序功效分配.3三、设计正文.6 3.1创建棋盘类.6 3.2判定输赢功效实现.9 3.3测试结果.9四、心得体会.12五、参考文件.12附录 (源代码).13一、课程设计要求设计一个1515围棋棋盘,由两玩家交替进行对战,并能够实现以下功效:1.选择落子前后次序 2.重置棋盘3.刷新重新开始4.退出提醒而且要求退出者判为负,

2、但退出过程中要有提醒。以防不小心点错了。最终判定某一方是否为五子连珠。实现一个简单多用户五子棋游戏程序,包含以下两个界面(1)选择对弈桌(执黑、执白)。(2)在游戏界面,有开始,退出(游戏未结束、点退出自动判负);二、设计步骤2.1程序步骤图2.2 程序功效分配a. 棋盘绘制public void draw_qipan(Graphics G) /画棋盘 15*15G.setColor(Color.lightGray);G.fill3DRect(10,10,300,300,true);G.setColor(Color.black);for(int i=1;i16;i+)G.drawLine(20

3、,20*i,300,20*i);G.drawLine(20*i,20,20*i,300); b. 添加按钮Button b1=new Button(开始);Button b2=new Button(重置游戏);Label lblWin=new Label( );Checkbox ckbHB=new Checkbox3;Button exist = new Button(退出); public void init()ckbHB0=new Checkbox(执白,ckgHB,false);ckbHB1=new Checkbox(执黑,ckgHB,false);ckbHB2=new Checkbox

4、(观看,ckgHB, false);c. 鼠标棋子触发事件public void mouseClicked(MouseEvent e) Graphics g=getGraphics();int x1,y1;x1=e.getX();y1=e.getY();if (e.getX()300 | e.getY()300) return;if (x1%2010) x1+=10;if(y1%2010) y1+=10;x1=x1/20*20;y1=y1/20*20;set_Qizi(x1,y1);m*=(-1); d. 按钮触发事件 public void actionPerformed(ActionEve

5、nt e) Graphics g=getGraphics();if (e.getSource()=b1) Game_start();elseGame_re();if(e.getSource()=exist)Game_re();lblWin.setText(Get_qizi_color(color_Qizi)+输了!);intGame_Start=0; e. 判定落子位置及画出对应黑白棋子public void set_Qizi(int x,int y) /落子if (intGame_Start=0) /判定游戏未开始return;if (intGame_Bodyx/20y/20!=0) ret

6、urn;Graphics g=getGraphics();if (color_Qizi=1)/判定黑子还是白子g.setColor(Color.black);color_Qizi=0;elseg.setColor(Color.white);color_Qizi=1;g.fillOval(x-10,y-10,20,20);intGame_Bodyx/20y/20=color_Qizi+1;f. 判定胜败if (Game_win_1(x/20,y/20) /判定输赢1lblWin.setText(Get_qizi_color(color_Qizi)+赢了!);intGame_Start=0;if

7、(Game_win_2(x/20,y/20) /判定输赢2lblWin.setText(Get_qizi_color(color_Qizi)+赢了!);intGame_Start=0;if (Game_win_3(x/20,y/20) /判定输赢3lblWin.setText(Get_qizi_color(color_Qizi)+赢了!);intGame_Start=0;if (Game_win_4(x/20,y/20) /判定输赢4lblWin.setText(Get_qizi_color(color_Qizi)+赢了!);intGame_Start=0; 三、设计正文3.1创建棋盘类Pub

8、lic class WcyChess extends Applet implements ActionListener,MouseListener,MouseMotionListener,ItemListenerint color_Qizi=0;/旗子颜色标识 0:白子 1:黑子int intGame_Start=0;/游戏开始标志 0未开始 1游戏中int intGame_Body=new int1616; /设置棋盘棋子状态int m=-1;Button b1=new Button(开始);Button b2=new Button(重置游戏);Label lblWin=new Label(

9、 );Checkbox ckbHB=new Checkbox3;Button exist = new Button(退出); CheckboxGroup ckgHB=new CheckboxGroup();NetchatClient chat=new NetchatClient();public void init()setLayout(null);addMouseListener(this);add(b1);b1.setBounds(330,50,80,30);b1.addActionListener(this);add(b2);b2.setBounds(330,90,80,30);b2.a

10、ddActionListener(this);ckbHB0=new Checkbox(执白,ckgHB,false);ckbHB0.setBounds(320,20,60,30);ckbHB1=new Checkbox(执黑,ckgHB,false);ckbHB1.setBounds(380,20,60,30);ckbHB2=new Checkbox(观看,ckgHB, false);add(ckbHB0);add(ckbHB1);add(ckbHB2);ckbHB0.addItemListener(this);ckbHB1.addItemListener(this);add(lblWin);

11、lblWin.setBounds(330,180,80,30);lblWin.setBackground(Color.red);lblWin.setText(胜利者!);/没有显示?ckbHB2.setBounds(440, 20,60, 30);add(exist);exist.setBounds(330,130,80,30);exist.addActionListener(this);/add(chat);chat.setBounds(20, 500, 300, 300);chat.frame();chat.setVisible(true);Game_start_csh();setSize

12、(500,600); setVisible(true);public void itemStateChanged(ItemEvent e) if (ckbHB0.getState() /选择黑子还是白子color_Qizi=0;elsecolor_Qizi=1;public void mousePressed(MouseEvent e)public void mouseClicked(MouseEvent e) Graphics g=getGraphics();int x1,y1;x1=e.getX();y1=e.getY();if (e.getX()300 | e.getY()300) re

13、turn;if (x1%2010) x1+=10;if(y1%2010) y1+=10;x1=x1/20*20;y1=y1/20*20;set_Qizi(x1,y1);m*=(-1);public void actionPerformed(ActionEvent e) Graphics g=getGraphics();if (e.getSource()=b1) Game_start();elseGame_re();if(e.getSource()=exist)Game_re();lblWin.setText(Get_qizi_color(color_Qizi)+输了!);intGame_Sta

14、rt=0;public void mouseEntered(MouseEvent e)public void mouseExited(MouseEvent e)public void mouseReleased(MouseEvent e)public void mouseDragged(MouseEvent e)public void mouseMoved(MouseEvent e)public void paint(Graphics g) draw_qipan(g);3.2判定输赢功效实现if (Game_win_1(x/20,y/20) /判定输赢1lblWin.setText(Get_q

15、izi_color(color_Qizi)+赢了!);intGame_Start=0;if (Game_win_2(x/20,y/20) /判定输赢2lblWin.setText(Get_qizi_color(color_Qizi)+赢了!);intGame_Start=0;if (Game_win_3(x/20,y/20) /判定输赢3lblWin.setText(Get_qizi_color(color_Qizi)+赢了!);intGame_Start=0;if (Game_win_4(x/20,y/20) /判定输赢4lblWin.setText(Get_qizi_color(color

16、_Qizi)+赢了!);intGame_Start=0;3.3 测试结果a. 进入游戏界面游戏开始界面有三个选择项,用户能够选择对应角色,选择完成后点击开始进入游戏。b. 选择角色,开始下棋首先达成五个棋子连在一块赢了,并在红色区域显示谁赢了!c. 下完后,重新开始下完一盘后游戏停止,点击重新开始,界面回到初始界面,选择角色继续游戏.d.游戏中点退出,自动判输在下棋过程当中谁中途退出,即点击退出,系统自动判定谁输四、课程设计心得体会经过此次课程设计,将我本学期所学JAVA知识得到巩固和应用,在设计过程中我碰到了很到问题,不过在老师和同学们帮助和自己思索下还是很好完成了。这此课程设计还让我知道了

17、写程序不能闭门造车,要努力拓宽知识面,开阔视野,拓展思维。它还让我学会了在网上查阅那些无限资料。因为自己分析设计和程序经验不足,该系统设计和实现过程中,还有很多没有完善地方,比如用户界面设计不够美观,异常犯错处理比较差等多方面问题,这些全部有待深入完善和提升。对于文中出现不足和系统中出现问题敬请老师指导。五、参考文件1. 吴其庆编著.Java程序设计实例教程.北京:冶金工业出版社2. 柳西玲.许斌编著.Java语言应用开发基础.北京:清华大学出版社 3丁振凡 Java 语言实用教程 :北京邮电大学出版社附录 (源代码)import .*;import java.io.*;import java

18、.applet.*;import java.awt.*;import java.awt.event.*;import java.applet.Applet;import java.awt.Color;Public class wuziqi extends Applet implements ActionListener,MouseListener,MouseMotionListener,ItemListener int color_Qizi=0;/旗子颜色标识 0:白子 1:黑子 int intGame_Start=0;/游戏开始标志 0未开始 1游戏中 int intGame_Body=ne

19、w int1616; /设置棋盘棋子状态 int m=-1; Button b1=new Button(开始); Button b2=new Button(重新开始); Label lblWin=new Label( );Checkbox ckbHB=new Checkbox3;Button exist = new Button(退出); CheckboxGroup ckgHB=new CheckboxGroup();public void init()setLayout(null);addMouseListener(this);add(b1);b1.setBounds(330,50,80,3

20、0);b1.addActionListener(this);add(b2);b2.setBounds(330,90,80,30);b2.addActionListener(this);ckbHB0=new Checkbox(执白,ckgHB,false);ckbHB0.setBounds(320,20,60,30);ckbHB1=new Checkbox(执黑,ckgHB,false);ckbHB1.setBounds(380,20,60,30);ckbHB2=new Checkbox(观看,ckgHB, false);add(ckbHB0);add(ckbHB1);add(ckbHB2);c

21、kbHB0.addItemListener(this);ckbHB1.addItemListener(this);add(lblWin);lblWin.setBounds(330,180,80,30);lblWin.setBackground(Color.red);lblWin.setText(胜利者!);/没有显示?ckbHB2.setBounds(440, 20,60, 30);add(exist);exist.setBounds(330,130,80,30);exist.addActionListener(this);Game_start_csh();setSize(500,600);

22、setVisible(true);public void itemStateChanged(ItemEvent e)if (ckbHB0.getState() /选择黑子还是白子color_Qizi=0;elsecolor_Qizi=1;public void mousePressed(MouseEvent e)public void mouseClicked(MouseEvent e)Graphics g=getGraphics();int x1,y1;x1=e.getX();y1=e.getY();if (e.getX()300 | e.getY()300)return;if (x1%20

23、10)x1+=10;if(y1%2010)y1+=10;x1=x1/20*20;y1=y1/20*20;set_Qizi(x1,y1);m*=(-1)public void actionPerformed(ActionEvent e)Graphics g=getGraphics();if (e.getSource()=b1)Game_start();elseGame_re();if(e.getSource()=exist)Game_re();/color_Qizi=m;lblWin.setText(Get_qizi_color(color_Qizi)+输了!);intGame_Start=0;

24、public void mouseEntered(MouseEvent e)public void mouseExited(MouseEvent e)public void mouseReleased(MouseEvent e)public void mouseDragged(MouseEvent e)public void mouseMoved(MouseEvent e)public void paint(Graphics g)draw_qipan(g);public void set_Qizi(int x,int y) /落子if (intGame_Start=0) /判定游戏未开始ret

25、urn;if (intGame_Bodyx/20y/20!=0)return;Graphics g=getGraphics();if (color_Qizi=1)/判定黑子还是白子g.setColor(Color.black);color_Qizi=0;elseg.setColor(Color.white);color_Qizi=1;g.fillOval(x-10,y-10,20,20);intGame_Bodyx/20y/20=color_Qizi+1;if (Game_win_1(x/20,y/20) /判定输赢1lblWin.setText(Get_qizi_color(color_Qi

26、zi)+赢了!);intGame_Start=0;if (Game_win_2(x/20,y/20) /判定输赢2lblWin.setText(Get_qizi_color(color_Qizi)+赢了!);intGame_Start=0;if (Game_win_3(x/20,y/20) /判定输赢3lblWin.setText(Get_qizi_color(color_Qizi)+赢了!);intGame_Start=0;if (Game_win_4(x/20,y/20) /判定输赢4lblWin.setText(Get_qizi_color(color_Qizi)+赢了!);intGam

27、e_Start=0;public String Get_qizi_color(int x)if (x=0)return 黑子;elsereturn 白子;public void draw_qipan(Graphics G) /画棋盘 15*15G.setColor(Color.lightGray);G.fill3DRect(10,10,300,300,true);G.setColor(Color.black);for(int i=1;i16;i+)G.drawLine(20,20*i,300,20*i);G.drawLine(20*i,20,20*i,300);public void Game

28、_start() /游戏开始intGame_Start=1;Game_btn_enable(false);b2.setEnabled(true);public void Game_start_csh() /游戏开始初始化intGame_Start=0;Game_btn_enable(true);b2.setEnabled(false);ckbHB0.setState(true);for (int i=0;i16 ;i+ )for (int j=0;j16 ;j+ )intGame_Bodyij=0;lblWin.setText();public void Game_re() /重新开始游戏re

29、paint();Game_start_csh();public void Game_btn_enable(boolean e) /设置组件状态b1.setEnabled(e);b2.setEnabled(e);ckbHB0.setEnabled(e);ckbHB1.setEnabled(e);public boolean Game_win_1(int x,int y) /横向判定输赢int x1,y1,t=1;x1=x;y1=y;for (int i=1;i15)break;if (intGame_Bodyx1+iy1=intGame_Bodyxy)t+=1;elsebreak;for (in

30、t i=1;i5 ;i+ )if (x14)return true;elsereturn false;public boolean Game_win_2(int x,int y) /纵向判定输赢int x1,y1,t=1;x1=x;y1=y;for (int i=1;i15)break;if (intGame_Bodyx1y1+i=intGame_Bodyxy)t+=1;elsebreak;for (int i=1;i5 ;i+ )if (x14)return true;elsereturn false;public boolean Game_win_3(int x,int y) /左斜判定输

31、赢 int x1,y1,t=1;x1=x;y1=y;for (int i=1;i15)break;if (intGame_Bodyx1+iy1-i=intGame_Bodyxy)t+=1;elsebreak;for (int i=1;i5 ;i+ )if (x14)return true;elsereturn false;public boolean Game_win_4(int x,int y) /左斜判定输赢 int x1,y1,t=1;x1=x;y1=y;for (int i=1;i15)break;if (intGame_Bodyx1+iy1+i=intGame_Bodyxy)t+=1;elsebreak;for (int i=1;i5 ;i+ )if (x14)return true;elsereturn false;

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 学术论文 > 其他

移动网页_全站_页脚广告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 

客服