字符跑酷又更了!

​
#include<bits/stdc++.h>
#include<stdlib.h>
#include<time.h>
#include<windows.h>
#include<conio.h>
#include<windows.h>
#define K_D(VK_NONAME) ((GetAsyncKeyState(VK_NONAME))?1:0)
#define SY system
#define FUNNN GetForegroundWindow()
#define HandLe GetStdHandle(STD_OUTPUT_HANDLE)
#ifdef FUNNN
#define Mess(Title,Text,MB) MessageBox(FUNNN,Text,Title,MB)
#else
#define FUNNN GetForegroundWindow()
#define Mess(Title,Text,MB) MessageBox(FUNNN,Text,Title,MB)
#endif
#define cls system("cls")
#define P system("pause")
#define SetWindow(a,b) system("mode con cols=a lines=b")
#include<wincon.h>
#include<time.h>
using namespace std;
void color(int fc,int bc){
	WORD wcolor=((bc&0x0f)<<4)+(fc&0x0f);
	SetConsoleTextAttribute(HandLe,wcolor);
}
void hide(){
	 HANDLE h_GAME =GetStdHandle(STD_OUTPUT_HANDLE);
	 CONSOLE_CURSOR_INFO cursor_info;
	 GetConsoleCursorInfo(h_GAME,&cursor_info);
	 cursor_info.bVisible=false;
	 SetConsoleCursorInfo(h_GAME,&cursor_info);
}
void show(){
	 HANDLE h_GAME =GetStdHandle(STD_OUTPUT_HANDLE);
	 CONSOLE_CURSOR_INFO cursor_info;
	 GetConsoleCursorInfo(h_GAME,&cursor_info);
	 cursor_info.bVisible=true;
	 SetConsoleCursorInfo(h_GAME,&cursor_info);
}
void Clear_Screen() {    
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD coordScreen = {0, 0};
    SetConsoleCursorPosition(hConsole, coordScreen);
}
 
void color(int m) {
	HANDLE consolehend;
	consolehend = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(consolehend, m);
}
 
int find(){
	int sore_time;
	freopen("sore.txt","r",stdin);     //打开text.txt,并设置为输出
	cin>>sore_time;                      //将a输出到text.txt
	fclose(stdout);
	return sore_time;
}
void stay(int t,int maxn){
	freopen("sore.txt","w",stdout);
	if(maxn<t){
	   cout<<t<<endl;
    }                      //将a输出到text.txt
	fclose(stdout);
}
string a[9] = {
	"########################################################################################################################################", 
	"#                                        W                           ################   #   ######  #   # #    #                   #  E#",
	"#       W        W##            *        W######  W#     #        *   ###M#      ###  #   # ##    W*  # # #    #  ################ # W#M",
	"#   W   W   W    W M          #####      W    M   W     #M      W####     # ####  ## ######    ###W## # #       #     #     # #  # # W#M",
	"#   W###M###W      M         #### #         # M       M##M      W## # ###   ####     ####M########W## #   #      ##W  # ### #   #  # W#M",
	"#   W       W    # M   M    ##### #      #  M M   #M##M  M      W## #    ## ####M##### ###  ## ###W##   # #    *   W  #   #   #    # W#M",
	"#            ###   M # M   ###### #    # M  M M  ##M  M  M      W## # ##       #######   #   #    W## # # #   M#M  W  ### M###M###M# W#M",
	"####MMMMMMMMMMMMMMMMMMMMM######## ###MMMMMMMMMMMMMMMMMMMMM###MM#### #   ######         #   #   ###### #   #  #M M###  #              W#M",
	"###########################################################################################################MMMMMMMMMMM##################"
};

class monster {
	public:
		bool direc = 0;
		int Mx = 6;
		int My = 5;
		void move() {
			if (a[Mx + 1][My] != '#' && Mx + 1 < 8) {
				Mx++;
			}
			if (direc == 0) {
				if (a[Mx][My + 1] == '#') {
					int t = Mx;
					for (int i = t; i >= t - 3; i--) {
						if (a[i][My] == '#') {
							break;
						}
						Mx--;
					}
				}
				My = My + 1;
			} else {
				if (a[Mx][My - 1] == '#') {
					int t = Mx;
					for (int i = t; i >= t - 3; i--) {
						if (a[i][My] == '#') {
							break;
						}
						Mx--;
					}
				}
				My = My - 1;
			}
			if ((My == 98 && direc == 0) || (My == 1 && direc == 1)) {
				direc = !direc;
			} 
		}
};
 
int Bx = 6;
int By = 1;
int x = 6;
int y = 1;
bool flag = 0;
bool costume = 0;
monster Mons;
 
