如何用mfc编写俄罗斯方块游戏,求详细解决过程!!!

2025-04-24 23:08:21
推荐回答(2个)
回答1:

控制台只能用字符串来话,要求基础还是蛮高的,
假如要做,首先要确定游戏的架构,有主体 全局 有地图 角色 NPC个个模块都分开,就是面向对象思想,

控制台游戏重点是,要把画的东西都写入缓冲区,然后再画出,否者会闪屏

我写个重要的给你吧

这是写入缓冲数组里面
void DrawBufferString( int iX, int iY, const char* szText, int iFRColor, int iBGColor )
{
if( iX < 0 || iX >= GAME_WIDTH ||
iY < 0 || iY >= GAME_HEIGHT )
{
return;
}

int iLen = strlen( szText );

WORD clr = iFRColor|iBGColor;

int l = ( iX + iLen > GAME_WIDTH )?( GAME_WIDTH - iX ):iLen;

strncpy( &g_ScreenBuffer[iY][iX], szText, l );

for( int i = 0; i < l; i++)
{
g_ColorBuffer[iY][iX+i] = clr;
}
}
这是写出
void DrawBufferToString()
{
HANDLE hConsole = GetStdHandle( STD_OUTPUT_HANDLE );

COORD rd = ;

DWORD wd = 0;

for( int i = 0; i < GAME_HEIGHT; i++)
{
WriteConsoleOutputCharacter( hConsole, g_ScreenBuffer[i], GAME_WIDTH, rd, &wd );

rd.Y++;
}

rd.Y = 0;

for( int i = 0; i < GAME_HEIGHT; i++)
{
WriteConsoleOutputAttribute( hConsole, g_ColorBuffer[i], GAME_WIDTH, rd, &wd );

rd.Y++;
}

DeleteObject( hConsole );
}

回答2:

给力,找到答案了也请给我发一份,xuukai@163.com,谢啦