⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fight.cpp

📁 1为攻击2为反弹3为休息 攻击对方可费对方5点生命,但对方反弹,则攻击加在自己身上
💻 CPP
字号:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream.h>

int main()
{
	int sm1=100,sm2=100;

	srand(unsigned (time(NULL)));
L1:
	int a=rand();
	int aa=rand();
	int chuzhao1;

	int chuzhao2=aa*3/RAND_MAX+1;  //电脑出的招
	
	printf("1.Attack  2.Reflect  3.Sleep\n");

L2:
	printf("Enter:");
	scanf("%d",&chuzhao1); //选自己的招
	
	if (chuzhao1<1 || chuzhao1>3)
	{
		printf("Error!!\n");
		goto L2;
	}

	
	
	if (chuzhao1==1 && chuzhao2==1)
	{
		sm1-=5;
		sm2-=5;
		printf ("You attack! Computer attack!\nComputer -5! You -5!\nYou remain %d Computer remain %d\n",sm1,sm2);
	}
	if (chuzhao1==1 && chuzhao2==2)
	{
		sm1-=7;
		sm2-=2;
		printf ("You attack! Computer reflect!\nComputer -2! You -7!\nYou remain %d Computer remain %d\n",sm1,sm2);
	}
	if (chuzhao1==1 && chuzhao2==3)
	{
		sm2-=10;
		printf ("You attack! Computer sleep!\nComputer -10! You -0!\nYou remain %d Computer remain %d\n",sm1,sm2);
	}
	if (chuzhao1==2 && chuzhao2==1)
	{
		sm1-=2;
		sm2-=7;
		printf ("You reflect! Computer attack!\nComputer -7! You -2!\nYou remain %d Computer remain %d\n",sm1,sm2);
	}
	if (chuzhao1==2 && chuzhao2==2)
	{
		printf ("You reflect! Computer reflect!\nComputer -0! You -0!\nYou remain %d Computer remain %d\n",sm1,sm2);
	}
	if (chuzhao1==2 && chuzhao2==3)
	{
		sm2+=10;
		printf ("You reflect! Computer sleep!\nComputer +10! You -0!\nYou remain %d Computer remain %d\n",sm1,sm2);
	}
	if (chuzhao1==3 && chuzhao2==1)
	{
		sm1-=10;
		printf ("You sleep! Computer attack!\nComputer -0! You -10!\nYou remain %d Computer remain %d\n",sm1,sm2);
	}
	if (chuzhao1==3 && chuzhao2==2)
	{
		sm1+=10;
		printf ("You sleep! Computer reflect!\nComputer -0! You +10!\nYou remain %d Computer remain %d\n",sm1,sm2);
	}
	if (chuzhao1==3 && chuzhao2==3)
	{
		sm1+=10;
		sm2+=10;
		printf ("You sleep! Computer sleep!\nComputer +10! You +10!\nYou remain %d Computer remain %d\n",sm1,sm2);
	}
	
	
	
	
	
	if (sm1<0)
	{
		system("cls");
		printf("You have lost!");
		goto L3;
	}

	if (sm2<0)
	{
		system("cls");
		printf("You win!");
		goto L3;
	}
	
	goto L1;

L3:
	cin.get();
	
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -