傻瓜式控制台画图工具(C++98都能跑)
傻瓜式控制台画图工具(C++98都能跑)
#C++ #暴力美学 #优先队列
这就是2025年最硬核的控制台绘图方式
核心代码(76行):
#include <iostream>
#include <queue>
#include <vector>
#include <windows.h>
using namespace std;
int curX = 0, curY = 0;
void moveCur(int tx, int ty) {
int dx = tx - curX;
int dy = ty - curY;
if (dy > 0) {
for (int i = 0; i < dy; i++) printf("\n");
}
if (dx > 0) {
for (int i = 0; i < dx; i++) printf(" ");
}
curX = tx;
curY = ty;
}
class Cmd_Control {
private:
struct P_Node {
int x, y;
char c;
};
struct Compare {
bool operator()(const P_Node& a, const P_Node& b) {
if (a.y != b.y) return a.y > b.y;
return a.x > b.x;
}
};
priority_queue<P_Node, vector<P_Node>, Compare> print_q;
public:
void add(int x, int y, char c) {
P_Node t;
t.x = x;
t.y = y;
t.c = c;
print_q.push(t);
}
void add_string(int x, int y, string s) {
for (int i = 0; i < s.size(); i++) {
add(x + i, y, s[i]);
}
}
void print_all() {
curX = 0; curY = 0;
while (!print_q.empty()) {
P_Node p = print_q.top();
print_q.pop();
moveCur(p.x, p.y);
printf("%c", p.c);
curX++;
}
printf("\n");
}
void clear_cmd() {
system("cls");
}
void clear_q() {
while (!print_q.empty()) print_q.pop();
}
};
使用方法:
int main() {
Cmd_Control cmd;
cmd.add_string(5,5,"帅呆了!");
cmd.add(6,7,'O');
cmd.add_string(5,5,"OwO '-' 'o' ^_^ >_<");
cmd.print_all();
Sleep(1000);
cmd.clear_cmd();
return 0;
}
输出:
OwO '-' 'o' ^_^ >_<
帅呆了!
O
5秒后:
完美!
希望这篇文章对大家有帮助
Comments (1)
Please login to post comments
Login