Created
January 25, 2021 23:22
-
-
Save JeffM2501/c93be76fa10d28b34e8307c87cdea576 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 | |
size_t bufferSize = nScreenWidth * nScreenHeight + 1; | |
auto *screen = new char[bufferSize]; | |
memset(screen, 0, sizeof(char) * bufferSize); | |
screen[(nScreenWidth * nScreenHeight)] = '\0'; | |
for(int i = 0; i < bufferSize -1 ; i++) | |
screen[i] = ' '; | |
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