自编小游戏,欢迎私信或评论,提供建议、bug和不足之处。
游戏概要:选择石头、剪刀、布对战
代码:
#include<bits/stdc++.h>
#include<ctime>
#include<string>
#include <windows.h>
using namespace std;
void shuju();
int fs,sj,wj,hh=1,shu=0,ying,ping,aab;
int main(){
system("color 97");
string dn;
while(1){
aac:
system("cls");
cout<<"=============================================\n\n 猜拳游戏\n\n=============================================\n\n" ;
cout<<"=============================================\n\n"<<" 第 "<<hh<<" 回合\n\n"<<"---------------------------------------------\n";
shuju();
cout<<"1.石头 2.剪刀 3.布 4.退出 5.背景\n\n你的选择:";
cin>>wj;
if(wj!=1&&wj!=2&&wj!=3&&wj!=4&&wj!=5){
cout<<"输入错误!";
break;
}
if(wj==4){
break;
}
if(wj==5){
cout<<"\n========================================================================================\n"<<endl;
cout<<"1.返回 2.灰色 3.黑白 4.黄色 5.蓝色"<<endl;
cin>>aab;
if(aab==2){
system("color F1");
}
if(aab==3){
system("color 07");
}
if(aab==4){
system("color E1");
}
if(aab==5){
system("color 97");
}
goto aac;
if(aab==1){
goto aac;
}
}
cout<<endl;
srand(time(0));
sj=rand()%3+1;
if(sj==1) {
dn="石头";
cout<<"电脑:"<<dn<<endl<<endl;
cout<<"---------------------------------------------\n\n";
}
if(sj==2){
dn="剪刀";
cout<<"电脑:"<<dn<<endl<<endl;
cout<<"---------------------------------------------\n\n";
}
if(sj==3){
dn="布";
cout<<"电脑:"<<dn<<endl<<endl;
cout<<"---------------------------------------------\n\n";
}
if(dn=="石头"&&wj==1){
cout<<"平局\n";
ping++;
}
if(dn=="石头"&&wj==2){
cout<<"你输了\n";
shu++;
}
if(dn=="石头"&&wj==3){
cout<<"你赢了\n";
ying++;
fs++;
}//
if(dn=="剪刀"&&wj==1){
cout<<"你赢了\n";
ying++;
fs++;
}
if(dn=="剪刀"&&wj==2){
cout<<"平局\n";
ping++;
}
if(dn=="剪刀"&&wj==3){
cout<<"你输了\n";
shu++;
}
if(dn=="布"&&wj==1){
cout<<"你输了\n";
shu++;
}
if(dn=="布"&&wj==2){
cout<<"你赢了\n";
ying++;
fs++;
}
if(dn=="布"&&wj==3){
cout<<"平局\n";
ping++;
}
hh++;
Sleep(1500);
}
return 0;
}
void shuju(){
cout<<setw(110)<<right<<"分数:"<<fs<<setw(118)<<right<<"胜:"<<ying<<endl<<setw(109)<<right<<"输:"<<shu<<endl<<setw(111)<<right<<"平局:"<<ping<<endl;
}
逆境是顺境的准备,顺境是逆境的铺垫。 6gn.