




已阅读5页,还剩20页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
课程设计说明书 no.1扑克游戏1.课程设计的目的java语言是当今流行的网络编程语言,它具有面向对象、跨平台、分布应用等特点。面向对象的开发方法是当今世界最流行的开发方法,它不仅具有更贴近自然的语义,而且有利于软件的维护和继承。为了进一步巩固课堂上所学到的知识,深刻把握java语言的重要概念及其面向对象的特性,使我们能够熟练的应用面向对象的思想和设计方法解决实际问题的能力。通过此次课程设计,巩固所学java语言基本知识,增进java语言编辑基本功,掌握jdk、editplus、eclipse、jcreator等开发工具的运用,拓宽常用类库的应用。使学生通过该教学环节与手段,把所学课程及相关知识加以融会贯通,全面掌握java语言的编程思想及面向对象程序设计的方法,为今后从事实际工作打下坚实的基础。本设计使用java语言开发扑克游戏程序,将电脑多次分发给你的牌按照相同的花色由大至小排列起来。2.设计方案论证2.1设计思路 用java语言,编程实现纸牌游戏,拥有如下规则,将电脑多次分发给你的牌按照相同的花色由大至小排列起来。游戏分为三个难度,简单,普通,困难。简单为单一花色。困难所分发给的牌有四种花色。将大小相邻的纸牌依次排列到一起当每种花色的全部纸牌都按顺序排列到一起,则游戏结束。2.2设计方法将程序设计成为4个类,aboutdialog类用于实现全部的对话。pkcard类用于实现游戏的规则。spidermenubar类用于实现各个模块的功能。spider为主界面。在spidermenubar建立主界面菜单,通过构造函数public spidermenubar构造函数,生成jmenubar的图形界面,对菜单中各按钮进行事件监听。在该方法中调用spider的构造方法,在其中生成spidermenubar对象,并放置在框架之上,同时设置框架标题 沈 阳 大 学课程设计说明书 no.2框架大小背景颜色,布局为空。public spider()settitle(陶时扑克); setdefaultcloseoperation(javax.swing.jframe.exit_on_close);setsize(1024, 742);setjmenubar(new spidermenubar(this); pane = this.getcontentpane(); pane.setbackground(new color(14, 25, 26); pane.setlayout(null); clicklabel = new jlabel(); clicklabel.setbounds(883, 606, 121, 96); pane.add(clicklabel);在spider类中有如下方法:newgame新游戏的方法,setgrade设置等级方法,初始化等级方法。setgrade,randomcards随即函数。pkcard getpreviouscard获得card上面的那张牌的方法等。由pkcard getpreviouscard,pkcard getnextcard,getlastcardlocation方法对类pkcard调用,代码如下:public pkcard getpreviouscard(pkcard card) point point = new point(card.getlocation(); point.y -= 5; card = (pkcard) table.get(point); if (card != null)return card; point.y -= 15; card = (pkcard) table.get(point); 沈 阳 大 学课程设计说明书 no.3 return card;public pkcard getnextcard(pkcard card) point point = new point(card.getlocation(); point.y += 5;card = (pkcard) table.get(point); if (card != null)return card; point.y += 15; card = (pkcard) table.get(point); return card;public point getlastcardlocation(int column) point point = new point(20 + column * 101, 25); pkcard card = (pkcard) this.table.get(point); if (card = null) return null; while (card != null) point = card.getlocation(); card = this.getnextcard(card); return point;public point getgroundlabellocation(int column) return new point(groundlabelcolumn.getlocation();public void setgroundlabelzorder() for (int i = 0; i 10; i+) 沈 阳 大 学课程设计说明书 no.4pane.setcomponentzorder(groundlabeli, 105 + i); 23功能模块图图1 功能模块图 沈 阳 大 学课程设计说明书 no.52.4程序流程图图2 程序流程图3.设计结果与分析(1)首先是对游戏中主菜单的设计,设计的菜单包括两个大部分,选项和帮助,如图3所示: 沈 阳 大 学课程设计说明书 no.6图3 显示菜单通过如下代码实现:jmenu jnewgame = new jmenu(选项); jmenu jhelp = new jmenu(帮助);(2)在选项菜单下面包含7级子菜单,如图4所示:图4 显示菜单 沈 阳 大 学课程设计说明书 no.7通过如下代码实现:jmenuitem jitemopen = new jmenuitem(开局);jmenuitem jitemplayagain = new jmenuitem(重发牌);jradiobuttonmenuitem jrmitemeasy = new jradiobuttonmenuitem(简单);jradiobuttonmenuitem jrmitemnormal = new jradiobuttonmenuitem(较难);jradiobuttonmenuitem jrmitemhard = new jradiobuttonmenuitem(困难);jmenuitem jitemexit = new jmenuitem(退出);jmenuitem jitemvalid = new jmenuitem(显示可执行行操作);(3)帮助下面包含2级子菜单,分别为游戏规则和声明,如图5所示:图5 显示帮助通过如下代码实现:jtabbedpane jtabbedpane = new jtabbedpane();private jpanel jpanel1 = new jpanel();private jpanel jpanel2 = new jpanel();(4)主窗体通过类spider实现。将窗体名称设置为“陶时扑克”,框架的大小设置为1024*742,背景颜色设置为黑色,布局管理设置为空,通过如下代码实现:public spider()settitle(陶时扑克); 沈 阳 大 学课程设计说明书 no.8setdefaultcloseoperation(javax.swing.jframe.exit_on_close);setsize(1024, 742);setjmenubar(new spidermenubar(this); pane = this.getcontentpane();pane.setbackground(new color(14, 25, 26);pane.setlayout(null);(5)进入游戏之后,首先选择开始新游戏,通过类spider调用它的方法newgame方法,采用随机函数随机初始化牌的顺序(这样做的目的是,使游戏性增加可玩性,使每次出现牌的顺序不同),如图6所示。图6 进入新游戏界面用如下代码实现:public void newgame() this.randomcards(); this.setcardslocation();this.setgroundlabelzorder(); 沈 阳 大 学课程设计说明书 no.9this.deal(); public int getc() return c; public void setgrade(int grade) this.grade = grade; public void initcards() if (cards0 != null) for (int i = 0; i 104; i+) pane.remove(cardsi); int n = 0;if (this.grade = spider.easy) n = 1; else if (this.grade = spider.natural) n = 2; else n = 4; for (int i = 1; i = 8; i+)for (int j = 1; j = 13; j+) cards(i - 1) * 13 + j - 1 = new pkcard(i % n + 1) + - + j, this); 沈 阳 大 学课程设计说明书 no.10 this.randomcards(); public void randomcards() pkcard temp = null; for (int i = 0; i 52; i+) int a = (int) (math.random() * 104); int b = (int) (math.random() * 104); temp = cardsa; cardsa = cardsb; cardsb = temp; (6)在游戏界面的右下角做一张图片,显示扑克牌的背面,同时点击图片,系统自动发牌(当游戏无法继续的时候,可以点击该图片,在每副纸牌上发一张牌,使得进入僵局的纸牌游戏得以继续进行),运行界面如图7,图8所示。 沈 阳 大 学课程设计说明书 no.11图7 发牌功能界面图8 显示发牌 沈 阳 大 学课程设计说明书 no.12用如下代码实现:首先在界面上添加纸牌背面的图片:public void turnrear() this.seticon(new imageicon(images/6.gif); this.isfront = false; this.canmove = false;public pkcard getpreviouscard(pkcard card) point point = new point(card.getlocation(); point.y -= 5; card = (pkcard) table.get(point); if (card != null)return card; point.y -= 15; card = (pkcard) table.get(point);return card; public pkcard getnextcard(pkcard card) point point = new point(card.getlocation(); point.y += 5; card = (pkcard) table.get(point); if (card != null)return card; point.y += 15; card = (pkcard) table.get(point); return card; 沈 阳 大 学课程设计说明书 no.13public point getlastcardlocation(int column) point point = new point(20 + column * 101, 25); pkcard card = (pkcard) this.table.get(point); if (card = null) return null; while (card != null) point = card.getlocation(); card = this.getnextcard(card); return point; public point getgroundlabellocation(int column) return new point(groundlabelcolumn.getlocation(); public void setgroundlabelzorder() for (int i = 0; i 10; i+)pane.setcomponentzorder(groundlabeli, 105 + i); (7)在游戏中每次开始游戏都由程序随机发牌,发牌的过程是,先设置纸牌的初始位置由随机函数产生,并随机生成牌号,设置纸牌的位置,初始化待展开的纸牌,将纸牌放置到固定位置(这里调用pkcard类中的setnextcardlocation方法调用图片文件夹里的纸牌图片),如图9,图10所示。 沈 阳 大 学课程设计说明书 no.14图9 图片库图10 图片被载入 沈 阳 大 学课程设计说明书 no.15使用如下代码实现:for (int i = 0; i 6; i+) for (int j = 0; j 5; i-) for (int j = 0; j = 104) continue;pane.add(cardsn); cardsn.turnrear(); cardsn.moveto(new point(x, y); table.put(new point(x, y), cardsn); x += 101; x = 20; y -= 5; 沈 阳 大 学课程设计说明书 no.16public void showenableoperator() int x = 0; out: while (true) point point = null; pkcard card = null; do if (point != null)n+; point = this.getlastcardlocation(n); while (point = null) point = this.getlastcardlocation(+n); if (n = 10) n = 0; x+; if (x = 10) break out; card = (pkcard) this.table.get(point); while (!card.iscardcanmove(); while (this.getpreviouscard(card)!= null& this.getpreviouscard(card).iscardcanmove()card = this.getpreviouscard(card); if (a = 10)a = 0;for (; a 10; a+) if (a != n) 沈 阳 大 学课程设计说明书 no.17point p = null; pkcard c = null; do if (p != null)a+;p = this.getlastcardlocation(a); int z = 0; while (p = null) p = this.getlastcardlocation(+a); if (a = 10) a = 0; if (a = n) a+; z+; if (z = 10) break out; c = (pkcard) this.table.get(p); while (!c.iscardcanmove(); if (c.getcardvalue() = card.getcardvalue() + 1) card.flashcard(card); try thread.sleep(800); catch (interruptedexception e)e.printstacktrace(); c.flashcard(c); 沈 阳 大 学课程设计说明书 no.18a+; if (a = 10)n+; break out; n+; if (n = 10)n = 0; x+; if (x = 10)break out; 通过调用如下代码实现图片的调用:public void setnextcardlocation(point point)pkcard card = main.getnextcard(this);if (card != null)if (point = null)card.setnextcardlocation(null);main.table.remove(card.getlocation();card.setlocation(card.initpoint);main.table.put(card.initpoint, card); 沈 阳 大 学课程设计说明书 no.19elsepoint = new point(point);point.y += 20;card.setnextcardlocation(point);point.y -= 20;main.table.remove(card.getlocation();card.setlocation(point);main.table.put(card.getlocation(), card);card.initpoint = card.getlocation();(8)进入游戏之后能对游戏的难度进行选择,难度分为三种,分别为简单,较难,困难,简单为单一花色的纸牌进行游戏,而较难和困难的纸牌花色相应的增多。在设计时首先在spidermenubar类中,将三种难度的菜单实现,然后通过调用pkcard的方法实现各难度的功能,如图11,12所示。 沈 阳 大 学课程设计说明书 no.20图11 难度选择图12 选择困难 沈 阳 大 学课程设计说明书 no.21通过如下代码实现:实现菜单分成三种难度:jradiobuttonmenuitem jrmitemeasy = new jradiobuttonmenuitem(简单); jradiobuttonmenuitem jrmitemnormal = new jradiobuttonmenuitem(较难);jradiobuttonmenuitem jrmitemhard = new jradiobuttonmenuitem(困难);jrmitemeasy.addactionlistener(new java.awt.event.actionlistener() public void actionperformed(java.awt.event.actionevent e) main.setgrade(spider.easy); main.initcards(); main.newgame(); 分别对菜单进行事件监听,若选中相应的难度登记则触发spider类中的方法进行实现:jrmitemnormal.addactionlistener(new java.awt.event.actionlistener() public void actionperformed(java.awt.event.actionevent e) main.setgrade(spider.natural); main.initcards(); main.newgame(); jrmitemhard.addactionlistener(new java.awt.event.actionlistener() public void actionperformed(java.awt.event.actionevent e) main.setgrade(spider.hard);main.initcards(); main.newgame(); 沈 阳 大 学课程设计说明书 no.22jnewgame.addmenulistener(new javax.swing.event.menulistener() public void menuselected(javax.swing.event.menuevent e) if(main.getc() 60) jitemplayagain.setenabled(true); else jitemplayagain.setenabled(false); public void menudeselected(javax.swing.event.menuevent e) public void menucanceled(javax.swing.event.menuevent e) (9)退出游戏,点击退出即可退出游戏,在spidermenubar类中actionperformed方法实现,如图13所示。图13 退出游戏 沈 阳 大 学课程设计说明书 no.23使用如下代码实现:jitemexit.addactionlistener(new java.awt.event.actionlistener() public void actionperformed(java.awt.event.actionevent e) main.dispose(); system.exit(0); 4.设计体会通过本次课程设计,我学会了很多东西,在课堂上学习的知识是理论的,平时没有多少机会去实践,平时觉得自己java学得还不错但真到想用它实现点什么的时候却又觉得好多地方不知道如何下手。我的这个程序设计是以蜘蛛纸牌游戏作为基础,对其中很多地方进行了修改,原来游戏只由2个难度,我在原来的基础上对游戏进行修改增加了一个难度,也增加了游戏的可玩性,还有游戏中好多图片过于死板,我利用photoshop等工具对图片进行修改,在
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 网络货运员国庆节后复工安全考核试卷含答案
- 灌排泵站运行工国庆节后复工安全考核试卷含答案
- 四年级语文修辞方法专项训练题集
- 锂冶炼工中秋节后复工安全考核试卷含答案
- 饮料调配工国庆节后复工安全考核试卷含答案
- 初中生物实验教学反思与改进建议
- 高考语文复习资料汇编与答题技巧
- 职业技能等级测试题库
- 办公室文秘工作职责与操作指南
- 饼干制作工节假日前安全考核试卷含答案
- 脑干神经解剖定位
- 土木工程生产实习日记50篇
- GB/T 5993-2003电子设备用固定电容器第4部分:分规范固体和非固体电解质铝电容器
- FZ/T 52059-2021抗菌粘胶短纤维
- 医学课件-护理评估课件
- 儿童营养性疾病的预防
- 幼儿园大班安全教育:《暴力玩具不能玩》 课件
- 26个英文字母大小写描红
- 养老院预算及成本管理制度
- 研学旅行基地评估认定评分表
- DL∕T 1867-2018 电力需求响应信息交换规范
评论
0/150
提交评论