欢迎来到天天文库
浏览记录
ID:11215228
大小:41.00 KB
页数:8页
时间:2018-07-10
《c++程序设计 对抗游戏》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、C++课程设计报告对抗游戏一、实验目的:1.加深对c++程序设计的理解,了解程序设计的流程。2.增强对程序模块化思想的概念3.加深对类、构造函数,析构函数,友元函数的理解。二、实验内容:1.阅读程序设计要求和源代码,理解和分类各部分的功能。2.设计一个类内定义的函数,实现增加赌注的功能。3.设计友元函数实现比大小的功能和输出结果功能。4.写出main函数,整合各部分功能,完成程序。三、实验环境:VC++6.0四、算法或核心技术介绍:1.利用类,实现各部分的定义。2.在友元函数中利用if函数实现比
2、较大小的功能。五、附件程序代码如下:#include"iostream"#include"math.h"#include"stdlib.h"#include"ctime"usingnamespacestd;intflag;classCCard{intnCard1,nCard2;//两张牌staticintnLoop;//出牌次数,游戏结束时给出总的出牌次数intnScore;//总分intnWin,nLose;staticnDraw;//赢,输,平的次数intnBet;//赌注public:in
3、tBet;CCard();//构造函数intSetCard();//出两张牌voidShow();//显示牌点intAddBet(int);//增加赌注,失败返回0voidfriendCompare(CCard&,CCard&);//友元函数,比较牌点大小,并显示结果voidfriendShowResult(CCard&,CCard&);//友元函数,输出输赢结果及最后积分};intCCard::nDraw=0;intCCard::nLoop=0;CCard::CCard(){nScore=20
4、;Bet=nScore;nWin=0;nLose=0;nBet=0;}intCCard::SetCard(){for(inti=0;i<=100000000;i++);srand((unsigned)time(0));nCard1=(rand()%13+1);nCard2=(rand()%13+1);returnnCard1;}voidCCard::Show(){if(nCard1>1&&nCard1<=10)cout<5、nCard1=1;cout<<"A"<<"";break;}case11:{cout<<"J"<<"";break;}case12:{cout<<"Q"<<"";break;}case13:{cout<<"K"<<"";}}if(nCard2>1&&nCard2<=10)cout<6、<<"Q"<<"";break;}case13:{cout<<"K"<<"";}}cout<nScore7、8、nBet<1){return0;}return1;}voidCompare(CCard&user,CCard&computer){if((user.nCard1==user.nCard2)&&(computer.nCard1!=computer.nCard2)){user.nScore+=comput9、er.nBet;computer.nScore-=computer.nBet;user.nLoop++;computer.nLoop++;user.nWin++;computer.nLose++;user.Bet=user.nScore;computer.Bet=computer.nScore;if(computer.nScore<=0){ShowResult(user,computer);return;}cout<<"这局玩家赢了,请继续努力哦"<10、rd1!=user.nCard2)&&(computer.nCard1==computer.nCard2)){computer.nScore+=user.nBet;user.nScore-=user.nBet;user.nLoop++;computer.nLoop++;computer.nWin++;user.nLose++;user.Bet=user.nScore;computer.Bet=computer.nScore;if(user.nScore<=0){ShowResult(user,c
5、nCard1=1;cout<<"A"<<"";break;}case11:{cout<<"J"<<"";break;}case12:{cout<<"Q"<<"";break;}case13:{cout<<"K"<<"";}}if(nCard2>1&&nCard2<=10)cout<6、<<"Q"<<"";break;}case13:{cout<<"K"<<"";}}cout<nScore7、8、nBet<1){return0;}return1;}voidCompare(CCard&user,CCard&computer){if((user.nCard1==user.nCard2)&&(computer.nCard1!=computer.nCard2)){user.nScore+=comput9、er.nBet;computer.nScore-=computer.nBet;user.nLoop++;computer.nLoop++;user.nWin++;computer.nLose++;user.Bet=user.nScore;computer.Bet=computer.nScore;if(computer.nScore<=0){ShowResult(user,computer);return;}cout<<"这局玩家赢了,请继续努力哦"<10、rd1!=user.nCard2)&&(computer.nCard1==computer.nCard2)){computer.nScore+=user.nBet;user.nScore-=user.nBet;user.nLoop++;computer.nLoop++;computer.nWin++;user.nLose++;user.Bet=user.nScore;computer.Bet=computer.nScore;if(user.nScore<=0){ShowResult(user,c
6、<<"Q"<<"";break;}case13:{cout<<"K"<<"";}}cout<nScore
7、
8、nBet<1){return0;}return1;}voidCompare(CCard&user,CCard&computer){if((user.nCard1==user.nCard2)&&(computer.nCard1!=computer.nCard2)){user.nScore+=comput
9、er.nBet;computer.nScore-=computer.nBet;user.nLoop++;computer.nLoop++;user.nWin++;computer.nLose++;user.Bet=user.nScore;computer.Bet=computer.nScore;if(computer.nScore<=0){ShowResult(user,computer);return;}cout<<"这局玩家赢了,请继续努力哦"<10、rd1!=user.nCard2)&&(computer.nCard1==computer.nCard2)){computer.nScore+=user.nBet;user.nScore-=user.nBet;user.nLoop++;computer.nLoop++;computer.nWin++;user.nLose++;user.Bet=user.nScore;computer.Bet=computer.nScore;if(user.nScore<=0){ShowResult(user,c
10、rd1!=user.nCard2)&&(computer.nCard1==computer.nCard2)){computer.nScore+=user.nBet;user.nScore-=user.nBet;user.nLoop++;computer.nLoop++;computer.nWin++;user.nLose++;user.Bet=user.nScore;computer.Bet=computer.nScore;if(user.nScore<=0){ShowResult(user,c
此文档下载收益归作者所有