资源描述
#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"
#pragma comment(lib, "winmm.lib")
int isMatch(int test, int cp_num[] ); //是否数字匹配
void Center_Text(char ShellText[80]){ //将文本居中显示
int length;
int center;
length= strlen(ShellText);
center = (80 - length)/2;
for(;center!=0;center--)
{
_cputs(" ");
}
_cputs(ShellText);
cout<<endl;
}
void wait(int milli)
{
clock_t start;
start=clock();
while((clock()-start)<milli);
}
void menu() //菜单
{
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";
int i;
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(int j=0;j<5;j++)
{
for(i=0;i<39;i++)
{
switch(j)
{
case 0:
cout<<"**";
break;
case 1:
cout<<"\b.\b\b";
break;
case 2:
cout<<"..";
break;
case 3:
cout<<"\b/\b\b";
break;
case 4:
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");
}
class CWelfareLot;
class CCustomer //定义用户类
{
private:
int nMoney; //用户彩金
int nRank; //中奖等级
char name[20]; //用户姓名
char Yon[5]; //存放用户输入yes或no
public:
int Welfare[6]; //福彩投注号码
CCustomer(int m1=0,int m2=100) //结构函数,并将中奖等级初始化为0,彩金初始化为100元
{
nRank=m1;
nMoney=m2;
}
void inputname() //输入玩家姓名
{
cout<<"请键入用户名[1 to 20 characters]:";
cin.getline(name,20);
}
char* printname()
{
return name;
}
int SetWelfare() //接收福彩投注,成功返回1
{
int n;
cout<<"您现在有100元,请输入所投注数(每注2元):";
cin>>n;
if(nMoney<(2*n)){
cout<<"您现在只剩"<<nMoney<<"元"<<" "<<"请重新投注:";
cin>>n;
}
nMoney-=2*n;
int j;
for (j=0; j<5; j++) //输入5个所选号码
{
cout<<"Enter Ball # "<<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--;
}
}
return 1;
}
void Compare(CWelfareLot& ); //比较福彩,赋值中奖等级
void show() //依据中奖等级计算奖金,输出结果
{
switch(nRank)
{
case 1:
cout <<"恭喜"<<name<<"! 您取得一等奖!!"<<endl;
MessageBox(NULL,"恭喜您取得一等奖!","恭喜中奖",0);
cout<<"现在你有 "<<nMoney<<" 元!";break;
case 2:
cout <<"恭喜 "<<name<<"! 您取得二等奖!!"<<endl;
MessageBox(NULL,"恭喜您取得二等奖!","恭喜中奖",0);
cout<<"现在你有 "<<nMoney<<" 元!";break;
case 3:
cout <<"恭喜 "<<name<<"! 您取得三等奖!!"<<endl;
MessageBox(NULL,"恭喜您取得三等奖!","恭喜中奖",0);
cout<<"现在你有 "<<nMoney<<" 元!";break;
case 4:
cout <<"恭喜 "<<name<<"! 您取得四等奖!!"<<endl;
MessageBox(NULL,"恭喜您取得四等奖!","恭喜中奖",0);
cout<<"现在你有 "<<nMoney<<" 元!";break;
case 5:
cout <<"恭喜 "<<name<<"! 您取得五等奖!!"<<endl;
MessageBox(NULL,"恭喜您取得五等奖!","恭喜中奖",0);
cout<<"现在你有"<<nMoney<<"元!";break;
case 6:
cout <<"恭喜 "<<name<<"! 您取得六等奖!!"<<endl;
MessageBox(NULL,"恭喜您取得六等奖!","恭喜中奖",0);
cout<<"现在你有 "<<nMoney<<" 元!";break;
default:
cout <<"对不起 "<<name<<",您未获奖!"<<endl;
MessageBox(NULL,"对不起,您未中奖!","提醒",0);
cout<<"现在你有 "<<nMoney<<" 元!"<<endl;
}
cout<<"\n*****************************************************************\n";
}
void judge() //判定用户彩金数目
{
if(nMoney<0||nMoney==0)
{
cout<<"对不起,您没钱了!"<<endl;
cout<<name<<","<<"您想再次取得100元吗![y or n]"<<endl;
cin>>Yon;
if(strcmp(Yon,"y")||strcmp(Yon,"Y"))
{
nMoney+=100;
cout<<"现在您拥有"<<nMoney<<" !"<<endl;
cout<<"请继续!"<<endl;
}
else
cout<<"谢谢!"<<endl;
}
}
void Player();//判定是否为超级玩家
void SuperPlayer();
};
class CWelfareLot //定义福彩类
{
private:
int LotNum[6]; //大奖号码
public:
CWelfareLot(){} //结构函数
void SetLot(); //开奖过程
void PrintLot() //输出大奖号码
{
cout <<"中奖号码为: "<<LotNum[0]<<" "<<LotNum[1]<<" "<<LotNum[2]<<" "<<LotNum[3]<<" "<<LotNum[4]<<" "<< "PB"<<" "<<LotNum[5]<<"\n";
cout <<"---------------------------------------------------------------------------\n";
}
friend class CCustomer; //判定用户是否中奖
};
void CWelfareLot::SetLot() //改善开奖过程
{
int nRnd,nNum;
for(int i=0;i<6;i++) //要开出6个数字
{
nRnd=rand(); //随机取循环次数,数字变换时间是随机
for(int j=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; //变换到最终数字即为大奖数字
}
}
void CCustomer::Compare(CWelfareLot&u)
{
int truematch[6];
int total=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 <<"\nTotal Matches: "<<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();
}
void CCustomer::Player(){
CCustomer user;
int n;
cout<<"1.一般玩家"<<endl;
cout<<"2.超级玩家"<<endl;
cout<<"请选择:"<<endl;
cin>>n;
if(n==1){
user.inputname();
cin.getline(name,20);
cout<<name<<"欢迎您!"<<endl;
CWelfareLot u2;
char Reply2;
int PowerBall,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<<", 您想再玩一次吗? [y or n]"<<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();
}
}
}
void CCustomer::SuperPlayer()
{
CWelfareLot u2;
CCustomer user;
char Reply2;
int PowerBall,play=1;
cout<<"请输入用户名:";
user.inputname();
cin.getline(name,20);
user.printname();
char code[25];
cout<<"请输入密码:";
cout.flush();
char ct=getch();
int i;
for(i=0;ct!=13;i++)
{
if(ct!=8)
{
if(i<20)
{
code[i]=ct;
cout<<"*";
}
else
i--;
}
else if(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");
int c;
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";
int j;
for (j=0; j<5; j++) //输入5个所选号码
{
cout<<"Enter Ball # "<<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]<<endl;
cout<<"大奖号码为: "<<endl;
int nRnd,nNum;
for(int i=0;i<6;i++) //要开出6个数字
{
nRnd=rand(); //随机取循环次数,数字变换时间是随机
for(int j=0;j<nRnd;j++)
{
nNum=rand()%48+1; //随机取1到48之间数字进行变换
if(nNum<10)
cout<<nNum<<'\b'; /*当取数字小于1,即一位数,显示后光标左移一位,再继续变换数字将原数字覆盖,出现摇奖效果*/
else
cout<<nNum<<'\b'<<'\b'; //当取出数字为两位数,左移两位
if(j==nRnd-1)
cout<<Welfare[i]<<" ";
}
}
int money=50+nMoney;
cout<<"恭喜您中了一等奖!"<<" "<<"奖金50元!"<<endl;
MessageBox(NULL,"恭喜您中一等奖!","恭喜中奖",0);
cout<<"现在您拥有"<<money<<"元";
cout<<"您想再玩一次吗?[Y/N]"<<endl;
cin>> Reply2;
play+=1;
}
while (Reply2=='Y'||Reply2=='y');
cout<<"\n感谢您参与 "<<name<<"! :-)"<<endl;
}
else{
cout<<endl<<"1.密码错误,请重新输入"<<endl;
cout<<"2.退出"<<endl;
char n=cin.get();
switch(n){
case '1':
CCustomer::SuperPlayer();
break;
case '2':
void CCustomer::Player();
}
}
}
void main()
{
menu();
CCustomer cc;
cc.Player();
exit (0);
}
int isMatch(int test, int cp_num[] ) //数字相等,则返回1
{
int match = 0;
for (int i=0; i<=5; i++)
if (test == cp_num[i]) match = 1;
cout <<"\n";
return match;
}
展开阅读全文