跳到正文

个人记录

好东西

small_lemon_qwq约 3 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 3 分钟

版本

  1. v1当前

不要在意标题,因为这确实是个好东西

相信大家在写C++小游戏的时候都这样写过:

gotoxy(0,0);

color(7);

如果没有赶紧去看一下我的贪吃蛇源代码,里面有这几个函数的定义

但是这几个函数都要用到windows.h库,那么如果是Linux该怎么办呢?

于是你百度了一下,发现了这玩意儿。

于是我就用它们写了个代码

C++
namespace words{
	string Delete(string s){
		return "\033[9m"+s+"\033[0m";
	}
	string Down(string s){
		return "\033[4m"+s+"\033[0m";
	}
	string Light(string s){
		return "\033[1m"+s+"\033[0m";
	}
	string Star(string s){
		return "\033[6m"+s+"\033[0m";
	}
	string Hide(string s){
		return "\033[8m"+s+"\033[0m";
	}
	string Italic(string s){
		return "\033[3m"+s+"\033[0m";
	}
	void clear_windows(){
		cout<<"\033[2J";
	}
}
namespace mouse{
	void up(unsigned int x){
		cout<<"\033["+to_string(x)+"A\033[0m";
	}
	void down(unsigned int x){
		cout<<"\033["+to_string(x)+"B\033[0m";
	}
	void left(unsigned int x){
		cout<<"\033["+to_string(x)+"D\033[0m";
	}
	void right(unsigned int x){
		cout<<"\033["+to_string(x)+"C\033[0m";
	}
	void hide(){
		cout<<"\033[?25l";
	}
	void show(){
		cout<<"\033[?25h";
	}
	void load(){
		cout<<"\033[s";
	}
	void used_load(){
		cout<<"\033[u";
	}
	void gotoxy(int x,int y){
		cout<<"\033["+to_string(y)+";"+to_string(x)+"H";
	}
}

未完

原文