Relationship between data structures

Within the function DrawMap the MAP_BUFFER parameter is used to determine the
values written into the GUI_BUFFER local variable. Discuss briefly the relationship between these data structures by explaining how the contents of an element of the MAP_BUFFER array determines the contents of the GUI_BUFFER array.

void DrawMap(MAP_BUFFER & rMap)
{
static GUI_BUFFER rScreenBuffer = {};

// Set the ScreenBuffer characters and attributes given the ENTITY values in rMap
for (unsigned int row = 0; row < MAP_HEIGHT; row++)
{
for (unsigned int col = 0; col < MAP_WIDTH; col++)
{
ENTITY & rTile = rMap[row][col];
rScreenBuffer[row][col].Char.AsciiChar = (char)TOKEN[rTile];
switch (rTile)
{
case EMPTY:
rScreenBuffer[row][col].Attributes = 0;
break;

case WALL:
rScreenBuffer[row][col].Attributes = FOREGROUND_WHITE;
break;
};
}
}

// Copy the ScreenBuffer content to the standard output console
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if (hStdOut != INVALID_HANDLE_VALUE)
{
COORD pos = { 0, 0 };
COORD size = { MAP_WIDTH, MAP_HEIGHT };

SMALL_RECT srDrawRegion;
srDrawRegion.Left = 0;
srDrawRegion.Top = 0;
srDrawRegion.Bottom = srDrawRegion.Top + MAP_HEIGHT;
srDrawRegion.Right = srDrawRegion.Left + MAP_WIDTH;

WriteConsoleOutput(hStdOut, (CHAR_INFO *)rScreenBuffer, size, pos, &srDrawRegion);
}
}
Last edited on
This is the part you need for your discussion:
1
2
3
ENTITY & rTile = rMap[row][col];
rScreenBuffer[row][col].Char.AsciiChar = (char)TOKEN[rTile];
switch (rTile)


Any questions?
Topic archived. No new replies allowed.