本作者无聊就编了一个猜拳游戏
智能程度:相当于原始人
话不多说,上代码!
#include<iostream>
#include<fstream>
#include<windows.h>
using namespace std;
long long level=1;
string name,sname,a,win="你赢了",lose="你输了",ping="平局";
void wait(){
system("pause");
}
void clean(){
system("cls");
}
void jd(){
int b=rand()%2;
if (b==0){
sname="sb";
}
else{
sname="250";
}
cout<<"你的对手:"<<sname<<'\n';
cout<<"准备好了吗(三局两胜)"<<'\n';
wait();
clean();
int x=0,y=0;
for (int i=0;i<3;i++){
cout<<"第"<<i+1<<"局"<<'\n';
cout<<"石头:stone 剪刀:scissors 布:paper"<<'\n';
string k;
int c=rand()%3;
cin>>a;
if (c==0){
k="stone";
if (a==k){
cout<<"对手:"<<k<<'\n';
cout<<name<<":"<<a<<'\n';
cout<<ping<<'\n';
}
else if (a=="scissors"){
cout<<"对手:"<<k<<'\n';
cout<<name<<":"<<a<<'\n';
cout<<lose<<'\n';
x++;
}
else{
cout<<"对手:"<<k<<'\n';
cout<<name<<":"<<a<<'\n';
cout<<win<<'\n';
y++;
}
}
if (c==1){
k="scissors";
if (a==k){
cout<<"对手:"<<k<<'\n';
cout<<name<<":"<<a<<'\n';
cout<<ping<<'\n';
}
else if (a=="paper"){
cout<<"对手:"<<k<<'\n';
cout<<name<<":"<<a<<'\n';
cout<<lose<<'\n';
x++;
}
else{
cout<<"对手:"<<k<<'\n';
cout<<name<<":"<<a<<'\n';
cout<<win<<'\n';
y++;
}
}
if (c==2){
k="paper";
if (a==k){
cout<<"对手:"<<k<<'\n';
cout<<name<<":"<<a<<'\n';
cout<<ping<<'\n';
}
else if (a=="stone"){
cout<<"对手:"<<k<<'\n';
cout<<name<<":"<<a<<'\n';
cout<<lose<<'\n';
x++;
}
else{
cout<<"对手:"<<k<<'\n';
cout<<name<<":"<<a<<'\n';
cout<<win<<'\n';
y++;
}
}
if (x==2||y==2){
break;
}
wait();
clean();
}
if (x==y){
cout<<ping<<'\n';
}
else if (x>y){
cout<<lose<<'\n';
}
else{
cout<<win<<'\n';
level++;
}
wait();
}
void sx(){
cout<<"名字:"<<name<<'\n';
cout<<"等级:"<<level<<'\n';
wait();
clean();
}
void cd(){
ofstream outfile;
outfile.open("game.game");
outfile<<name<<' '<<level;
cout<<"存档成功"<<'\n';
wait();
clean();
}
int main(){
cout<<"要新建账号还是打开存档"<<'\n';
cout<<"1.新建账号"<<'\n';
cout<<"2.打开存档"<<'\n';
cin>>a;
if (a=="1"){
cout<<"请输入姓名";
cin>>name;
}
else{
ifstream infile;
infile.open("game.game");
infile>>name>>level;
}
clean();
while (true){
cout<<"1.对战"<<'\n';
cout<<"2.属性"<<'\n';
cout<<"3.存档"<<'\n';
cin>>a;
if (a=="1"){
jd();
}
else if (a=="2"){
sx();
}
else if (a=="3"){
cd();
}
clean();
}
return 0;
}
如果有不好玩的地方可以把建议打在评论区里