C++::1+1游戏

该篇文章介绍了使用C++编写的一个简单的控制台游戏,涉及随机数生成、用户输入处理和角色移动。玩家通过按键控制两个角色进行加法运算,当一方达到10分时获胜。
摘要由CSDN通过智能技术生成
#include <bits/stdc++.h>
#include <windows.h>
#include <fstream>
#include <conio.h>
using namespace std;
int Rand(int MIN, int MAX){
	return rand() % (MAX - MIN + 1) + MIN;
}
void f(){
	int my1=1,my2=1,he1=1,he2=1;
	while(1){
		system("cls");
		cout << he1 << "   " << he2 << "\n\n";
		cout << my1 << "   " << my2 << "\n";
		cout << "\nmyWho:";
		int g=_getch();
		cout << "\nmygoto:";
		int g1=_getch();
		if(g=='1'&&my1!=0){
			if(g1=='1'&&he1!=0){
				my1=(my1+he1)%10;
			} 
			else if(g1=='2'&&he2!=0){
				my1=(my1+he2)%10;
			}
		}
		else if(g=='2'&&my2!=0){
			if(g1=='1'&&he1!=0){
				my2=(my2+he1)%10;
			}
			else if(g1=='2'&&he2!=0){
				my2=(my2+he2)%10;
			}
		}
		if(my1==0&&my2==0){
			Sleep(1000);
			system("cls");
			cout << "Win";
			Sleep(1000);
			system("cls");
			return;
		}
		system("cls");
        cout << he1 << "   " << he2 << "\n\n";
		cout << my1 << "   " << my2 << "\n";
		cout << "\nheWho:";
		int r=Rand(1,2);
        if(r==1&&he1==0){
        	r=2;
		}
		else if(r==2&&he2==0){
			r=1;
		}
		if(he1+my1==10||he1+my2==10){
			r=1;
		}
		else if(he2+my1==10||he2+my2==10){
			r=2;
		}
		cout << r;
		Sleep(1000);
		cout << "\nhegoto:";
		int r1=Rand(1,2);
		if(r1==1&&my1==0){
			r1=2;
		}
		else if(r1==2&&my2==0){
			r1=1;
		}
		if(r==1){
			if(he1+my1==10){
				r1=1;
			}
			else if(he1+my2==10){
				r1=2;
			}
		}
		if(r==2){
			if(he2+my1==10){
				r1=1;
			}
			else if(he2+my2==10){
				r1=2;
			}
		}
		cout << r1;
		Sleep(1000);
		if(r==1){
			if(r1==1){
				he1=(he1+my1)%10;
			}
			else if(r1==2){
				he1=(he1+my2)%10;
			}
		}
		else if(r==2){
			if(r1==1){
				he2=(he2+my1)%10;
			}
			else if(r1==2){
				he2=(he2+my2)%10;
			}
		}
		if(he1==0&&he2==0){
			system("cls");
			cout << "HE  WIN";
			Sleep(1000);
			system("cls");
			return;
		}
	}
}
int main(){
	int time=0;
	ifstream AAAi;
	AAAi.open("AAA.txt");
	AAAi>>time;
	time++;
	srand(time);
    int n;
    cout << "次数:::"; 
    cin >> n;
    system("cls");
    for(int i=0;i<n;i++){
    	f();
	}
	ofstream AAA;
    AAA.open("AAA.txt");
    AAA<<time<<" ";
	return 0;
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值