别摸我的键盘 的学生作业:
//
// Created by linux on 2025/3/11.
//
#include
#include
using namespace std;
class MiVt100 {
public:
MiVt100(int x, int y, int len) : x(x), y(y), len(len) {}
~MiVt100() = default;
MiVt100(const MiVt100 &other) {
*this = other;
}
void setPoint(int x, int y, int backVtColor, int fontVtColor) {
fprintf(stderr, "\033[%d;%dH", y, x);
fprintf(stderr, "\033[%d;%dm", backVtColor, fontVtColor);
fprintf(stderr, "*\n");
}
void show() {
showHorizontal();
showVertical();
showTiltUp();
showTiltDown();
}
void reset() {
fprintf(stderr, "\033[0m\033[?25h");
fprintf(stderr, "\033[%d;%dH", y + 10, x - 10);
}
private:
int x;
int y;
int len;
//水平
void showHorizontal() {
for (int i = 0; i < len; i++) {
//left
this->setPoint(x + i, y, 40, 30);
//right
this->setPoint(x - i, y, 40, 30);
}
}
//垂直
void showVertical() {
for (int i = 0; i < len; i++) {
//up
this->setPoint(x, y - i, 41, 31);
//down
this->setPoint(x, y + i, 41, 31);
}
}
//斜上
void showTiltUp() {
for (int i = 0; i < len; i++) {
//up
this->setPoint(x + i, y - i, 42, 32);
//down
this->setPoint(x - i, y + i, 42, 32);
}
}
//斜下
void showTiltDown() {
for (int i = 0; i < len; i++) {
//up
this->setPoint(x + i, y + i, 43, 33);
//down
this->setPoint(x - i, y - i, 43, 33);
}
}
};
int main(int argc, const char *argv[]) {
MiVt100 *mi = new MiVt100(10, 10, 5);
mi->show();
mi->reset();
return 0;
}