基于java开发的蜘蛛纸牌程序设计
- 格式:doc
- 大小:803.02 KB
- 文档页数:28
蜘蛛纸牌概要设计说明书南昌航空大学软件学院2011年10月1.引言1.1编写目的1.1编写目的本详细设计说明书是针对蜘蛛纸牌游戏的课程作业而编写。
目的是对该软件进行详细设计,在概要设计的基础上进一步明确系统结构,详细地介绍系统的各个模块,为进行后面的实现和测试作准备。
本详细设计说明书的预期读者为本项目小组的成员以及对该系统感兴趣,在以后想对系统进行扩展和维护的人员。
1.2背景a.待开发的系统的名称:蜘蛛纸牌游戏软件b.本项目的任务提出者: 周璇、罗书惟、罗剑、王天宇开发者:周璇、罗书惟、罗剑、王天宇用户:所有对该软件感兴趣,并且对该游戏熟悉的用户]1.3定义AboutDialog:游戏关于类;Frame1:游戏界面设计;PKCard:扑克牌的排列算法;Spider:游戏规则;SpiderMenuBar:游戏菜单栏1.4参考资料《Java实用教程》清华大学出版社张跃平耿祥义著《Java实用教程》2. 系统的结构3.模块1(Frame1)设计说明3.1模块描述实现用户界面的类,含有1个类3种方法,是本系统中最简单的代码3.2功能实现用户友好界面。
3.3性能负责接受用户输入,显示系统输出,其他模块功能的协调调用。
3.4输入项选择游戏的难度系数(简单、中等、高等)、显示可行性操作、统计战况、发牌、保存游戏等。
3.5输出项得出游戏的结果界面。
3.6接口import javax.swing.JMenuBar;import javax.swing.JMenu;import javax.swing.JMenuItem;import javax.swing.JRadioButtonMenuItem;import javax.swing.ButtonGroup。
3.7注释设计ImageIcon icon = new ImageIcon("images/测试.gif"); //gif,jpg 格式能用,bmp格式不能用3.8 限制条件扑克牌的图画格式只能是gif,jpg。
基于j a v a开发的蜘蛛纸牌程序设计集团文件版本号:(M928-T898-M248-WU2669-I2896-DQ586-M1988)编号:本科毕业论文(设计)题目:学院专业学号姓名指导教师职称:完成日期诚信承诺我谨在此承诺:本人所写的毕业论文《》均系本人独立完成,没有抄袭行为,凡涉及其他作者的观点和材料,均作了注释,若有不实,后果由本人承担。
承诺人(签名):年月日基于java开发的蜘蛛纸牌程序设计姓名:关俊生学号:指导老师:李林国摘要:java是由Sun Microsystems公司于1995年5月推出的Java程序设计语言(以下简称Java语言)和Java平台的总称。
Java是面向对象的语言。
蜘蛛纸牌是一款受人喜欢的休闲游戏,微软的每一代操作系统中都装有这种纸牌游戏,很多人都玩过蜘蛛纸牌,都熟悉蜘蛛纸牌游戏所需要的功能。
本人做的蜘蛛纸牌游戏开发理念是基于WINDOWS XP操作系统中自带蜘蛛纸牌游戏。
利用java语言实现了蜘蛛纸牌游戏的主要功能如纸牌的移动、放置、回收、重发。
利用javax.swing包的类实现纸牌游戏的用户界面,通为各个菜单组件添加监视器来实现鼠标单击事件所触发的接口方法,使得用户可以单击菜单项来实现具体的功能。
通过设置纸牌的等级来初始化纸牌随机分配纸牌,为用户玩纸牌游戏提供相应的等级。
意义:通过自己对蜘蛛纸牌游戏的开发,使我更加热爱java语言,让我懂得和洗去了更多程序开发的知识及经验,为以后进入编程工作提供条件。
关键字:java语言、游戏背景、功能实现Spider solitaire program based on java developmentName: Guan Junsheng Student ID: 200 829 010 213 Instructor: Li LinguoAbstract: java is the Java programming language from Sun Microsystems, Inc. in May 1995 (hereinafter referred to as the general term of the Java language) and Java platforms. Java is object-oriented languages. Spider Solitaire is a people like casual games, each generation of Microsoft's operating system are equipped with this card game, many people have played Spider Solitaire are all familiar with the functionality required by the spider card game. I do spider solitaire game development philosophy is based on the WINDOWS XP operating system comes with the spider solitaire game. Java language to achieve the main function of the spider solitaire game, such asmovement of the playing cards, place, recycling, re-issued. The use of the javax.swing package class that implements the user interface of the card game pass for each menu component to add a monitor to the mouse click event triggered by the interface method, the user can click the menu items to achieve a specific function. To initialize the cards by the level of the set of cards randomly assigned to cards, to provide the appropriate level for users playing solitaire. Meaning: the spidersolitaire game development, so that I more love the java language, so I know how to wash away the more knowledge and experience of program development, and provide conditions for the future to enter the programming work.Keywords: Java language, the background of the game functions目录1.绪论1.1 游戏开发的背景知识.....................................1.2 需要做的准备工作......................................2.开发工具介绍................................................2.1 java语言概述..........................................2.2 java语言的特点........................................2.3 Eclipse开发平台介绍...................................3.总体设计...................................................3.1代码功能模块的设计....................................3.2 程序总体设计流程图...................................3.3模块一的详细介绍......................................3.3.1 主要的类.......................................3.3.2 主要的变量.............................................................................3.4 模块二的详细介绍.....................................3.4.1主要的类.........................................3.4.2 主要的变量.....................................3.4.3主要的方法.......................................3.5 模块三的详细介绍......................................3.5.1主要的类..........................................3.5.2主要的变量.......................................3.5.3 主要的方法........................................3.6模块四的详细.............................................3.6.1主要的类...........................................3.6.2主要的变量.......................................3.6.3 主要的方法........................................4.功能设计....................................................4.1 需要实现的主要功能......................................4.2 功能设计流程图..........................................4.3 主要功能的代码实现......................................4.3.1 游戏菜单栏内游戏菜单及帮助菜单功能展示............4.3.2 主界面的设计.........................................4.3.3 纸牌的初始化以及发牌操作.............................4.3.4 纸牌的移动以及放置....................................4.3.5显示当前纸牌可行的操作................................4.3.6 回收纸牌.............................................5.程序的运行及发布................................................5.1 运行程序....................................................5.2 发布程序....................................................6.工作总结........................................................参考文献..........................................................1.绪论1.1 游戏开发的背景知识相信很多人都玩过蜘蛛纸牌这款休闲游戏,现在随着生活水平的提高,人们拥有充分的时间来享受休闲游戏带来的快乐,越来越多的人亲睐蜘蛛纸牌游戏。
《面向对象程序设计》课程设计报告题目: 下拉列表运算器设计专业: xxxxx班级: xxx姓名: xx指导教师: xx成绩:xxxxxx 年 x 月xx 日xx目录1设计内容及要求 (2)1.1 设计内容 (2)1.2 设计要求 (2)2概要设计 (2)2.1代码功能功能模块设计: (2)2.2程序的总体设计流程图: (3)2.3模块一的详细介绍: (3)2.3.1主要的类: (3)2.3.2主要的变量: (4)2.3.3主要的方法: (4)2.4模块二的详细介绍: (5)2.4.1主要的类: (5)2.4.2主要的变量: (5)2.4.3主要的方法: (5)2.5模块三的详细介绍: (6)2.5.1主要类介绍: (6)2.5.2主要变量: (6)2.5.3主要方法: (7)2.6模块四的详细介绍: (7)2.6.1主要的类: (8)2.6.2主要的变量: (8)2.6.3主要的方法: (8)3设计过程或程序代码 (9)3.1需要实现的主要功能: (9)3.2功能设计流程图: (10)3.3主要功能的代码实现: (10)3.3.1游戏菜单栏内游戏菜单及帮助菜单功能展示: (10)3.3.2主界面的设计: (11)3.3.3纸牌的初始化以及发牌操作 (13)3.3.4纸牌的移动以及放置 (18)3.3.5显示当前纸牌可行的操作: (19)3.3.6回收纸牌: (21)4设计结果与分析 (22)4.1运行程序: (22)4.2发布程序: (23)4.3总结: (24)5参考文献 (24)1设计内容及要求1.1 设计内容相信很多人都玩过蜘蛛纸牌这款休闲游戏,现在随着生活水平的提高,人们拥有充分的时间来享受休闲游戏带来的快乐,越来越多的人亲睐蜘蛛纸牌游戏。
谈起这款游戏,大家并不陌生。
从WINDOWS2000系统开始,就嵌入了蜘蛛纸牌游戏,可是随着微软系统的不段升级,蜘蛛纸牌游戏的功能业变得越来越强大,游戏的界面也更加美观。
目录1. 选题目的与系统概述 (2)2. 系统可行性分析与相关技术背景分析 (3)2.1系统可行性分析 (3)2.2相关技术背景分析 (3)3. 系统设计与关键技术 (4)3.1系统设计 (4)3.2关键技术 (5)4.系统测试与操作实施方法 (9)4.1进入游戏运行界面 (9)4.2 游戏的具体的操作过程 (9)4.3进入“帮助”菜单 (10)4.4游戏中的异常处理情况 (11)5.系统设计总结与回顾 (12)6.附录 (13)6.1 AboutDialog.java (13)6.2 PKCard.java (14)6.3 Spider.java (20)6.4 Spider M enuBar.java (29)1.选题目的与系统概述随着经济全球一体化的逐步加剧,人们的生活节奏越来越快。
蜘蛛纸牌游戏的一种,旨在让工作学习之后疲惫的玩家有一个轻愉快的放松方式。
与普通的纸牌相比,降低了一点难度。
游戏简单级别由8组A-K的清一色黑桃牌面组成,取消了红黑相间的游戏规则,更突然出强化了玩家在安排事物方面的能力。
蜘蛛纸牌游戏实现了与Windows系列操作系统中自带的蜘蛛纸牌游戏类似的功能。
该游戏程序中采用Windows系列中游戏的图片,运用Java语言设计了线程、鼠标事件、纸牌的装载、图形界面的构造、组件监听接口的实现、生成蜘蛛纸牌游戏的框架、实现游戏中的方法,是一种休闲益智游戏。
2.系统可行性分析与相关技术背景分析2.1系统可行性分析蜘蛛纸牌游戏规则是:(1)将电脑分发给你的牌按照相同的花色又打至小排列起来,直到桌面上的牌全都消失。
(2)可执行的牌必须为明牌(3)单牌移动规则(4)多拍移动规则游戏分三个等级:(1)简答:单一花色;(2)中级:双花色;(3)四花色。
2.2相关技术背景分析2.2.1蜘蛛纸牌游戏是基于Eclipse平台的Java程序。
Eclipse的背景如下:Eclipse最初是IBM公司的一个软件产品。
蜘蛛纸牌java程序设计小游戏设计代码JA V A程序——小游戏设计:蜘蛛纸牌4代码如下:import javax.swing.JMenuBar;import javax.swing.JMenu;import javax.swing.JMenuItem;import javax.swing.JRadioButtonMenuItem;import javax.swing.ButtonGroup;public class SpiderMenuBar extends JMenuBar{//生成spider框架对象Spider main = null;//生成菜单组JMenu jNewGame = new JMenu("游戏");JMenu jHelp = new JMenu("帮助");//生成菜单项JMenuItem jItemAbout = new JMenuItem("关于");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("显示可行操作");/****构造函数,生成JMenuBar的图形界面*/public SpiderMenuBar(Spider spider){this.main = spider;/****初始化“游戏”菜单栏*/jNewGame.add(jItemOpen);jNewGame.add(jItemPlayAgain);jNewGame.add(jItemValid);jNewGame.addSeparator();jNewGame.add(jRMItemEasy);jNewGame.add(jRMItemNormal);jNewGame.add(jRMItemHard);jNewGame.addSeparator();jNewGame.add(jItemExit);ButtonGroup group = new ButtonGroup();group.add(jRMItemEasy);group.add(jRMItemNormal);group.add(jRMItemHard);jHelp.add(jItemAbout);this.add(jNewGame);this.add(jHelp);//为组件添加事件监听并实现//“开局”jItemOpen.addActionListener(newjava.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { main.newGame();}});//“重新发牌”jItemPlayAgain.addActionListener(newjava.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { if(main.getC() < 60){main.deal();}}});//"显示可行操作"jItemValid.addActionListener(newjava.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { new Show().start();}});//“退出”jItemExit.addActionListener(newjava.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { main.dispose();System.exit(0);}});//“简单级别”默认已选jRMItemEasy.setSelected(true);//“简单级别”jRMItemEasy.addActionListener(newjava.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { main.setGrade(Spider.EASY);main.initCards();main.newGame();}});//“中级”jRMItemNormal.addActionListener(newjava.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { main.setGrade(Spider.NATURAL);main.initCards();main.newGame();}});//“高级”jRMItemHard.addActionListener(newjava.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { main.setGrade(Spider.HARD);main.initCards();main.newGame();}});jNewGame.addMenuListener(newjavax.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) {} });//“关于”jItemAbout.addActionListener(newjava.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) {new AboutDialog();}});}/****构造线程:显示可以执行的操作*/class Show extends Thread{public void run(){main.showEnableOperator();}}}。
蜘蛛纸牌java代码_源代码-Java实现蜘蛛纸牌.doc源代码-Java实现蜘蛛纸牌aboutdialog.javaimport javax.swing.*;import java.awt.*;/***“关于”窗⼝*/public class AboutDialog extends JDialog{JPanel jMainPane = new JPanel();JTabbedPane jTabbedPane = new JTabbedPane();private JPanel jPanel1 = new JPanel();private JPanel jPanel2 = new JPanel();private JTextArea jt1 = new JTextArea("将电脑多次分发给你的牌按照相同的花⾊由⼤⾄⼩排列起来。
直到桌⾯上的牌全都消失。
"); private JTextArea jt2 = new JTextArea("该游戏中,纸牌的图⽚来⾃于Windows7的纸牌游戏,图⽚权属于原作者所有!");/***构造函数*/public AboutDialog(){setTitle("蜘蛛牌");setSize(300,200);setResizable(false);//⽣成的窗⼝由程序员决定⼤⼩,⽤户不能随意改变窗⼝⼤⼩setDefaultCloseOperation (WindowConstants.DISPOSE_ON_CLOSE);//设置框的⼤⼩Container c = this.getContentPane();//初始化容器jt1.setSize(260,200);jt2.setSize(260,200);jt1.setEditable(false);//是调⽤这个函数的控件不能被编辑jt2.setEditable(false);jt1.setLineWrap(true);//设置⾃动换⾏jt2.setLineWrap(true);jt1.setFont(new Font("楷体_GB2312", java.awt.Font.BOLD, 13));jt1.setForeground(Color.black);jt2.setFont(new Font("楷体_GB2312", java.awt.Font.BOLD, 13));jt2.setForeground(Color.black);jPanel1.add(jt1);jPanel2.add(jt2);jTabbedPane.setSize(300,200);jTabbedPane.addTab("游戏规则", null, jPanel1, null);jTabbedPane.addTab("声明", null, jPanel2, null);jMainPane.add(jTabbedPane);c.add(jMainPane);pack();//窗⼝this.setVisible(true);//设置可见}}PKcard.javaimport java.awt.*;import java.awt.event.*;import javax.swing.*;public class PKCard extends JLabel implements MouseListener,//implements实现接⼝MouseMotionListener{//纸牌的位置Point point = null;Point initPoint = null;int value = 0;int type = 0;String name = null;Container pane = null;Spider main = null;boolean canMove = false;boolean isFront = false;PKCard previousCard = null;public void mouseClicked(MouseEvent arg0){}public void flashCard(PKCard card){//启动Flash线程new Flash(card).start();//不停的获得下⼀张牌,直到完成if(main.getNextCard(card) !=。
宜宾学院2020届毕业设计(论文)摘要现在社会在进步,人民生活水平也随着提高,人们可以利用多余的时间去体验游戏,从中感受快乐。
目前为止,游戏有很多类型。
例如,动作、冒险、模拟、角色扮演、休闲等类游戏都在迅速发展。
其中,很多人最熟悉的应该就是蜘蛛纸牌游戏了吧。
蜘蛛纸牌游戏是一款休闲益智类游戏,非常受大家的欢迎,随着科学技术的发展科技水平的进步,游戏实现的功能也越来越多,游戏界面也变得越来越好看,玩家的体验感受也越来越好, 让游戏的开发对于人们的生活娱乐更加有意义。
因此,也有越来越多的人亲睐于这款游戏。
这款蜘蛛纸牌游戏我是用Java语言来实现的,其中主要实现了纸牌的移动,发放等。
其设计的灵感主要来自于window7操作系统中的蜘蛛纸牌游戏。
关键词休闲游戏;Java语言;功能实现AbstractNow that society is progressing and people's living standards are improving, people can use the extra time to experience games and feel happy. So far, there are many types of games. For example, action, adventure, simulation, role-playing, leisure and other games are all developing rapidly. Among them, the spider card game should be the most familiar to many people. Spider Solitaire is a casual puzzle game that is very popular with everyone. With the development of science and technology, the level of science and technology has improved, the game has more and more functions, and the game interface has become more and more beautiful The experience experience is getting better and better, making game development more meaningful for people's life and entertainment. Therefore, more and more people love this game.I implemented this spider card game in Java language, which mainly realized the movement and distribution of cards. The inspiration for its design comes mainly from the spider card game in the window7 operating systemKey words the recreational game; java language; function realization目录第1章绪论 (3)1.1 休闲娱乐游戏[1] (3)1.2 游戏的背景 (3)1.3 国内外研究现状[2] (3)1.4 工作内容 (3)1.5 开发语言的简介[3] (4)1.6 开发语言特点[4] (4)1.7 开发工具Eclipse[5] (5)1.8 本游戏开发的意义 (6)第2章需求分析设计 (6)2.1 程序设计的任务概述[6] (6)2.2 系统特点 (6)2.3 功能需求 (7)2.4 界面的设计 (7)2.5 游戏设计主流程分析 (7)2.6 综合要求 (8)2.7 模型[8] (8)2.8 游戏程序需要解决的问题[9] (9)第3章程序的总体设计 (9)3.1 线程的设计 (9)3.1.1 通过Thread类实现 (9)3.1.2 实现Runnable接口 (10)3.2 代码功能的设计 (10)3.3 总体设计流程图 (10)3.4 模块一Spider (11)3.5 模块二SpiderMenuBar (13)3.6 模块三AboutDialog (14)3.7 模块四PKCard (15)第4章程序的详细设计 (6)4.1 程序流程图 (16)4.2 界面设计的实现[10] (17)4.3 等级设置的实现[14] (24)4.4 初始化纸牌以及发牌操作的实现[16] (25)4.5 游戏的运行 (27)4.5.1 纸牌游戏的移动放置操作[18] (28)4.5.2 回收纸牌操作[19] (29)4.5.3 帮助菜单 (29)4.5.4 退出功能 (29)第5章系统测试 (29)5.1 测试方法 (29)5.2 测试用例[20] (30)5.3 测试结果 (30)结论 (36)致谢.......................................................................................................................... 错误!未定义书签。
编号:本科毕业论文(设计)题目:学院专业学号姓名指导教师职称:完成日期诚信承诺我谨在此承诺:本人所写的毕业论文《》均系本人独立完成,没有抄袭行为,凡涉及其他作者的观点和材料,均作了注释,若有不实,后果由本人承担。
承诺人(签名):年月日基于java开发的蜘蛛纸牌程序设计姓名:关俊生学号:200829010213 指导老师:李林国摘要:java是由Sun Microsystems公司于1995年5月推出的Java程序设计语言(以下简称Java语言)和Java平台的总称。
Java是面向对象的语言。
蜘蛛纸牌是一款受人喜欢的休闲游戏,微软的每一代操作系统中都装有这种纸牌游戏,很多人都玩过蜘蛛纸牌,都熟悉蜘蛛纸牌游戏所需要的功能。
本人做的蜘蛛纸牌游戏开发理念是基于WINDOWS XP操作系统中自带蜘蛛纸牌游戏。
利用java语言实现了蜘蛛纸牌游戏的主要功能如纸牌的移动、放置、回收、重发。
利用javax.swing包的类实现纸牌游戏的用户界面,通为各个菜单组件添加监视器来实现鼠标单击事件所触发的接口方法,使得用户可以单击菜单项来实现具体的功能。
通过设置纸牌的等级来初始化纸牌随机分配纸牌,为用户玩纸牌游戏提供相应的等级。
意义:通过自己对蜘蛛纸牌游戏的开发,使我更加热爱java语言,让我懂得和洗去了更多程序开发的知识及经验,为以后进入编程工作提供条件。
关键字:java语言、游戏背景、功能实现Spider solitaire program based on java development Name: Guan Junsheng Student ID: 200 829 010 213 Instructor: Li LinguoAbstract: java is the Java programming language from Sun Microsystems, Inc. in May 1995 (hereinafter referred to as the general term of the Java language) and Java platforms. Java is object-oriented languages. Spider Solitaire is a people like casual games, each generation of Microsoft's operating system are equipped with this card game, many people have played Spider Solitaire are all familiar with the functionality required by the spider card game. I do spider solitaire game development philosophy is based on the WINDOWS XP operating system comes with the spider solitaire game. Java language to achieve the main function of the spider solitaire game, such as movement of the playing cards, place, recycling, re-issued. The use of the javax.swing package class that implements the user interface of the card game pass for each menu component to add a monitor to the mouse click event triggered by the interface method, the user can click the menu items to achieve a specific function. To initialize the cards by the level of the set of cards randomly assigned to cards, to provide the appropriate level for users playing solitaire. Meaning: the spider solitaire game development, so that I more love the java language, so I know how to wash away the more knowledge and experience of program development, and provide conditions for the future to enter the programming work.Keywords: Java language, the background of the game functions目录1.绪论1.1 游戏开发的背景知识.....................................1.2 需要做的准备工作......................................2.开发工具介绍................................................2.1 java语言概述..........................................2.2 java语言的特点........................................2.3 Eclipse开发平台介绍...................................3.总体设计...................................................3.1代码功能模块的设计....................................3.2 程序总体设计流程图...................................3.3模块一的详细介绍......................................3.3.1 主要的类.......................................3.3.2 主要的变量......................................3.3.3主要的方法.......................................3.4 模块二的详细介绍.....................................3.4.1主要的类.........................................3.4.2 主要的变量.....................................3.4.3主要的方法.......................................3.5 模块三的详细介绍......................................3.5.1主要的类..........................................3.5.2主要的变量.......................................3.5.3 主要的方法........................................3.6模块四的详细.............................................3.6.1主要的类...........................................3.6.2主要的变量.......................................3.6.3 主要的方法........................................4.功能设计....................................................4.1 需要实现的主要功能......................................4.2 功能设计流程图..........................................4.3 主要功能的代码实现......................................4.3.1 游戏菜单栏内游戏菜单及帮助菜单功能展示............4.3.2 主界面的设计.........................................4.3.3 纸牌的初始化以及发牌操作.............................4.3.4 纸牌的移动以及放置....................................4.3.5显示当前纸牌可行的操作................................4.3.6 回收纸牌.............................................5.程序的运行及发布................................................5.1 运行程序....................................................5.2 发布程序....................................................6.工作总结........................................................参考文献..........................................................1.绪论1.1 游戏开发的背景知识相信很多人都玩过蜘蛛纸牌这款休闲游戏,现在随着生活水平的提高,人们拥有充分的时间来享受休闲游戏带来的快乐,越来越多的人亲睐蜘蛛纸牌游戏。
基于javafx设计的蜘蛛纸牌游戏包含三个程序块:Spider.java ; SpiderMenu.java ; PKCard.java程序入口在Spider.java中1 Spider.javaimport java.util.*;import javafx.util.Duration;import javafx.geometry.Point2D;import javafx.animation.PathTransition;import javafx.animation.PathTransitionBuilder;import javafx.animation.PathTransition.OrientationType;import javafx.application.Application;import javafx.scene.Group;import javafx.scene.Scene;import javafx.stage.Stage;import bel;import javafx.scene.effect.Lighting;import javafx.scene.paint.Color;import javafx.scene.shape.CubicCurveTo;import javafx.scene.shape.MoveTo;import javafx.scene.shape.Path;import javafx.scene.shape.PathBuilder;import javafx.scene.text.Font;import javafx.scene.text.Text;import javafx.event.EventHandler;import javafx.scene.image.Image;import javafx.scene.image.ImageView;import javafx.scene.input.MouseEvent;public class Spider extends Application {//整型变量,表示难度等级为:简单public static final int EASY = 1;//整型变量,表示难度等级为:普通public static final int NATURAL = 2;//整型变量,表示难度等级为:难public static final int HARD = 3;//设定初始难度等级为简单private int grade = Spider.EASY;private PKCard cards[] = new PKCard[104];private PathTransition pathTransition;private int c = 0;private int n = 0;private int a = 0;private int finish = 0;Point2D p1 = null ;Label label[] = null ;Point2D point[] = new Point2D[10];Group root1 = new Group();static final Image ICON = new Image("images/white.gif"); Hashtable<Point2D, PKCard> table = null;Color d = Color.rgb(0,100,0);public void init(Stage primaryStage) {Group root = new Group() ;primaryStage.setResizable(false) ;primaryStage.setScene(new Scene(root,1024,704,d)) ;primaryStage.setTitle("蜘蛛纸牌");label = new Label[10];int x = 20 ;for(int k=0;k<10;k++) {ImageView imageView = new ImageView(ICON);label[k] = new Label("",imageView);label[k].resizeRelocate(x,25 ,71,96);label[k].setVisible(true);point[k] = new Point2D(x,25);x += 101 ;root.getChildren().add(label[k]);}root1 = root ;new SpiderMenu(this);this.initCards();this.setCardsLocation();root = root1 ;}public void newGame(){this.c = 0 ;for(int k=0;k<=103;k++){cards[k].setVisible(false);}this.initCards(); //纸牌赋值并打乱for(int k=0;k<=103;k++){cards[k].setVisible(true);}this.setCardsLocation(); //放置纸牌this.setOpen();//发牌开局this.setLabelZOrder() ;}public void initCards(){//如果纸牌已被赋值,即将其从框架的面板中移去if (cards[0] != null){for (int i = 0; i < 104; i++){cards[i].setVisible(false);table.remove(cards[i].getLocation());}}int n = 0;//通过难度等级,为n赋值if (this.grade == Spider.EASY){n = 1;}else if (this.grade == Spider.NA TURAL){n = 2;}else{n = 4;}//为104张扑克牌赋值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);}}for(int m=0;m<=103;m++){final PKCard pk=cards[m];// 鼠标点击监听pk.setOnMousePressed(new EventHandler<MouseEvent>() { public void handle(MouseEvent me) {if(pk.canMove) {pk.mousePressed(me);}}});//鼠标拖拽监听pk.setOnMouseDragged(new EventHandler<MouseEvent>() {public void handle(MouseEvent me) {if(pk.canMove){pk.mouseDragged(me);}}});//鼠标释放监听pk.setOnMouseReleased(new EventHandler<MouseEvent>() {public void handle(MouseEvent me) {pk.mouseReleased(me);}});}//随机纸牌初始化,打乱纸牌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 = cards[a];cards[a] = cards[b];cards[b] = temp;}}public void setCardsLocation(){table = new Hashtable<Point2D, PKCard>();c = 0;finish = 0;n = 0;a = 0;double x = 863;double y = 580;//初始化待展开的纸牌0~49号for (int i = 0; i < 5; i++){for (int j = 0; j < 10; j++){int n = i * 10 + j;root1.getChildren().add(cards[n]);//将card转向背面cards[n].turnRear();//将card放在固定的位置上cards[n].moveto(new Point2D(x, y));//将card的位置及相关信息存入table.put(new Point2D(x, y), cards[n]);final PKCard pkc = cards[n];pkc.setOnMouseClicked(new EventHandler<MouseEvent>() {public void handle(MouseEvent me) {if((580-(pkc.getLocation().getY())<10) && (1024-pkc.getLocation().getX())<200) {if(c < 60){Spider.this.deal();}}}});}x += 10;}x = 913;y = 580;//初始化背面显示的纸牌50~103号for (int i = 5; i<11; i++){for (int j = 0; j < 10; j++){int n = i * 10 + j;if (n >= 104) break;root1.getChildren().add(cards[n]);cards[n].moveto(new Point2D(x, y));table.put(new Point2D(x, y),cards[n]);}}}public void setOpen() {c = 0 ;for(int i=5;i<=11;i++) {for(int j=0;j<10;j++) {int n=10*i+j ;if(n>=94) {if(n<104) {cards[n].turnFront();cards[n].setCanMove(true);this.c++;}else break ;}else{ cards[n].turnRear();}Path path = PathBuilder.create().elements(newMoveTo(cards[n].getLocation().getX(),cards[n].getLocation().getY()),new CubicCurveTo(55.5+101*j, 48+5*i, 55.5+101*j, 48+5*i, 55.5+101*j, 48+5*i)).build();path.setStroke(Color.DODGERBLUE);path.getStrokeDashArray().setAll(0d,10000d);root1.getChildren().add(path);pathTransition = PathTransitionBuilder.create().duration(Duration.seconds(0.5)).path(path).node(cards[n]).orientation(OrientationType.NONE).cycleCount(1).autoReverse(false).build();pathTransition.play();try{Thread.sleep(1);//毫秒}catch(Exception e){}table.remove(cards[n].getLocation());cards[n].moveto(new Point2D(point[j].getX(),point[j].getY()+(i-5)*5));table.put((new Point2D(point[j].getX(),point[j].getY()+(i-5)*5)),cards[n]);}}c = 10 ;}public void setNA(){a = 0;n = 0;}public Point2D getLastCardLocation(int column) {Point2D p1 = new Point2D(20+column*101,25);PKCard card = (PKCard) this.table.get(p1);if (card == null) return null;while (card != null){p1 = card.getLocation();card = this.getNextCard(card);}return p1;}public PKCard getNextCard(PKCard card){Point2D point = card.getLocation();point = new Point2D(point.getX(),point.getY()+5) ;card = (PKCard) table.get(point);if (card != null)return card;//此牌是背面向上,故下张牌y坐标相差5point = new Point2D(point.getX(),point.getY()+15) ;card = (PKCard) table.get(point);if(card!=null) return card ;//此牌是正面向上,故下张牌坐标相差20else return null;}public PKCard getPreviousCard(PKCard card){Point2D point = new Point2D(card.getLocation().getX(),card.getLocation().getY()-5);card = (PKCard) table.get(point);if (card != null){return card;//上面牌背面向上}point = new Point2D(point.getX(),point.getY()-15);card = (PKCard) table.get(point);return card;//上面牌正面向上}public Point2D getGroundLabelLocation(int column){return point[column];}public void deal(){this.setNA();//判断10列中是否空列for (int i = 0; i < 10; i++){if (this.getLastCardLocation(i) == null){final Stage stage = new Stage();Group rootGroup = new Group();Scene scene = new Scene(rootGroup, 350, 100, Color.PURPLE);stage.setScene(scene);stage.centerOnScreen();stage.show();Text text = new Text(20, 110, "提示:有空位不能发牌!");text.setX(40);text.setY(50);text.setFill(Color.DODGERBLUE);text.setEffect(new Lighting());text.setFont(Font.font(Font.getDefault().getFamily(), 28));rootGroup.getChildren().add(text);stage.show();return;}}System.out.println(+c);if(this.c <60) {for (int i=0;i<=9;i++) {Point2D LastPoint = this.getLastCardLocation(i);LastPoint = new Point2D(LastPoint.getX(),LastPoint.getY()+20);Path path = PathBuilder.create().elements(newMoveTo(cards[59-c-i].getLocation().getX(),cards[59-c-i].getLocation().getY()),new CubicCurveTo(55.5+101*i, LastPoint.getY()+48, 55.5+101*i,LastPoint.getY()+48, 55.5+101*i, LastPoint.getY()+48)).build();path.setStroke(Color.DODGERBLUE);path.getStrokeDashArray().setAll(0d,10000d);root1.getChildren().add(path);pathTransition = PathTransitionBuilder.create().duration(Duration.seconds(0.5)).path(path).node(cards[59-c-i]).orientation(OrientationType.NONE).cycleCount(1).autoReverse(false).build();pathTransition.play();try{Thread.sleep(1);//毫秒}catch(Exception e){}table.remove(cards[59-c-i].getLocation());cards[59-c-i].moveto(LastPoint) ;table.put(LastPoint,cards[59-c-i]);cards[59-c-i].turnFront();cards[59-c-i].setCanMove(true);cards[59-c-i].toFront();Point2D point = new Point2D(LastPoint.getX(),LastPoint.getY());if (cards[59-c - i].getCardV alue() == 1){int n = cards[59-c - i].whichColumnAvailable(point);point = new Point2D(point.getX(),point.getY()-240);PKCard card = (PKCard) this.table.get(point);if (card != null && card.isCardCanMove()){this.haveFinish(n);}}}c +=10 ;System.out.println(+c);}}public int getC(){return c;}public void setGrade(int grade){this.grade = grade;}public void showEnableOperator(){int x = 0;out: while (true){Point2D 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);////扑克牌1}if (a == 10){a = 0;}for (; a < 10; a++){if (a != n){Point2D 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);//扑克牌2}while (!c.isCardCanMove());if (c.getCardValue() == card.getCardValue() + 1){card.flashCard(card);try{Thread.sleep(800);}catch (InterruptedException e){e.printStackTrace();}c.flashCard(c);a++;if (a == 10){n++;}break out;}}}n++;if (n == 10){n = 0;}x++;if (x == 10){break out;}}}public void setLabelZOrder(){for (int i = 0; i < 10; i++){label[i].toBack();}}public void haveFinish(int column){Point2D point = this.getLastCardLocation(column);PKCard card = (PKCard) this.table.get(point);do{Path path = PathBuilder.create().elements(new MoveTo(card.getLocation().getX(),card.getLocation().getY()),new CubicCurveTo(55.5+finish * 10,628, 55.5+finish * 10,628, 55.5+finish * 10, 628)).build();path.setStroke(Color.DODGERBLUE);path.getStrokeDashArray().setAll(0d,10000d);root1.getChildren().add(path);pathTransition = PathTransitionBuilder.create().duration(Duration.seconds(0.5)).path(path).node(card).orientation(OrientationType.NONE).cycleCount(1).autoReverse(false).build();pathTransition.play();try{Thread.sleep(1);//毫秒}catch(Exception e){}this.table.remove(point);card.moveto(new Point2D(20 + finish * 10, 580));card.toFront();//将纸牌新的相关信息存入Hashtablethis.table.put(card.getLocation(), card);card.setCanMove(false);point = this.getLastCardLocation(column);if (point == null)card = null;elsecard = (PKCard) this.table.get(point);}while (card != null && card.isCardCanMove());finish++;//如果8付牌全部组合成功,则显示成功的对话框if (finish == 8){final Stage stage = new Stage();Group rootGroup = new Group();Scene scene = new Scene(rootGroup, 400, 150, Color.BLUE);stage.setScene(scene);stage.setTitle("通知");stage.centerOnScreen();stage.show();Text text = new Text(20, 110, "恭喜你,顺利通关!");text.setFill(Color.DODGERBLUE);text.setEffect(new Lighting());text.setFont(Font.font(Font.getDefault().getFamily(), 40));rootGroup.getChildren().add(text);stage.show();return;}if (card != null){card.turnFront();card.setCanMove(true);}}public double getSampleWidth() {return 1024 ;}public double getSampleHeight() {return 724 ;}@Overridepublic void start(Stage primaryStage) throws Exception { init(primaryStage) ;primaryStage.show() ;}/*** @param args*/public static void main(String[] args) {launch(args);}}2 SpiderMenu.javaimport javafx.scene.Group;import javafx.scene.Scene;import javafx.scene.control.ColorPicker;import bel;import javafx.scene.control.Menu;import javafx.scene.control.MenuBar;import javafx.scene.control.MenuBuilder;import javafx.scene.control.MenuItem;import javafx.scene.control.MenuItemBuilder;import javafx.scene.control.ToolBar;import javafx.scene.control.ToolBarBuilder;import javafx.scene.effect.Lighting;import javafx.scene.input.MouseEvent;import yout.VBox;import yout.VBoxBuilder;import javafx.scene.paint.Color;import javafx.scene.shape.Rectangle;import javafx.scene.text.Font;import javafx.scene.text.Text;import javafx.stage.Stage;import javafx.event.ActionEvent;import javafx.event.Event;import javafx.event.EventHandler;import javafx.geometry.Insets;import javafx.geometry.Pos;public class SpiderMenu {Spider main = null;VBox vbox = new VBox();final MenuBar menuBar = new MenuBar();MenuItem menuOpen = MenuItemBuilder.create().text("开局").build();MenuItem menuRefapai = MenuItemBuilder.create().text("重新发牌").build();MenuItem menuEnableOperator = MenuItemBuilder.create().text("显示可行操作").build();MenuItem menuExit = MenuItemBuilder.create().text("退出").build();MenuItem menuEasy = MenuItemBuilder.create().text("简单:单花色").build();MenuItem menuMedium = MenuItemBuilder.create().text("中等:双花色").build();MenuItem menuHard = MenuItemBuilder.create().text("困难:四花色").build();MenuItem menuGameRule = MenuItemBuilder.create().text("游戏规则").build();MenuItem menuStatement = MenuItemBuilder.create().text("声明").build();public SpiderMenu(Spider spider){this.main = spider;Menu menuGrade = MenuBuilder.create().text("等级设置").items(menuEasy, menuMedium,menuHard).build();Menu menuAbout = MenuBuilder.create().text("关于").items(menuGameRule, menuStatement).build();Menu menuGame = MenuBuilder.create().text("游戏").items( menuOpen, menuRefapai,menuEnableOperator,menuGrade, menuExit).build();Menu menuHelp = MenuBuilder.create().text("帮助").items( menuAbout).build();menuBar.getMenus().addAll(menuGame,menuHelp);menuBar.setPrefWidth(1024);vbox.getChildren().addAll(menuBar/*,standardToolbar, coloredObjectsVBox*/);main.root1.getChildren().addAll(vbox);//鼠标监听menuOpen.setOnAction(new EventHandler<ActionEvent>() {public void handle(ActionEvent me) {menuRefapai.setDisable(false);main.newGame();}});menuRefapai.setOnAction(new EventHandler<ActionEvent>() {public void handle(ActionEvent me) {if(main.getC() < 60){main.deal();}}});menuEnableOperator.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent me) {new Show().start();}});menuExit.setOnAction(new EventHandler<ActionEvent>() {public void handle(ActionEvent me) {System.exit(0);}});menuEasy.setOnAction(new EventHandler<ActionEvent>() {public void handle(ActionEvent me) {main.setGrade(Spider.EASY);main.initCards();main.newGame();}});menuMedium.setOnAction(new EventHandler<ActionEvent>() {public void handle(ActionEvent me) {main.setGrade(Spider.NATURAL);main.initCards();main.newGame();}});menuHard.setOnAction(new EventHandler<ActionEvent>() {public void handle(ActionEvent me) {main.setGrade(Spider.HARD);main.initCards();main.newGame();}});menuGameRule.setOnAction(new EventHandler<ActionEvent>() {public void handle(ActionEvent me) {final Stage stage = new Stage();Group rootGroup = new Group();Scene scene = new Scene(rootGroup, 300, 150, Color.rgb(50,10,0));stage.setScene(scene);stage.setTitle("游戏规则");stage.centerOnScreen();stage.show();Text text = new Text(20, 110, "扑克牌从A到K构成一条龙"+"\n"+"请将相同类型的扑克牌集齐"+"\n"+"一共集齐八条龙即可通关。
编号:本科毕业论文(设计)题目:学院专业学号姓名指导教师职称:完成日期诚信承诺我谨在此承诺:本人所写的毕业论文《》均系本人独立完成,没有抄袭行为,凡涉及其他作者的观点和材料,均作了注释,若有不实,后果由本人承担。
承诺人(签名):年月日基于java开发的蜘蛛纸牌程序设计姓名:关俊生学号:200829010213 指导老师:李林国摘要:java是由Sun Microsystems公司于1995年5月推出的Java程序设计语言(以下简称Java语言)和Java平台的总称。
Java是面向对象的语言。
蜘蛛纸牌是一款受人喜欢的休闲游戏,微软的每一代操作系统中都装有这种纸牌游戏,很多人都玩过蜘蛛纸牌,都熟悉蜘蛛纸牌游戏所需要的功能。
本人做的蜘蛛纸牌游戏开发理念是基于WINDOWS XP操作系统中自带蜘蛛纸牌游戏。
利用java语言实现了蜘蛛纸牌游戏的主要功能如纸牌的移动、放置、回收、重发。
利用javax.swing包的类实现纸牌游戏的用户界面,通为各个菜单组件添加监视器来实现鼠标单击事件所触发的接口方法,使得用户可以单击菜单项来实现具体的功能。
通过设置纸牌的等级来初始化纸牌随机分配纸牌,为用户玩纸牌游戏提供相应的等级。
意义:通过自己对蜘蛛纸牌游戏的开发,使我更加热爱java语言,让我懂得和洗去了更多程序开发的知识及经验,为以后进入编程工作提供条件。
关键字:java语言、游戏背景、功能实现Spider solitaire program based on java development Name: Guan Junsheng Student ID: 200 829 010 213 Instructor: Li LinguoAbstract: java is the Java programming language from Sun Microsystems, Inc. in May 1995 (hereinafter referred to as the general term of the Java language) and Java platforms. Java is object-oriented languages. Spider Solitaire is a people like casual games, each generation of Microsoft's operating system are equipped with this card game, many people have played Spider Solitaire are all familiar with the functionality required by the spider card game. I do spider solitaire game development philosophy is based on the WINDOWS XP operating system comes with the spider solitaire game. Java language to achieve the main function of the spider solitaire game, such as movement of the playing cards, place, recycling, re-issued. The use of the javax.swing package class that implements the user interface of the card game pass for each menu component to add a monitor to the mouse click event triggered by the interface method, the user can click the menu items to achieve a specific function. To initialize the cards by the level of the set of cards randomly assigned to cards, to provide the appropriate level for users playing solitaire. Meaning: the spider solitaire game development, so that I more love the java language, so I know how to wash away the more knowledge and experience of program devel opment, and provide conditions for the future to enter the programming work.Keywords: Java language, the background of the game functions目录1.绪论1.1 游戏开发的背景知识.....................................1.2 需要做的准备工作......................................2.开发工具介绍................................................2.1 java语言概述..........................................2.2 java语言的特点........................................2.3 Eclipse开发平台介绍...................................3.总体设计...................................................3.1代码功能模块的设计....................................3.2 程序总体设计流程图...................................3.3模块一的详细介绍......................................3.3.1 主要的类.......................................3.3.2 主要的变量......................................3.3.3主要的方法.......................................3.4 模块二的详细介绍.....................................3.4.1主要的类.........................................3.4.2 主要的变量.....................................3.4.3主要的方法.......................................3.5 模块三的详细介绍......................................3.5.1主要的类..........................................3.5.2主要的变量.......................................3.5.3 主要的方法........................................3.6模块四的详细.............................................3.6.1主要的类...........................................3.6.2主要的变量.......................................3.6.3 主要的方法........................................4.功能设计....................................................4.1 需要实现的主要功能......................................4.2 功能设计流程图..........................................4.3 主要功能的代码实现......................................4.3.1 游戏菜单栏内游戏菜单及帮助菜单功能展示............4.3.2 主界面的设计.........................................4.3.3 纸牌的初始化以及发牌操作.............................4.3.4 纸牌的移动以及放置....................................4.3.5显示当前纸牌可行的操作................................4.3.6 回收纸牌.............................................5.程序的运行及发布................................................5.1 运行程序....................................................5.2 发布程序....................................................6.工作总结........................................................参考文献..........................................................1.绪论1.1 游戏开发的背景知识相信很多人都玩过蜘蛛纸牌这款休闲游戏,现在随着生活水平的提高,人们拥有充分的时间来享受休闲游戏带来的快乐,越来越多的人亲睐蜘蛛纸牌游戏。
谈起这款游戏,大家并不陌生。
从WINDOWS2000系统开始,就嵌入了蜘蛛纸牌游戏,可是随着微软系统的不段升级,蜘蛛纸牌游戏的功能业变得越来越强大,游戏的界面也更加美观。