Game Temp
查看原帖
Game Temp
515532
InfiniteUniverse楼主2021/8/1 16:17

直接上代码

#include <bits/stdc++.h>
#include <windows.h>
#define left ((GetAsyncKeyState(VK_LEFT) & 0x8000) ? 1 : 0)
#define right ((GetAsyncKeyState(VK_RIGHT) & 0x8000) ? 1 : 0)
#define up ((GetAsyncKeyState(VK_UP) & 0x8000) ? 1 : 0)
#define down ((GetAsyncKeyState(VK_DOWN) & 0x8000) ? 1 : 0)
#define esc ((GetAsyncKeyState(VK_ESCAPE) & 0x8000) ? 1 : 0)
using namespace std;

string ship = "▲■▼";

void color(int a) {
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), a);
	return;
}

void Pos(int x, int y) {
	COORD pos;
	pos.X = x;
	pos.Y = y / 2;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
	return;
}

void put(string s, int a, int x, int y) {
	color(a);
	for (int i = 0; i < s.size(); i++) {
		Pos(x, y);
		cout << s[i];
		y++;
	}
	return;
}

void r(int x, int y, int k) {
	Pos(x, y);
	for (int i = 0; i <= k; i++)
		printf("  ");
	put(ship, 8, k, y);
	return;
}

//void l(int x, int y, int k, int d) {
//	Pos(x, y);
//	printf("  ");
//	Pos(x, y + 1);
//	printf("  ");
//	Pos(x, y + 2);
//	printf("  ");
//	put(ship, 8, x--, y);
////	Pos(x, y);
////	for (int i = 0; i <= k < d ? k - d + 80 : k - d; i++)
////		printf("  ");
////	printf("* ");
//	return;
//}

void d(int x, int &y) {
	for (int i = 0; i <= y; i++) {
		Pos(x, i);
		printf("  ");
	}
	put(ship, 8, x, y++);
	return;
}

void u(int x, int &y) {
	Pos(x, y + 1);
	printf("  ");
	Pos(x, y + 2);
	printf("  ");
	Pos(x, y--);
	put(ship, 8, x, y);
	Pos(x, y + 7);
	printf("  ");
	return;
}

int main() {
	int x = 0, y = 0, k = 0, t = 0;
	put(ship, 8, x, y);
	color(12);
	Pos(x, y);
	Pos(x, y);
	while (1) {
		if (right) {
			r(x, y, k);
			k++;
			y += k / 80;
			k %= 80;
			int s;
			Sleep(100);
			for (int i = 1; i <= 5000; i++)
				for (int j = 1; j <= 50000; j++)
					s++;
		}
//		if (left) {
//			l(x, y, k, t);
//			t++;
//			x--;
//			int s;
//			Sleep(100);
//			for (int i = 1; i <= 5000; i++)
//				for (int j = 1; j <= 50000; j++)
//					s++;
//		}
		if (up) {
			x = k;
			u(x, y);
			int s;
			Sleep(100);
			for (int i = 1; i <= 5000; i++)
				for (int j = 1; j <= 50000; j++)
					s++;
			x = 0;
		}
		if (down) {
			x = k;
			d(x, y);
			int s;
			Sleep(100);
			for (int i = 1; i <= 5000; i++)
				for (int j = 1; j <= 50000; j++)
					s++;
			x = 0;
		}
		if (esc) {
			color(2);
			return 0;
		}
	}
	return 0;
}
以此犒劳击败新手村BOSS的勇士们
2021/8/1 16:17
加载中...