void check() {
	if (a[x][y] == 'M') {
		x = Bx;
		y = By;
	}
	if (a[x][y] == '*') {
		Bx = x;
		By = y;
	}
	if (a[x][y] == 'W') {
		costume = 1;
	} else {
		costume = 0;
	}
	if (a[x][y] == 'E') {
		flag = 1;
	}
}
 
int main(){
	int T=clock(),ms1,ms2;
	SY("mode con cols=200 lines=200");
	hide();
	while (1) {
		Sleep(50);
		Mons.move();
		if (a[x + 1][y] != '#' && a[x + 1][y] != 'W' && x + 1 < 9) {
			x++;
			check();
		}
		if (x == Mons.Mx - 1 || x == Mons.Mx || x == Mons.Mx + 1) {
			if (y == Mons.My - 1 || y == Mons.My || y == Mons.My + 1) {
				x = Bx;
				y = By;
			}
		}
		Clear_Screen();
		printf("   嗨~欢迎来到字符酷跑,在这里,I是你,#是墙,M是岩浆,碰到了就会死了,W是水,可以游上去,*是存档点  \n");
		printf("                          E就是终点,还有,↑往上跳,←向左走,→向右走,加油~                          \n");
		for (int i = 0; i < 9; i++) {
			int len = a[i].size();
			for (int j = 0; j < len; j++) {
				if (i == x && j == y) {
					if (costume == 0) {
						color(6);
						printf("I");
					} else {
						color(1);
						printf("U");
					}
					continue;
				} 
				if (i == Mons.Mx && j == Mons.My) {
					color(6);
					printf("?");
					continue;
				}
				switch (a[i][j]) {
					case '*':
						color(2);
						printf("%c", a[i][j]);
						break;
					case 'M':
						color(4);
						printf("%c", a[i][j]);
						break;
					case 'W':
						color(9);
						printf("%c", a[i][j]);
						break;
					case 'E':
						color(14);
						printf("%c", a[i][j]);
						break;
					default:
						color(0xF);
						printf("%c", a[i][j]);
						break;
				}
			}
			printf("\n");
		}
		if (flag) {
			break;
		}
		color(0xF);
		if (GetKeyState(VK_LEFT) < 0 && a[x][y - 1] != '#') {
			y--;
		}
		if (GetKeyState(VK_RIGHT) < 0 && a[x][y + 1] != '#') {
			y++; 
			check();
		}
		if (GetKeyState(VK_UP) < 0 && (a[x - 1][y] == 'W' || a[x + 1][y] == 'W')) {
			costume = 1;
			x--;
		} else if (GetKeyState(VK_UP) < 0 && a[x + 1][y] == '#') {
			costume = 0;
			int t = x;
			for (int i = t; i >= t - 4; i--) {
				if (a[i][y] == '#') {
					break;
				}
				x--;
				check();
			}
		}
		if (GetKeyState(VK_DOWN) < 0 && (a[x - 1][y] == 'W' || a[x + 1][y] == 'W') && a[x + 1][y] != '#') {
			x++;
			costume = 1;
			check();
		}
	}
	system("cls");
	show();
	T=clock(); 
	T/=10;
	Mess("GameOver!","YouWin!",MB_OK);
 	ms1=T%10;
  	T/=10;
  	ms2=T%10;
  	T/=10;
	cout<<"用时"<<T<<"."<<ms2<<ms1<<"秒";
	int temp=find();
	remove("sore.txt"); 
	stay(T,temp);
	return 0;
}
/*"####MMMMMMMMMMMMMMMMMMMMM##   #   ###MMMMMMMMMMMMMMMMMMMMM###MM#### #   ######         #   #   ###### #   #  #M M###  #              W# M",
	"###########    ## *         # # # #######WWWWWWWW###################################### ###################MMMMMMMMMMM################# #",
	"#E #######  ##     ##########   #                 ################################## #   ##### #    ###   ####   #   #   #  #      #   W#",
	"##W    ##  ####### ##   ##################M     # #################################M   #  ###    ##     #      #   #   #      #  #   ##W#",
	"##W### #  ########    #   ##   #   #   # #     M# ################################## ####       ############## ##### ##### #### #######W#",
	"##W###   #   ###### #   # ## # # # # # # #  M   #                  *                 ######### ############   WWWWWWW                ##W#",
	"##W######  # WWWWW  ##### ##   #   # #   # M    # # ################################ #   #   # * #   #  WW                            #W#",
	"##W   ##       #          ## # # #   # # #     M#   ################################   # # # # # # # # ##                WW     W     #W#",
	"##W##    #M#M#M#MM##MMMM#    #   # # # #        #################################### ###   #   #   #   ##             #               *W#",
	"##########################################MMMMMM####################################M####################MMMM#MMM#MMMMMMMMMMM#MMMMM######", 
*/

​

更新了分数存档保存与计时(虽然time.h的clock函数不太准)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值