毕业论文基于C++的“21点”纸牌游戏设计01280

上传人:仙*** 文档编号:78176511 上传时间:2022-04-21 格式:DOC 页数:22 大小:441.03KB
返回 下载 相关 举报
毕业论文基于C++的“21点”纸牌游戏设计01280_第1页
第1页 / 共22页
毕业论文基于C++的“21点”纸牌游戏设计01280_第2页
第2页 / 共22页
毕业论文基于C++的“21点”纸牌游戏设计01280_第3页
第3页 / 共22页
点击查看更多>>
资源描述
学校代码: 学 号: 课程设计说明书题 目:基于C+的“21点”纸牌游戏设计 学生姓名:学 号: 学 院:班 级:指导教师: 二一二年一月四日大学课程设计(论文)任务书课程名称: 面向对象的程序设计 学院: 班级: 学生姓名: 学号: 指导教师: 一、题目“21点”纸牌游戏二、目的与意义面向对象程序设计课程设计可以培养学生综合运用所学面向对象程序设计知识和技能分析与解决实际问题的能力,以及严肃认真的科学态度和严谨求实的工作作风。 三、要求(包括原始数据、技术参数、设计要求、图纸量、工作量要求等) l 采用面向对象程序设计语言C+进行程序开发l 选用一种C+语言的开发环境设计界面及程序l 在开发环境下,进行程序的运行及调试四、工作内容、进度安排 主要内容使用C+程序设计语言及其开发环境实现简单的“21点”纸牌游戏,完成程序的编写和调试。工作进度安排第一天:熟悉课程设计题目及具体要求,认识所要解决的问题,基本确定选择的开发环境。第二天到第四天:拿出解决问题的初步方案,根据课题给出的题目,确定题目的解决方式及步骤。第五天到第七天:设计系统的功能模块,确定模块的功能,及模块之间的关系。第八天到第十天:分析模块,确定需要的界面、结构,完成软件的整体框架,在开发环境下,编程实现所开发的系统。第十一天到第十二天:综合调试,去除软件中的错误,美化应用程序的界面。第十三天和第十五天:撰写课程设计报告。五、主要参考文献1郑莉,董渊,何江舟.C+语言程序设计.第4版.北京:清华大学出版.2010.72Stanley B.Lippman,Jose LaJoie,Barbara E.Moo.C+ Primer(中文版).第四版.北京: 人民邮电出版社.20063 Walter Savitch. C+面向对象程序设计基础、数据结构与编程思想.第4版.北京: 清华大学出版社.20034钱能.C+程序设计教程.第2版.北京:清华大学出版社.20055郑莉.C+语言程序设计案例教程.第1版.北京:清华大学出版社.20056韦朴,陈泰生. Visual C+通用范例开发金典.北京:电子工业出版社.2008审核意见系(教研室)主任(签字) 指导教师下达时间 2011 年 12月 19日指导教师签字:_摘 要本次C+课程设计题目是“21 点纸牌游戏” ,系统的主要功能是娱乐游戏,有电脑和玩家一起玩这个游戏,玩家设法使自己的牌达到总分21并要比电脑开的点数大而且不超过这个数值。扑克牌的分值取它们的面值,J,Q,K 分别是11,12和13分。“21 点纸牌游戏”是比较经典的一款小游戏,实现它的方法很多,可以用很多不同算法和语言实现,如 C,C+,VB,JAVA 等。本文研究的是以 Visual C+ 6.0 为开发环境,设计并开发一款“21 点纸牌游戏”。关键词:程序设计;“21 点纸牌游戏”;C+目 录第一章 引 言61.1 C+介绍61.1.1 组成部分61.1.2 C+语言的主要特点61.2 “21点游戏”介绍71.2.1 游戏起源71.2.2 本课程设计7第二章 设计要求81.1 问题描述81.2 要求分析8第三章 总体设计93.1 功能分析93.1.1 程序的主要功能描述93.1.2 总体结构93.2 详细设计93.2.1序流程图9第四章 功能测试114.1 主界面114.2 功能测试124.2.1输入赌注124.2.2 电脑随机发牌134.2.3 用户决定是否要牌134.2.4 报错界面144.2.5 开牌显示游戏结果144.2.6 退出游戏15第五章 源程序16参考文献21第一章 引 言1.1 C+介绍 C+这个词在中国大陆的程序员圈子中通常被读做“C加加”,而西方的程序员通常读做“C plus plus”,“CPP”。 它是一种使用非常广泛的计算机编程语言。C+是一种静态数据类型检查的、支持多重编程范式的通用程序设计语言。它支持过程化程序设计、数据抽象、面向对象程序设计、制作图标等等泛型程序设计等多种程序设计风格。1.1.1 组成部分现在C+由以下四个“子语言”组成: (1)C子语言。C+支持C语言的几乎全部功能,主要是c89的部分,在语法上与C语言仅有极微妙的差别(如括号表达式的左右值性,具体请参考C+标准文献)。 (2)面向对象的C+语言。C+语言原本不具备面向对象的设计功能,然而随着面向对象的概念的提出以及如Java等语言的发展成熟,C+语言也开发出了支持面向对象功能的版本。(3)泛型编程语言。C+强大(但容易失控的)模板功能使它能在编译期完成许多工作,从而大大提高运行期效率。 (4)STL(C+标准模板库,Standard Template Library)。随着STL的不断发展,它已经逐渐成为C+程序设计中不可或缺的部分,其效率可能比一般的native代码低些,但是其安全性与规范性使它大受欢迎。 此外,包含在TR1等中的C+0x将实现的新功能在开发和测试中。1.1.2 C+语言的主要特点C+语言的主要特点表现在两个方面,一是全面兼容C语言,二是支持面向对象的程序设计方法。(1) C+是一个更好的C,它保持了C语言的优点,大多数的C程序代码略作修改或不作修改就可在C+的集成环境下调试和运行。这对于继承和开发当前已在广泛的软件是非常重要的,可以节省大量的人力和物力。(2) C+是一种面向对象的程序设计语言它使得程序的各个模块的独立性更强,程序的可读性和可移植性更强,程序代码的结构更加合理,程序的扩充性更强。这对于设计、编制和调试一些大型的软件尤为重要。 (3) C+集成环境不仅支持C+程序的编译和调试,而且也支持C程序的编译和调试。通常,C+程序环境约定:当源程序文件的扩展名为c时,则为C程序;而当源程序文件的扩展名为cpp时,则为C+程序。(4) C+语句非常简练,对语法限制比较宽松,因此C+语法非常灵活。其优点是给用户编程带来书写上的方便。其缺点是由于编译时对语法限制比较宽松,许多逻辑上的错误不容易发现,给用户编程增加了难度。1.2 “21点游戏”介绍1.2.1 游戏起源又名黑杰克,起源于法国,现已流传到世界各地。现在在世界各地的赌场中都可以看到二十一点,随着互联网的发展,二十一点开始走向网络时代,比如菲律宾的博彩公司就有该游戏。该游戏由 2 到 6 个人玩,使用除大小王之外的52 张牌,游戏者的目标是使手中的牌的点数之和不超过 21 点且尽量大。 有着悠久的历史。1700年左右法国赌场就有这种21点的纸牌游戏。1931年,当美国内华达州宣布赌博为合法活动时,21点游戏第一次公开出现在内华达州的赌场俱乐部,15年内,它取代掷骰子游戏,而一举成为非常流行的赌场庄家参与的赌博游戏。1.2.2 本课程设计本次课程设计是模拟古老的 21 点扑克牌游戏,实现一对一的人机大战。要求游戏过程中任意一方牌的点数之和超过 21 点,则自动出局;在不超过 21 点的情况下, 玩家下注由电脑随机发牌与庄家比累积牌的点数的大小,大者为赢家。第二章 设计要求编写程序实现游戏,该程序是模拟古老的“21点纸牌游戏”,实现一对一的人机大战。要求游戏过程中任意一方牌的点数之和超过 21 点,则自动出局;在不超过 21 点的情况下, 玩家下注由电脑随机发牌与庄家比累积牌的点数的大小,大者为赢家。1.1 问题描述 本次C+课程设计题目是“21点纸牌游戏”,系统的主要功能是娱乐游戏,有电脑和玩家一起玩这个游戏,玩家设法使自己的牌达到总分21并要比电脑开的点数大而且不超过这个数值。扑克牌的分值取它们的面值。J,Q,K分别是11,12和13分。1.2 要求分析编写程序实现游戏,该程序是模拟古老的“21点纸牌游戏”,实现1对1的人机大战。要求游戏过程中任意一方牌的点数之和超过21点,则自动出局;在不超过21点的情况下,玩家下注由电脑随机发牌与庄家比累积牌的点数的大小,大者为赢家。第三章 总体设计3.1 功能分析3.1.1 程序的主要功能描述该程序主要是模拟古老的“21点纸牌游戏”,但简易为人机大战。玩家与庄家比牌的累积点数的大小,不超过21点的情况下大者为赢家。3.1.2 总体结构游戏界面输入下注金额选择是否要牌 开始游戏退出图3-1 总体结构3.2 详细设计3.2.1序流程图主函数流程图开始键盘输入赌注产生随机数开始游戏键盘输入输出结果循环结束图3-2 流程图第四章 功能测试4.1 主界面本游戏的主界面游戏主界面介绍了本游戏的规则,还有提示玩家下注的提示图4-14.2 功能测试4.2.1输入赌注用户可根据系统提示输入赌金图4-24.2.2 电脑随机发牌图4-34.2.3 用户决定是否要牌图4-44.2.4 报错界面图4-54.2.5 开牌显示游戏结果图4-64.2.6 退出游戏继续游戏按Y,退出游戏按N图4-7第五章 源程序#include#include#include using namespace std;int x=1;int rand(int n ); /声明bool win(); /定义变量win为逻辑型变量void money(); /运行赌注 int main() coutt欢迎进入21点nn;couttt 游戏规则:n; coutendl;couttt 1.玩家最多可下赌注1100;n;coutendl;couttt 2.如果牌点数的总数超过21点则暴点,自动判数;n;coutendl;couttt 3.计算机方在大于等于16点时不再要牌。n;coutendl;coutt祝您好运n; money(); return 0; /死循环int rand(int n ) /调用函数 return rand()%n; /产生随机数,对生成的随机数取余 void money() int a=400,b=400,c;/定义玩家和庄家的赌注各400 for(;) /控制游戏循环 cout请输入您要押的钱数(现在您还有ac; /玩家所压赌注 if(c100|c1)cout请最多输入1-100请重新输入c; else if(win() a+=c;b-=c;/控制赌注 cout您现在的钱数为a; coutn对手还有b; if(a=800|b=0) cout对手已经没钱了。您赢了游戏结束了endl; exit(0); else coutn请继续下注endl; else a-=c;b+=c;/控制赌注 cout您现在的钱数为a; coutn对手还有b; if(a=800) cout您已经没钱在玩了。游戏结束了endl; exit(0); else coutn请继续下注endl; bool win()bool zhen=true; bool jia=false; int n,r,b,z; char d; int num_i; /庄家的牌 int num_r; /玩家的牌 srand(time(NULL); /调用随机函数NULL空函数 r=rand(13)+1; /取一个数字 int i; i=rand(13)+1; cout您的牌是rendl; a:cout对手的牌是iendl; /a是标记 cout您是否再要一张牌?endl; cout要请输入1,开牌请输入2c; while(x) if(c=1) n=rand(13)+1; coutn您又要到一张n; r+=n; num_r+=1; coutnn您现在总点数为r21)cout牌点数过了21n;goto b;/跳到标记b goto a; /跳到标记a break; else if(c=2) x=0; coutn轮到电脑叫牌endl; coutn现在电脑的牌是i; while(i=18&ir) cout现在电脑在要一张牌endl; b=rand(13)+1; coutn电脑又要到一张b; i+=b; num_i+=1; coutn电脑的点数是i; coutn好了现在开牌; elsecoutc; if(ir&inum_r)/比较对手大小 b:cout这回合电脑赢了nnendl;cout是否继续游戏(y/n)nnd;if (d=n)cout游戏结束endl;exit(0);else return jia; else cout这回合您赢了nnendl;cout是否继续游戏(y/n)nnendl;if (d=n)cout游戏结束endl;exit(0);else return zhen;参考文献1郑莉,董渊,何江舟.C+语言程序设计.第4版.北京:清华大学出版.2010.72Stanley B.Lippman,Jose LaJoie,Barbara E.Moo.C+ Primer(中文版).第四版.北京:人民邮电出版社.20063 Walter Savitch. C+面向对象程序设计基础、数据结构与编程思想.第4版.北京:清华大学出版社.20034钱能.C+程序设计教程.第2版.北京:清华大学出版社.20055郑莉.C+语言程序设计案例教程.第1版.北京:清华大学出版社.20056韦朴,陈泰生. Visual C+通用范例开发金典.北京:电子工业出版社.20087李爱华,程磊著. 面向对象程序设计(C+语言) .北京:清华大学出版社,20108刘振安,刘燕君著. C+程序设计课程设计. 北京: 机械工业出版社,2004ag an employment tribunal clai Emloyment tribunals sort out disagreements between employers and employees. You may need to make a claim to an employment tribunal if: you dont agree with the disciplinary action your employer has taken against you your employer dismisses you and you think that you have been dismissed unfairly. For more informu, take advice from one of the organisations listed underFur ther help. Employment tribunals are less formal than some other courts, but it is still a legal process and you will need to give evidence under an oath or affirmation. Most people find making a claim to an employment tribunal challenging. If you are thinking about making a claim to an employment tribunal, you should get help straight away from one of the organisations listed underFurther help. ation about dismissal and unfair dismissal, seeDismissal. You can make a claim to an employment tribunal, even if you haventappealedagainst the disciplinary action your employer has taken against you. However, if you win your case, the tribunal may reduce any compensation awarded to you as a result of your failure to appeal. Remember that in most cases you must make an application to an employment tribunal within three months of the date when the event you are complaining about happened. If your application is received after this time limit, the tribunal will not usually accept i. If you are worried about how the time limits apply to you If you are being represented by a solicitor at the tribunal, they may ask you to sign an agreement where you pay their fee out of your compensation if you win the case. This is known as adamages-based agreement. In England and Wales, your solicitor cant charge you more than 35% of your compensationif you win the case. You are clear about the terms of the agreement. It might be best to get advice from an experienced adviser, for example, at a Citizens Advice Bureau. To find your nearest CAB, including those that give advice by e-mail, click onnearest CAB. For more information about making a claim to an employment tribunal, seeEmployment tribunals. The (lack of) air up there Watch m Cay man Islands-based Webb, the head of Fifas anti-racism taskforce, is in London for the Football Associations 150th anniversary celebrations and will attend Citys Premier League match at Chelsea on Sunday. I am going to be at the match tomorrow and I have asked to meet Ya ya Toure, he told BBC Sport. For me its about how he felt and I would like to speak to him first to find out what his experience was. Uefa hasopened disciplinary proceedings against CSKAfor the racist behaviour of their fans duringCitys 2-1 win. Michel Platini, president of European footballs governing body, has also ordered an immediate investigation into the referees actions. CSKA said they were surprised and disappointed by Toures complaint. In a statement the Russian side added: We found no racist insults from fans of CSKA. Age has reached the end of the beginning of a word. May be guilty in his seems to passing a lot of different life became the appearance of the same day; May be back in the past, to oneself the paranoid weird belief disillusionment, these days, my mind has been very messy, in my mind constantly. Always feel oneself should go to do something, or write something. Twenty years of life trajectory deeply shallow, suddenly feel something, do it.一字开头的年龄已经到了尾声。或许是愧疚于自己似乎把转瞬即逝的很多个不同的日子过成了同一天的样子;或许是追溯过去,对自己那些近乎偏执的怪异信念的醒悟,这些天以来,思绪一直很凌乱,在脑海中不断纠缠。总觉得自己似乎应该去做点什么,或者写点什么。二十年的人生轨迹深深浅浅,突然就感觉到有些事情,非做不可了。The end of our life, and can meet many things really do?而穷尽我们的一生,又能遇到多少事情是真正地非做不可? During my childhood, think lucky money and new clothes are necessary for New Year, but as the advance of the age, will be more and more found that those things are optional; Junior high school, thought to have a crush on just means that the real growth, but over the past three years later, his writing of alumni in peace, suddenly found that isnt really grow up, it seems is not so important; Then in high school, think dont want to give vent to out your inner voice can be in the high school children of the feelings in a period, but was eventually infarction when graduation party in the throat, later again stood on the pitch he has sweat profusely, looked at his thrown a basketball hoops, suddenly found himself has already cant remember his appearance. Baumgartner the disappointing news: Mission aborted. r plays an important role in this mission. Starting at the ground, conditions have to be very calm - winds less than 2 mph, with no precipitation or humidity and limited cloud cover. The balloon, with capsule attached, will move through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. It will climb higher than the tip of Mount Everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratosphere. As he crosses the boundary layer (called the tropopause),e can expect a lot of turbulence. We often close ourselves off when traumatic events happen in our lives; instead of letting the world soften us, we let it drive us deeper into ourselves. We try to deflect the hurt and pain by pretending it doesnt exist, but although we can try this all we want, in the end, we cant hide from ourselves. We need to learn to open our hearts to the potentials of life and let the world soften us.生活发生不幸时,我们常常会关上心门;世界不仅没能慰藉我们,反倒使我们更加消沉。我们假装一切仿佛都不曾发生,以此试图忘却伤痛,可就算隐藏得再好,最终也还是骗不了自己。既然如此,何不尝试打开心门,拥抱生活中的各种可能,让世界感化我们呢? Whenever we start to let our fears and seriousness get the best of us, we should take a step back and re-evaluate our behavior. The items listed below are six ways you can open your heart more fully and completely.当恐惧与焦虑来袭时,我们应该退后一步,重新反思自己的言行。下面六个方法有助于你更完满透彻地敞开心扉。Whenever a painful situation arises in your life, try to embrace it instead of running away or trying to mask the hurt. When the sadness strikes, take a deep breath and lean into it. When we run away from sadness thats unfolding in our lives, it gets stronger and more real. We take an emotion thats fleeting and make it a solid event, instead of something that passes through us.当生活中出现痛苦的事情时,别再逃跑或隐藏痛苦,试着拥抱它吧;当悲伤来袭时,试着深呼吸,然后直面它。如果我们一味逃避生活中的悲伤,悲伤只会变得更强烈更真实悲伤原本只是稍纵即逝的情绪,我们却固执地耿耿于怀By utilizing our breath we soften our experiences. If we dam them up, our lives will stagnate, but when we keep them flowing, we allow more newness and greater experiences to blossom.深呼吸能减缓我们的感受。屏住呼吸,生活停滞;呼出呼吸,更多新奇与经历又将拉开序幕。
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!