在过去的一周里,我和一个朋友一起使用C++制作了一款Roguelike游戏,主要是为了学习这门语言。
我使用以下工具:
下面是我用于输出的相关代码。
我使用以下工具:
- pdcurses
- Windows 7
- Visual studio C++
下面是我用于输出的相关代码。
// Container of room information
struct RoomInfo
{
wchar_t * layout;
int width;
int height;
};
// The following function builds RoomInfo
RoomInfo Room::examine(IActor * examinor)
{
RoomInfo ri;
ri.width = this->width;
ri.height = this->height;
ri.layout = new wchar_t[height * width];
for(unsigned int y = 0; y < height; y++)
{
for(unsigned int x = 0; x < width; x++)
{
ri.layout[y*width + x] = L'\u263B'; // works
//ri.layout[y*width + x] = L'\u2638'; // will not work
}
}
}
// The following function outputs RoomInfo
void CursesConsole::printRoom(RoomInfo room)
{
int w = room.width;
int h = room.height;
WINDOW * mapw = newwin(h, w, 1, 0);
for(int y = 0; y < h; y++)
{
wmove(mapw, y, 0);
for(int x = 0; x < w; x++)
{
int c = y*w + x;
waddch(mapw, room.layout[c]);
}
}
wrefresh(mapw);
delwin(mapw);
}
当然,我可以使用无聊的ANSI字符。但是拥有完整的Unicode字符集来玩耍真的很棒。
简而言之:如何确保正确输出Unicode字符?
编辑:
好的,所以我发现我的编码工作正常。问题在于我需要强制终端切换到一个更丰富的Unicode字体。是否有跨平台的方法?是否有针对Windows特定的方法?