MC起床战争

1.02更新:增加弓箭、死斗模式。(提前声明:本版本超吃配置,请确保使用时电脑不烫)

代码

#include<algorithm>
#include<fstream>
#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<windows.h>
#include<conio.h>
#include <time.h>
#include <stdlib.h>
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include <windows.h>
#include <stdlib.h>
#include <time.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0) //必要的,要背下来
using namespace std;
//KEY_DOWN(MOUSE_EVENT)检测右键
//SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);颜色
//█
int vs_map[3][10];
bool bed=true,dbed=true;
int fx=1;
int hurt=1;
int HP=10;
int dHP=10;
int x,y;
int dx,dy;
int bx,by;
int dbx,dby;
int go;
int money=0;
int x_what(int x) {//取随机数
	srand((unsigned)time(NULL));
	return( rand() % x);
}
int j_out() {
	if(hurt<10) {
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY );
		cout<<"|";
	} else {
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
		cout<<"|";
	}
}
int play() {
	char c;
	if(HP<=0&&bed==true) {
		HP=10;
		x=1;
		y=0;
	}
	if(kbhit()) {
		c=getch();
		if(c=='w'&&x>0) {
			x--;
		}
		if(c=='a'&&y>0) {
			y--;
			fx=-1;
		}
		if(c=='s'&&x<2) {
			x++;
		}
		if(c=='d'&&y<9) {
			fx=1;
			y++;
		}
		if(c=='e'&&money>=20&&x==1) {
			hurt=10;
			money-=20;
		}
		if(c=='f'&&money>=10){
			money-=10;
			dHP=0;
		}
	}
	if(KEY_DOWN(MOUSE_EVENT)) {
		if(x==dx&&y==dy) {
			dHP-=hurt;
		}
		if(x==dbx&&y==dby&&dbed==true) {
			dbed=false;
			money+=20;
		}
	}
}
int AI() {
	if(go%3!=0) {
		return 0;
	}
	if(dHP<=0&&dbed==true) {
		dx=1;
		dy=9;
		dHP=10;
		money+=10;
		return 0;
	}
	if(vs_map[dx][dy-1]==1) {
		if(x_what(1)==0) {
			dx++;
		} else {
			dx--;
		}
	} else if(dx==x&&dy==y) {
		HP--;
	} else if(dx==bx&&dy==by) {
		bed=false;
	} else if(dy!=by) {
		dy--;
	} else {
		if(dx<bx) {
			dx++;
		} else {
			dx--;
		}
	}
}
int out() {
	system("cls");
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
	for(int i=0; i<HP; i++) {
		cout<<"V";
	}
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
	if(go<100){
		cout<<"战斗模式"<<endl; 
	}
	else{
		cout<<"死斗模式"<<endl; 
		bed=false;
		dbed=false;
	}
	cout<<"经验:"<<money<<endl;
	for(int i=0; i<3; i++) {
		for(int j=0; j<10; j++) {
			if(vs_map[i][j]==1) {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY  |FOREGROUND_BLUE| FOREGROUND_GREEN);
				cout<<"█";
			} else if(i==x&&j==y) {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
				cout<<"█";
			} else if(i==dx&&j==dy) {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
				cout<<"█";
			} else if(i==bx&&j==by&&bed) {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
				cout<<"█";
			} else if(i==dbx&&j==dby&&dbed) {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
				cout<<"█";
			} else if(i==x&&j==y+fx) {
				j_out();
			} else {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE|FOREGROUND_RED);
				cout<<"█";
			}
		}
		cout<<endl;
	}
	if(vs_map[x][y]==1) {
		x=1;
		y=0;
	}
	if(vs_map[dx][dy]==1) {
		dx=1;
		dy=9;
	}
}
int first() {
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
	cout<<"|----------|"<<endl;
	cout<<"|MC起床战争|"<<endl;
	cout<<"|网易花雨庭|"<<endl;
	cout<<"|按右键开始|"<<endl;
	cout<<"|----------|"<<endl;
	while(!KEY_DOWN(MOUSE_EVENT)) {

	}
	system("cls");
	bed=true;
	dbed=true;
	x=1;
	y=0;
	dbx=1;
	dby=9;
	bx=1;
	by=0;
	dx=1;
	dy=9;
	for(int i=1; i<9; i++) {
		vs_map[1][i]=1;
	}
}
int game_get_up() {
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
	cout<<"加载中"<<endl;
	for(int i=0; i<10; i++) {
		Sleep(500);
	}
	while(true) {
		out();
		play();
		AI();
		if(bed==false&&HP<=0) {
			system("cls");
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY  |FOREGROUND_BLUE| FOREGROUND_GREEN);
			cout<<"失败";
			Sleep(2000);
			return 0;
		}
		if(dbed==false&&dHP<=0) {
			system("cls");
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY  |FOREGROUND_BLUE| FOREGROUND_GREEN);
			cout<<"胜利";
			Sleep(2000);
			return 0;
		}
		go++;
	}
}
int main() {
	first();
	int n;
	while(true) {
		bed=true;
		dbed=true;
		x=1;
		y=0;
		dbx=1;
		dby=9;
		bx=1;
		by=0;
		dx=1;
		dy=9;
		for(int i=1; i<9; i++) {
			vs_map[1][i]=1;
		}
		system("cls");
		game_get_up();
		system("cls");
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
		cout<<"输入1退出,其他继续。";
		cin>>n;
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值