跳到正文

休闲·娱乐

图画版,但是cpp

derekyang326约 7 分钟
原文
文章信息与版本

文章信息

发布
2026年4月3日
收录
2026年4月19日
更新
2026年11月20日
篇幅
约 7 分钟

版本

  1. v2当前
  2. v1

膜拜胎神和z_z_b_。

按左键作画,空格擦掉(会比较闪,谁知道怎么解决可以私信我),1-9,a-e(或A-E)改变画笔颜色。

注意: 初始化(按键)之后若调整终端大小可能会导致地图清空,影响体验。

C++
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
#define color(a) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a)
typedef BOOL (WINAPI *PROCSETCONSOLEFONT)(HANDLE, DWORD);
PROCSETCONSOLEFONT SetConsoleFont;//给鼠标用
void Print(int a){HMODULE hKernel32 = GetModuleHandle("kernel32");SetConsoleFont = (PROCSETCONSOLEFONT)GetProcAddress(hKernel32,"SetConsoleFont");SetConsoleFont(GetStdHandle(STD_OUTPUT_HANDLE),a);}
int to_int(float a) {if(a>0) return int(a+0.5);else if(a<0) return int(-a-0.5);if(a==0) return 0;}
//绝对值四舍五入
float Sin(int a) {return sin(3.1416*a/180);}
float Cos(int a) {return cos(3.1416*a/180);}
//多少度。例:Sin(30)=0.5
float SinP(int a) {return sin(3.1416*a);}
float CosP(int a) {return cos(3.1416*a);}
//多少pai。例:SinP(1)=0
void move_print(int x,int y){
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD coordScreen = { short(y), short(x) };//这行指令就是反的
    SetConsoleCursorPosition(hConsole, coordScreen);
}
void noedit()//windows.h,同样后文有。 关闭鼠标“选中”
{
	HANDLE hStdin=GetStdHandle(STD_INPUT_HANDLE);
	DWORD mode;
	GetConsoleMode(hStdin,&mode);
	mode&=~ENABLE_QUICK_EDIT_MODE;
	mode&=~ENABLE_INSERT_MODE;
	mode&=~ENABLE_MOUSE_INPUT;
	SetConsoleMode(hStdin,mode);
}
POINT Windowpos(){//鼠标位置
    POINT pt;
    GetCursorPos(&pt);
    HWND h=GetForegroundWindow();
    ScreenToClient(h,&pt);
    pt.x/=8;pt.y/=16;
    swap(pt.x,pt.y);
    return pt;
}
void HideCursor(){
	CONSOLE_CURSOR_INFO cur={1,0};
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cur);
}
void ShowCursor(){
	CONSOLE_CURSOR_INFO cur={1,1};
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cur);
}
int maxx=62,maxy=235;
int main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//	system("mode con cols=240 lines=80");
	Print(2);//字体缩小(好像没用)
	noedit();
	srand(time(NULL));
//	int x=rand()%10,y=rand()%10;
//	move_print(x,y);cout<<'o';
	system("pause");
	HideCursor();
	system("cls");
	bool flag=0;int lstx,lsty;//lst:上一次“擦除”位置
	int lstmousex,lstmousey;
	int a=7;//颜色
	while(1)
		{
			char c=0;
			HideCursor();
		    POINT pt=Windowpos();int mouse;
			mouse=GetAsyncKeyState(VK_LBUTTON)&0x8000;
			pt.x=max(0,(int)pt.x);pt.y=max(0,(int)pt.y);
			pt.x=min((int)pt.x,maxx);pt.y=min((int)pt.y,maxy);
			if(mouse){
//				if(abs(pt.x-x)<=1&&abs(pt.y-y)<=1){//pt.x于x差1倍好像
////								cout<<pt.x<<" "<<pt.y<<endl;
//					move_print(x,y);cout<<' ';
//					x=rand()%10,y=rand()%10;
//					move_print(x,y);cout<<'o';
//				}
				color(a*16);
				move_print(pt.x,pt.y);printf(" ");
				color(7);
			}
			if(flag/*&&(lstmousex!=pt.x||lstmousey!=pt.y)*/){
				move_print(lstx-1,lsty-1);printf("   ");
				move_print(lstx,lsty-1);printf("   ");
				move_print(lstx+1,lsty-1);printf("   ");
				flag=0;
			}
			if(kbhit()){
				c=_getch();
				if(c==' '){
					color(119);
					pt.x=max(1,(int)pt.x);pt.y=max(1,(int)pt.y);
					pt.x=min((int)pt.x,maxx-1);pt.y=min((int)pt.y,maxy-1);
					move_print(pt.x-1,pt.y-1);printf("   ");
					move_print(pt.x,pt.y-1);printf("   ");
					move_print(pt.x+1,pt.y-1);printf("   ");
					lstx=pt.x,lsty=pt.y;
					flag=1;
					color(7);
				}else if((c>='1'&&c<='9')||(c>='a'&&c<='e')||(c>='A'&&c<='E')){
					if(c>='1'&&c<='9')a=c-'0';
					else if(c>='a'&&c<='e')
						a=10+c-'a';
					else if(c>='A'&&c<='E'){
						a=10+c-'A';
					}
				}
			}
			Sleep(10);
//			if(c!=' '){

				lstmousex=pt.x;
				lstmousey=pt.y;
//			}
//			Sleep(10);
		}
    return 0;
}
原文