Created
January 25, 2021 23:22
-
-
Save JeffM2501/c626cf597abc16eaf0e5ece1d4fe9664 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void game::loop() | |
{ | |
pField = new unsigned char[nFieldWidth*nFieldHeight]; | |
for (int x =0; x < nFieldWidth; x++) | |
{ | |
for (int y = 0; y < nFieldHeight; y++) | |
{ | |
pField[y*nFieldWidth + x] = (x == 0 || x == nFieldWidth - 1 || y == nFieldHeight - 1) ? 9 : 0; | |
} | |
} | |
//Command Prompt Drawing Routine | |
HANDLE hConsole = CreateConsoleScreenBuffer( GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); | |
SetConsoleActiveScreenBuffer(hConsole); | |
DWORD dwBytesWritten = 0; | |
bool gameOver = false; | |
char icons[] = { ' ','A','B','C','D', 'E', 'F','G','=','#' }; | |
// | |
char* buffer = new char[nFieldWidth+1]; | |
buffer[nFieldWidth] = '\0'; | |
while(!gameOver) | |
{ | |
for (int y = 0; y < nFieldHeight; y++) | |
{ | |
for (int x = 0; x < nFieldWidth; x++) | |
{ | |
int val = pField[y * nFieldWidth + x]; | |
if (val < 10) | |
buffer[x] = icons[val]; | |
else | |
buffer[x] = ' '; | |
} | |
WriteConsoleOutputCharacterA(hConsole, buffer, nFieldWidth, { 2 , (short)y + 2 }, &dwBytesWritten); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment