c++猜拳小游戏【开源】

本作者无聊就编了一个猜拳游戏

智能程度:相当于原始人

话不多说,上代码!

#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;
}

如果有不好玩的地方可以把建议打在评论区里

  • 5
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值