问题标题: 双人游戏

0
1
已解决
于逸杋
于逸杋
高级光能
高级光能
/*
猜对x次,对方就扣x*10滴血 
*/
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#define random(x) (rand()%x)
using namespace std;
int p1,p2,p1a,p2a,p1cnt,p2cnt;
int p1hp=100,p2hp=100;
int main(){
	cout<<"欢迎来到卡牌大作战1.0\n"<<"p1血量:"<<100<<' '<<"p2血量:"<<100<<endl;
	for(int i=1;i<=5000;i++){
		int cnt=0;
		cout<<"p1玩家猜\n";
			while(1){
			if(cnt==1){
				cout<<"猜对了,请继续猜\n";
			}
			cout<<"请输入0,1,2(否则会有BUG)\n";
			cin>>p1;
			p1a=random(2);
			if(p1==p1a){
				p1cnt++;
				cnt=1;
			}else{
				break;
			}	
		}
		p2hp-=p1cnt*10;
		p1cnt=0;
		cnt=0;
		cout<<"p2玩家猜\n";
		while(1){
			if(cnt==1){
				cout<<"猜对了,请继续猜\n";
			}
			cout<<"请输入0,1,2(否则会有BUG)\n";
			cin>>p2;
			p2a=random(2);
			if(p2==p2a){
				p2cnt++;
				cnt=1;
			}else{
				break;
			}	
		}
		p1hp-=p2cnt*10;
		if(p1hp<=0||p2hp<=0){
			cout<<"p1血量:"<<p1hp<<' '<<"p2血量:"<<p2hp<<endl;
			if(p1hp==0){
				cout<<"p2 is winner!";
			}else{
				cout<<"p1 is winner!";
			}
			cout<<endl<<"游戏结束! 制作不易点个赞吧\n";
			cout<<"制作人:于逸杋,李文耀";
			break;
		}
		cout<<"p1血量:"<<p1hp<<' '<<"p2血量:"<<p2hp<<endl;
	}
    return 0;
}

 

于逸杋在2025-09-09 20:31:08追加了内容
/*
规则:猜对x次,对方就扣x*10滴血 
*/
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#define random(x) (rand()%x)
using namespace std;
int p1,p2,p1a,p2a,p1cnt,p2cnt;
int p1hp=100,p2hp=100;
int main(){
	cout<<"欢迎来到卡牌大作战1.0\n"<<"p1血量:"<<100<<' '<<"p2血量:"<<100<<endl;
	for(int i=1;i<=5000;i++){
		int cnt=0;
		cout<<"p1玩家猜\n";
			while(1){
			if(cnt==1){
				cout<<"猜对了,请继续猜\n";
			}
			cout<<"请输入0,1,2(否则会有BUG)\n";
			cin>>p1;
			p1a=random(2);
			if(p1==p1a){
				p1cnt++;
				cnt=1;
			}else{
				cout<<"猜错了\n";
				break;
			}	
		}
		p2hp-=p1cnt*10;
		p1cnt=0;
		cnt=0;
		cout<<"p2玩家猜\n";
		while(1){
			if(cnt==1){
				cout<<"猜对了,请继续猜\n";
			}
			cout<<"请输入0,1,2(否则会有BUG)\n";
			cin>>p2;
			p2a=random(2);
			if(p2==p2a){
				p2cnt++;
				cnt=1;
			}else{
				cout<<"猜错了\n";
				break;
			}	
		}
		p1hp-=p2cnt*10;
		p2cnt=0;
		if(p1hp<=0||p2hp<=0){
			cout<<"p1血量:"<<p1hp<<' '<<"p2血量:"<<p2hp<<endl;
			if(p1hp<=0){
				cout<<"p2 is winner!";
			}else if(p2hp<=0){
				cout<<"p1 is winner!";
			}else{
				cout<<"平局";
			}
			cout<<endl<<"游戏结束! 制作不易点个赞吧\n";
			cout<<"制作人:于逸杋,李文耀";
			break;
		}
		cout<<"p1血量:"<<p1hp<<' '<<"p2血量:"<<p2hp<<endl;
	}
    return 0;
}

 


0
0
0
孟烨然
孟烨然
中级守护
中级守护

为啥p1玩家血量为-10却赢了?

我要回答