马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 bin554385863 于 2019-9-16 21:47 编辑
GameWnd.h#include <windows.h>
#include <cstdio>
class GameWnd
{
private:
TCHAR *Title; //窗口标题
int Fclr, Bclr; //前景色,背景色
COORD Pos;
HANDLE winHandle; //窗口句柄
public:
GameWnd(TCHAR *t = nullptr) : Title(t)
{
winHandle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTitle(Title);
}
void SetColor(int fclr, int bclr);
void SetPosition(short x, short y);
void CleanScr(short begx, short begy, int endx, int endy);
~GameWnd() {}
};
void GameWnd::SetColor(int fclr, int bclr)
{
Fclr = fclr;
Bclr = bclr;
SetConsoleTextAttribute(winHandle, Fclr + Bclr * 0x10);
}
void GameWnd::SetPosition(short x, short y)
{
Pos = {x, y};
SetConsoleCursorPosition(winHandle, Pos);
}
void GameWnd::CleanScr(short begx, short begy, int endx, int endy)
{
for (size_t i = begx; i < endx; i++)
{
for (size_t j = begy; j < endy; j++)
{
SetPosition(i, j);
printf(" ");
}
printf("\n");
}
}
---------------------------------------------------------------------------------
Game.cpp#include "GameWnd.h"
#include <iostream>
int main()
{
char t[] = "*******";
GameWnd wnd = t;
wnd.SetColor(2, 0);
wnd.SetPosition(0,0);
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 160; j++)
{
printf("*");
}
printf("\n");
}
wnd.CleanScr(3,1,157,5);
wnd.SetPosition(80, 2);
std::cout<<"八格牙路";
wnd.SetPosition(170, 8);
return 0;
}
-----------------------------------------------------------------------------------------------------------
****************************************************************************************************************************************************************
*** ***
*** 八格牙路 ***
*** .*** ****************************************************************************************************************************************************************
E:\Users\86184\Documents\Code> |