#include<bits/stdc++.h>
#include<stdlib.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);
}
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<<"秒";
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######",
*/
C++字符跑酷刚更新
最新推荐文章于 2024-08-18 09:30:54 发布