




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
年4月19日C课程设计福彩游戏文档仅供参考#include<stdlib.h>#include<time.h>#include<stdio.h>#include<cmath>#include<iomanip.h>#include<iostream.h>#include<string.h>#include<conio.h>#include"windows.h"#pragmacomment(lib,"winmm.lib")intisMatch(inttest,intcp_num[]); //是否数字匹配voidCenter_Text(charShellText[80]){//将文本居中显示 intlength; intcenter; length=strlen(ShellText); center=(80-length)/2; for(;center!=0;center--) { _cputs(""); } _cputs(ShellText); cout<<endl;}voidwait(intmilli){ clock_tstart; start=clock(); while((clock()-start)<milli);}voidmenu() //菜单{MessageBox(NULL,"欢迎进入福彩游戏","欢迎",0); cout<<"\n\n\n\n"; Center_Text("警告"); cout<<endl<<endl; Center_Text("本计算机程序受版权法和国际条约保护");cout<<endl;Center_Text("如未经授权而擅自复制、传播、修改本程序(或者其中任何部分)");cout<<endl; Center_Text("将受到严厉的刑事及民事制裁,并在法律允许的范围内受到最大可能的起诉"); cout<<endl; cout<<"Yogurt"<<endl; cout<<"版权所有"<<endl; cout<<"10月"<<endl;cout<<endl; cout<<"3"; wait(1000); cout.flush(); cout<<"\b\b\b"; inti; for(i=2;i>0;i--) { cout<<i; wait(1000); cout.flush(); cout<<'\b'; } wait(1000); cout.flush(); system("cls"); cout<<"\n\n\n\n"; Center_Text("健康游戏忠告"); cout<<endl; cout<<endl; Center_Text("抵制不良游戏,拒绝盗版游戏"); cout<<endl; Center_Text("注意自我保护,谨防受骗上当"); cout<<endl; Center_Text("适度游戏益脑,沉迷游戏伤身"); cout<<endl; Center_Text("合理安排时间,享受健康生活"); cout<<endl; cout<<"\n\n"; for(intj=0;j<5;j++) { for(i=0;i<39;i++) { switch(j) { case0: cout<<"**"; break; case1: cout<<"\b.\b\b"; break; case2:cout<<".."; break; case3: cout<<"\b/\b\b"; break; case4: cout<<"//"; break; } wait(25); cout.flush(); } } system("cls"); cout<<"\n\n\n"; Center_Text("课程题目:福彩游戏"); cout<<endl; Center_Text("学号姓名:陆雅婷"); Center_Text("指导老师:张宏"); cout<<endl; Center_Text("难度等级:A"); cout<<"\n\n\n"; cout.flush(); system("pause"); system("cls");}classCWelfareLot;classCCustomer//定义用户类{private: intnMoney;//用户彩金 intnRank; //中奖等级charname[20]; //用户姓名 charYon[5];//存放用户输入的yes或nopublic: intWelfare[6]; //福彩投注号码 CCustomer(intm1=0,intm2=100) //构造函数,并将中奖等级初始化为0,彩金初始化为100元 { nRank=m1; nMoney=m2; } voidinputname() //输入玩家姓名 { cout<<"请键入用户名[1to20characters]:"; cin.getline(name,20); } char*printname() { returnname; } intSetWelfare() //接受福彩投注,成功返回1 { intn; cout<<"您现在有100元,请输入所投注数(每注2元):"; cin>>n; if(nMoney<(2*n)){ cout<<"您当前只剩"<<nMoney<<"元"<<""<<"请重新投注:"; cin>>n; } nMoney-=2*n; intj; for(j=0;j<5;j++) //输入5个所选号码 { cout<<"EnterBall#"<<j+1<<":"; while(!(cin>>Welfare[j])) //在输入的同时对输入的类型及大小做限定 { cin.clear(); while(!(cin.get()!='\n')) continue; cout<<"对不起输入错误,请输入1~48之间的整数\n"; } if((Welfare[j]<1)) { cout<<"对不起输入错误,请输入1~48之间的整数\n"; j--; } if((Welfare[j]>48)) { cout<<"对不起输入错误,请输入1~48之间的整数\n"; j--; } } return1; } voidCompare(CWelfareLot&); //比较福彩,赋值中奖等级voidshow() //根据中奖等级计算奖金,输出结果 { switch(nRank) { case1: cout<<"恭喜"<<name<<"!您获得一等奖!!"<<endl; MessageBox(NULL,"恭喜您获得一等奖!","恭喜中奖",0); cout<<"现在你有"<<nMoney<<"元!";break; case2: cout<<"恭喜"<<name<<"!您获得二等奖!!"<<endl; MessageBox(NULL,"恭喜您获得二等奖!","恭喜中奖",0); cout<<"现在你有"<<nMoney<<"元!";break; case3: cout<<"恭喜"<<name<<"!您获得三等奖!!"<<endl; MessageBox(NULL,"恭喜您获得三等奖!","恭喜中奖",0); cout<<"现在你有"<<nMoney<<"元!";break; case4: cout<<"恭喜"<<name<<"!您获得四等奖!!"<<endl; MessageBox(NULL,"恭喜您获得四等奖!","恭喜中奖",0); cout<<"现在你有"<<nMoney<<"元!";break; case5: cout<<"恭喜"<<name<<"!您获得五等奖!!"<<endl; MessageBox(NULL,"恭喜您获得五等奖!","恭喜中奖",0); cout<<"现在你有"<<nMoney<<"元!";break; case6: cout<<"恭喜"<<name<<"!您获得六等奖!!"<<endl; MessageBox(NULL,"恭喜您获得六等奖!","恭喜中奖",0); cout<<"现在你有"<<nMoney<<"元!";break; default: cout<<"对不起"<<name<<",您未获奖!"<<endl; MessageBox(NULL,"对不起,您未中奖!","提示",0); cout<<"现在你有"<<nMoney<<"元!"<<endl; } cout<<"\n*****************************************************************\n"; } voidjudge() //判断用户彩金数目 {if(nMoney<0||nMoney==0) { cout<<"对不起,您没钱了!"<<endl;cout<<name<<","<<"您想再次获得100元吗![yorn]"<<endl; cin>>Yon; if(strcmp(Yon,"y")||strcmp(Yon,"Y")) { nMoney+=100; cout<<"现在您拥有"<<nMoney<<"!"<<endl; cout<<"请继续!"<<endl; } else cout<<"谢谢!"<<endl; } } voidPlayer();//判断是否为超级玩家 voidSuperPlayer();};classCWelfareLot //定义福彩类{private:intLotNum[6]; //大奖号码public: CWelfareLot(){} //构造函数 voidSetLot(); //开奖过程 voidPrintLot() //输出大奖号码 { cout<<"中奖号码为:"<<LotNum[0]<<""<<LotNum[1]<<""<<LotNum[2]<<""<<LotNum[3]<<""<<LotNum[4]<<""<<"PB"<<""<<LotNum[5]<<"\n"; cout<<"\n"; } friendclassCCustomer; //判断用户是否中奖};voidCWelfareLot::SetLot() //改进的开奖过程{ intnRnd,nNum; for(inti=0;i<6;i++) //要开出6个数字 { nRnd=rand(); //随机取循环次数,数字变换的时间是随机的 for(intj=0;j<nRnd;j++) { nNum=rand()%48+1; //随机取1到48之间的数字进行变换 if(nNum<10) cout<<nNum<<'\b'; /*当取的数字小于1,即一位数,显示后光标左移一位,再继续变换数字将原数字覆盖,出现摇奖效果*/ else cout<<nNum<<'\b'<<'\b'; //当取出的数字为两位数,左移两位 } cout<<nNum<<""; LotNum[i]=nNum; //变换到最后的数字即为大奖数字 }}voidCCustomer::Compare(CWelfareLot&u){ inttruematch[6]; inttotal=0;truematch[0]=isMatch(Welfare[0],u.LotNum);//判断玩家输入数字是否与计算机产生的是否匹配truematch[1]=isMatch(Welfare[1],u.LotNum);truematch[2]=isMatch(Welfare[2],u.LotNum);truematch[3]=isMatch(Welfare[3],u.LotNum);truematch[4]=isMatch(Welfare[4],u.LotNum);truematch[5]=isMatch(Welfare[5],u.LotNum); //输出最终结果 u.PrintLot(); //输出计算机的号码cout<<name<<",您投注的号码为:"<<Welfare[0]<<" "<<Welfare[1]<<" "<<Welfare[2]<<" "<<Welfare[3]<<" "<<Welfare[4]<<" "<<"PB"<<" "<<Welfare[5]<<"\n"; cout<<"\n"; //显示比较结果 cout<<name<<",您匹配的号码数:"<<truematch[0]<<" "<<truematch[1]<<" "<<truematch[2]<<" "<<truematch[3]<<" "<<truematch[4]<<" "<<"PB"<<" "<<truematch[5]<<"\n";cout<<"\n"; total=(truematch[0]+truematch[1]+truematch[2]+truematch[3]+truematch[4]+truematch[5]); //将对应数字正确的数目相加 cout<<"\nTotalMatches:"<<total<<"\n\n"; //显示有几个数字相等 if(total==6) //如果6个数字相等赢得大奖,并其它中奖奖励 { nRank=1;nMoney+=50; } else if(total==5) { nRank=2;nMoney+=30; } else if(total==4) { nRank=3;nMoney+=20; } else if(total==3||truematch[5]==1) { nRank=4;nMoney+=15; } else if(total==2||truematch[5]==1) { nRank=5;nMoney+=10; } else if(total==2) { nRank=6;nMoney+=5; } else nRank=0; show();}voidCCustomer::Player(){ CCustomeruser; intn; cout<<"1.普通玩家"<<endl; cout<<"2.超级玩家"<<endl; cout<<"请选择:"<<endl; cin>>n; if(n==1){ user.inputname(); cin.getline(name,20); cout<<name<<"欢迎您!"<<endl;CWelfareLotu2; charReply2; intPowerBall,play=1; srand((unsigned)time(NULL)); do { cout<<"\n"<<name<<",请输入您投注的1~48球号.\n"; cout<<"\n"; cout<<name<<",请输入最终的能量球号:"; cin>>PowerBall; while(!(PowerBall<=48&&PowerBall>=1)) { cout<<"对不起输入错误,请输入1~48之间的整数!\n"; cout<<name<<",请再次输入您的能量球号:"; cin>>PowerBall; } user.Welfare[5]=PowerBall; user.SetWelfare(); cout<<"\n"; u2.SetLot(); cout<<"\n****************************************************************"; cout<<"\nPlay#"<<play; cout<<"\n****************************************************************\n"; cout<<"\n"; user.Compare(u2); user.judge(); cout<<name<<",您想再玩一次吗?[yorn]"<<endl; cin>>Reply2; play+=1; }while(Reply2=='Y'||Reply2=='y');cout<<"\n感谢您的参与"<<name<<"!:-)"<<endl; exit(0);} else{ if(n==2) CCustomer::SuperPlayer(); else{ cout<<"输入错误,请重新输入"<<endl; MessageBox(NULL,"输入错误,请重新输入","提示",0); CCustomer::Player(); } }}voidCCustomer::SuperPlayer(){ CWelfareLotu2; CCustomeruser; charReply2; intPowerBall,play=1; cout<<"请输入用户名:"; user.inputname(); cin.getline(name,20); user.printname(); charcode[25]; cout<<"请输入密码:"; cout.flush(); charct=getch(); inti; for(i=0;ct!=13;i++) { if(ct!=8) { if(i<20) { code[i]=ct; cout<<"*"; } else i--; } elseif(i==0) i--; else { cout<<"\b\b"; i-=2; } cout.flush(); ct=getch(); } if((i==3)&&(code[0]=='1')&&(code[1]=='2')&&(code[2]=='3')) { cout<<endl<<"密码正确,欢迎您,超级玩家!"<<endl; MessageBox(NULL,"密码正确,欢迎您,超级玩家!","超级玩家",0); do { system("cls"); intc; cout<<"您现在有100元,请输入所投注数(每注2元):"; cin>>c; if(nMoney<(2*c)){ cout<<"您当前只剩"<<nMoney<<"元"<<""<<"请重新投注:"; cin>>c; } nMoney-=2*c; cout<<"\n"<<name<<",请输入您投注的1~48球号.\n"; cout<<"\n"; cout<<name<<",请输入最终的能量球号:"; cin>>PowerBall; while(!(PowerBall<=48&&PowerBall>=1)) { cout<<"对不起输入错误,请输入1~48之间的整数!\n"; cout<<name<<",请再次输入您的能量球号:"; cin>>PowerBall; } Welfare[5]=PowerBall; cout<<"\n"; intj; for(j=0;j<5;j++) //输入5个所选号码 { cout<<"EnterBall#"<<j+1<<":"; while(!(cin>>Welfare[j])) //在输入的同时对输入的类型及大小做限定 { cin.clear(); while(!(cin.get()!='\n')) continue; cout<<"对不起输入错误,请输入1~48之间的整数\n"; } if((Welfare[j]<1)) { cout<<"对不起输入错误,请输入1~48之间的整数\n"; j--; } if((Welfare[j]>48)) { cout<<"对不起输入错误,请输入1~48之间的整数\n"; j--; } } cout<<"您投注的号码为:"<<Welfare[0]<<""<<Welfare[1]<<""<<Welfare[2]<<""<<Welfare[3]<<""<<Welfare[4]<<""<<Welfare[5]
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 湖北鄂州市2024-2025学年普通高中毕业班质量检查语文试题含解析
- 山东省利津县联考2025届初三下学期九月份统一联考语文试题含解析
- 西安音乐学院《地球物理测井与生产测井》2023-2024学年第一学期期末试卷
- 厦门海洋职业技术学院《医药英文文献阅读与论文撰写》2023-2024学年第二学期期末试卷
- 淮北师范大学《影视动画灯光设计》2023-2024学年第一学期期末试卷
- 江西省赣州市大余县2025届初三下学期期末质量抽测生物试题含解析
- 环境污染治理与大数据应用考核试卷
- 卫生服务机构财务管理的考核试卷
- 碳排放减少与绿色生活方式考核试卷
- 果蔬销售终端服务技巧与礼仪考核试卷
- 2023年河南建筑职业技术学院单招综合素质考试笔试题库及答案解析
- 模具保养记录表
- 高考化学专题复习:探究“暖宝宝”的主要成分及发热原理
- 2022《义务教育数学课程标准(2022年版)》解读课件
- 小学生理财小知识主题班会精编ppt
- DBJ∕T 15-104-2015 预拌砂浆混凝土及制品企业试验室管理规范
- 互联网开放平台解决方案
- 腺样体肥大诊疗与腺样体切除术(概述、临床表现与危害、诊断、治疗及腺样体切除术)
- 贾宝玉形象分析PPT课件(PPT 30页)
- 建筑工程质量通病课件
- 阿坝州果蔬产业发展现状及展望
评论
0/150
提交评论