自编小游戏,比上篇文章的简单一些,后期将陆续推出自编的小游戏,最后整合成《1.0多功能大厅》可统一享受多款小游戏共同使用。欢迎私信或评论,提供建议、bug和不足之处。
游戏概要:可设置总数量和最大抽取数量,先抽中即赢。
注:游戏中背景色若不习惯,有更换背景色功能
代码:
#include<bits/stdc++.h>
#include <windows.h>
using namespace std;
int main(){
int xg_monum,xg_wjnum,xg_dnnum,xg_maxnum,aab;
string aaa;
system("color E1");
while(1){
aac:
cout<<"===================================================================\n\n";
cout<<" 抓小鬼 \n\n";
cout<<"===================================================================\n\n";
cout<<"===========================游戏规则================================\n\n" ;
cout<<"设置木偶的总数量和抽取木偶,其中一个为小鬼,抓到小鬼胜利\n(输入q,退出游戏; 输入b,可更换背景颜色)\n\n";
cout<<"===========================设置参数================================\n\n";
cout<<"木偶数量:";
cin>>aaa;
if(aaa=="q"){
break;
}
if(aaa=="b"){
cout<<"\n========================================================================================\n"<<endl;
cout<<"1.返回 2.灰色 3.黑白 4.黄色 5.蓝色"<<endl;
cin>>aab;
if(aab==1){
goto aac;
}
if(aab==2){
system("color F1");
}
if(aab==3){
system("color 07");
}
if(aab==4){
system("color E1");
}
if(aab==5){
system("color 97");
}
system("cls");
}
else{
stringstream ss;
ss<<aaa;
ss>>xg_monum;
while(xg_monum<=0){
if(xg_monum<=0){
cout<<"木偶数量要大于0\n"<<endl;
}
cout<<"木偶数量:";
cin>>xg_monum;
}
cout<<endl;
cout<<"每次抽取木偶的最大数量为:";
cin>>xg_maxnum;
while(xg_maxnum<=0){
if(xg_maxnum<=0){
cout<<"最大数量要大于0\n"<<endl;
}
cout<<"每次抽取木偶的最大数量为:";
cin>>xg_maxnum;
}
cout<<endl;
while(1){
cout<<"----------------------------玩家抽取-------------------------------\n" ;
cout<<"输入抽取木偶数量:";
cin>>xg_wjnum;
while(xg_wjnum>xg_maxnum||xg_wjnum<0){
if(xg_wjnum>xg_maxnum){
cout<<"超出范围!"<<endl;
cout<<"输入抽取木偶数量:";
cin>>xg_wjnum;
}
if(xg_wjnum<0){
cout<<"超出范围!"<<endl;
cout<<"输入抽取木偶数量:";
cin>>xg_wjnum;
}
}
xg_monum-=xg_wjnum;
if(xg_monum<=0){
cout<<"\n剩余木偶数量:0"<<endl;
cout<<"----------------------------对战结果-------------------------------\n\n";
cout<<"你胜利!\n";
Sleep(1800);
system("cls");
break;
}
cout<<"\n剩余木偶数量:" <<xg_monum<<endl;
cout<<"----------------------------电脑抽取-------------------------------\n\n" ;
srand(time(0));
if(xg_monum%xg_maxnum!=0){
xg_dnnum=rand()%xg_maxnum+1;
xg_monum-=xg_dnnum;
cout<<"电脑抽取木偶数量:"<<xg_dnnum;
cout<<endl;
if(xg_monum<=0){
cout<<"\n剩余木偶数量:0"<<endl;
cout<<"----------------------------对战结果-------------------------------\n\n";
cout<<"电脑胜利!\n";
Sleep(1800);
system("cls");
break;
}
cout<<"\n剩余木偶数量:" <<xg_monum<<endl;
}
if(xg_monum%xg_maxnum==0){
xg_dnnum=xg_maxnum;
xg_monum-=xg_dnnum;
cout<<"电脑抽取木偶数量:"<<xg_dnnum;
cout<<endl;
if(xg_monum<=0){
cout<<"\n剩余木偶数量:0"<<endl;
cout<<"----------------------------对战结果-------------------------------\n\n";
cout<<"电脑胜利!\n";
Sleep(1800);
system("cls");
break;
}
cout<<"\n剩余木偶数量:" <<xg_monum<<endl;
}
}
}
}
return 0;
}
无数的未知包围着我们,才使人生保留迸发的乐趣。 6gn.