【c++小游戏】谁与争锋1.0.0.0

代码如下:

#include"bits/stdc++.h" //Devc++的,vsc++没有
#include<windows.h>
#include<stdio.h>
#define kd(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
#define sys system
#define cls system("cls")
#define pause sys("pause")

#define up 72 
#define left 75 
#define right 77 
#define down 80 
using namespace std;
double juli(double x1,double y1,double x2,double y2){
	int lsbl=pow(max(x1,x2)-min(x1,x2),2)+pow(max(y1,y2)-min(y1,y2),2);
	return sqrt(lsbl);
}

void print(){
	cerr<<"1.剑士 hp:100 att:7 1技能:劈砍\n";
	cerr<<"2.咒术师 hp:75 att:10 1技能:诅咒\n";
	
}
bool youxi(){
	cls;
	int hp=1,hp2=1,att=1,att2=1,bh,bh2,i=0,le=0,le2=0;
	bool winter1=1,zhou=0;
	int x1=5,y1=5,x2=6,y2=6;
	print();
	cerr<<"玩家1:";
	in:cin>>bh;
	switch(bh){
		case 1:
			hp=100,att=7;
			break;
		case 2:
			hp=75,att=10;
			break;
		default:
			goto in;
			break;
	}
	cerr<<"玩家2:";
	in2:cin>>bh2;
	switch(bh){
		case 1:
			hp2=100,att2=7;
			break;
		case 2:
			hp2=75,att2=10;
			break;
		default:
			goto in2;
			break;
	}
	while(1){
		if(hp<=0||hp2<=0){/*胜负*/
			if(hp<=0){
				winter1=0;
			}
			break;
		}
		/*正常*/
		if(zhou){
			i++;
		}
		if(i>=5){
			if(bh==2)
				hp2-=30;
			else 
				hp-=30;
			i=0;
			zhou=0;
		}
		if(le){
			if(time(NULL)-le>=20){
				le=0;
			}
		}
		if(le2){
			if(time(NULL)-le2>=20){
				le2=0;
			}
		}
		for(int i=0;i<10;i++){
			for(int i1=0;i1<30;i1++){
				if(x1==i&&y1==i1){
					cerr<<"1";
				}else if(x2==i&&y2==i1){
					cerr<<"2";
				}else cerr<<" ";
			}
			cerr<<endl;
		}
		for(int i=0;i<30;i++){
			cerr<<"-";
		}
		cerr<<endl;
		cerr<<"玩家1:\n";
		cerr<<"hp="<<hp;
		cerr<<"\natt="<<att;
		cerr<<"\n英雄:";
		switch(bh){
			case 1:
				cerr<<"剑士\n";
				break;
			case 2:
				cerr<<"咒术师\n";
				break;
			default:
				//TODO
				break;
		}
		cerr<<"技能:";
		switch(bh){
			case 1:
				cerr<<"劈砍\n";
				break;
			case 2:
				cerr<<"诅咒\n";
				break;
			default:
				//TODO
				break;
		}
		cerr<<"玩家2:\n";
		cerr<<"hp="<<hp2;
		cerr<<"\natt="<<att2;
		cerr<<"\n英雄:";
		switch(bh2){
			case 1:
				cerr<<"剑士\n";
				break;
			case 2:
				cerr<<"咒术师\n";
				break;
			default:
				//TODO
				break;
		}
		cerr<<"技能:";
		switch(bh2){
			case 1:
				cerr<<"劈砍\n";
				break;
			case 2:
				cerr<<"诅咒\n";
				break;
			default:
				//TODO
				break;
		}
		if(le2){
			cerr<<"冷却中\n";
		}
		if(kd('W')){
			x1--;
		}
		if(kd('S')){
			x1++;
		}
		if(kd('A')){
			y1--;
		}
		if(kd('D')){
			y1++;
		}
		if(kd('1')){
			if(!le)
				switch(bh){
					case 1:
						if(juli(x1,y1,x2,y2)<=5){
							hp2-=25;
							if(juli(x1,y1,x2,y2)<=3){
								hp2-=25;
							}
						}
						le=time((NULL));
						break;
					case 2:
						zhou=1;
						le=time(NULL);
						break;
					default:
						//TODO
						break;
				}
		}
		if(kd('Q')){
			if(juli(x1,y1,x2,y2)<=5){
				hp2-=att;
			}
		}
		if(kd(VK_UP)){
			x2--;
		}
		if(kd(VK_DOWN)){
			x2++;
		}
		if(kd(VK_LEFT)){
			y2--;
		}
		if(kd(VK_RIGHT)){
			y2++;
		}
		if(kd(VK_NUMPAD1)){
			if(!le2)
				switch(bh2){
					case 1:
						if(juli(x1,y1,x2,y2)<=5){
							hp-=25;
							if(juli(x1,y1,x2,y2)<=3){
								hp-=25;
							}
						}
						le2=time((NULL));
						break;
					case 2:
						zhou=1;
						le2=time(NULL);
						break;
					default:
						//TODO
						break;
				}
		}
		if(kd(VK_NUMPAD0)){
			if(juli(x1,y1,x2,y2)<=5){
				hp-=att2;
			}
		}
		cls;
	}
	Sleep(1000);
	return winter1;
}/*1.wasd赢 0.↑↓←→赢*/
int main(){
	while(1){
		cerr<<"谁与争锋1.0.0.0版\n\n";
		cerr<<"1.开始游戏\n";
		cerr<<"2.游戏详情\n";
		cerr<<"3.作者的话\n\n";
		if(kd('1')){
			if(youxi()){
				cls;
				cerr<<"玩家1获胜!!!\n";
			}else{
				cls;
				cerr<<"玩家2获胜!!!\n";
			}
			pause;
		}
		if(kd('2')){
			cls;
			cerr<<"开始制作日期:2023.7.11\n";
			cerr<<"结束日期:2023.7.12\n";
			cerr<<"版本:1.0.0.0\n";
			cerr<<"作者:杨某一辰\n";
			pause;
			cls;
			cerr<<"玩家1:wasd移动\nq射击\n1放技能\n";
			cerr<<" 玩家2↑←↓→:移动\n数字0射击\n数字1放技能\n";
			pause;
		}
		if(kd('3')){
			cls;
			cerr<<"希望大家玩的开心!\n";
			cerr<<"作者:杨某一辰\n";
			cerr<<"1.进入作者主页 0.返回\n";
			int lsbl_kd_3;
			cin>>lsbl_kd_3;
			if(lsbl_kd_3){
				sys("start https://blog.csdn.net/langhat?type=lately");
			}
		}
		cls;
	}
}

 

玩法如下:

击杀对方,即可获胜!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值