更改网格内的输出
Change output inside grid
我正在尝试使用以下控制台显示类来显示井字游戏 - 这是用于作业- 我得到了以下代码来使用-控制台显示一个网格,其中列标记为 0-9,并显示标记为 0-9 的行 - 控制台还在网格内显示随机字符 - 我需要将随机字符更改为我选择的字符 - 但我在代码中找不到在中间网格中设置空间的部分。
如果有人能帮助我确定代码中决定网格中显示的内容的部分,我将不胜感激。
注意 - 必须将字符集更改为(使用多字节字符集)才能看到程序的正确输出。 转换器字符集位于 Visual Studio 中的"项目属性"-"常规"-"项目默认值"下
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <tchar.h>
using std::cin;
bool setxychar( int x, int y, const char* pBuf, int len )
{
HANDLE console_handle;
COORD cursor_coord;
DWORD actual=0;
console_handle= GetStdHandle(STD_OUTPUT_HANDLE);
cursor_coord.X=x; // (40-(strlen(buffer)/2));
cursor_coord.Y=y;
//This would be the equivalent to gotoxy(x,y).
if (SetConsoleCursorPosition(console_handle,cursor_coord))
{
// Look up this function in your VC++ help/index
WriteConsole(console_handle,pBuf,len,&actual,NULL);
return true;
}
return false;
}
// setxychar() - Overloaded
// this method allows you to print a single character at a location
bool setxychar( int x, int y, char Buf )
{
return( setxychar( x, y, &Buf, 1 ) );
}
int _tmain(int argc, _TCHAR* argv[])
{
const char graybar = 'xB2';
char *buffer ="Tic Tac Toe";
int x=0, y=0;
for(x=0; x<80; x++) // vertical borders
{
y=0;
setxychar(x,y,&graybar,1);
y=23;
setxychar(x,y,&graybar,1);
}
for( y=0; y<24; y++ ) // horizontal borders
{
x=0;
setxychar(x,y,&graybar,1);
x=79;
setxychar(x,y,&graybar,1);
}
setxychar(3,3,' '); // position pointer
printf( " 0 1 2 3 4 5 6 7 8 9 A B C D E Fn" );
char testchar = 0; // A warning is put up by the compiler
for(y=4; y<20; y++ ) // "warning C4309: 'initializing' : truncation of constant value"
{ // 80 hex is the same as -128, Hex is just easier
setxychar(1,y,' '); // position pointer
printf( "%X", 16*(y-4) );
for(x=6; x<38; x+=2)
{
setxychar(x,y,&testchar,1);
testchar++;
}
}
// Putting text to screen just for fun
setxychar(52,6,buffer,(int)strlen(buffer));
setxychar(1,22,' '); // position pointer
cin.get();
return 0;
}
看起来相关部分是:
char testchar = 0;
和
setxychar(x,y,&testchar,1);
和
testchar++;
相关文章:
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 请解释"函数1(p1,p2,p3);"的输出
- C++:将控制台输出存储在宏中更好吗
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 为什么我的代码在输出中增加了93天
- 如何从void函数输出字符串
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- AES加密到解密未正确输出
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 使用C++程序合并排序没有得到正确的输出
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- C++格式化输出问题
- 将值从二维数组输出到文本文件
- 集合上的输出迭代器:assign和increment迭代器
- 在while循环中输入带有std::cin的字符串后,控制台会输出大量胡言乱语
- 阵列输出网格上的x和y轴
- 2D 数组,在网格上输出 x 和 y 轴
- 更改网格内的输出