diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2023-02-06 01:35:49 -0800 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2023-02-06 01:35:49 -0800 |
| commit | df22092a336543c0f6d2c605e0aa96df7d2ccae2 (patch) | |
| tree | 67ce5086ae83d0c93dda362a18cb8fb78d0b9b3d | |
| parent | e9459fc46af4f934faaee5f806df0b73bd494124 (diff) | |
added colours. draw_board is no longer line based
| -rw-r--r-- | snake.c | 17 |
1 files changed, 5 insertions, 12 deletions
@@ -171,7 +171,6 @@ void draw_board() { printf("\033[0;0H"); //iterate through and write the board for(int r = 0; r < boardSize; r++) { - char* line = calloc(boardSize * 2, sizeof(char)); for(int c = 0; c < boardSize; c++) { //determine the contents of the board position int type = 0; @@ -190,27 +189,21 @@ void draw_board() { //append the appropriate value if(type == 0) { //empty square - line[c * 2] = '`'; - line[(c * 2) + 1] = ' '; + printf("` "); } else if(type == 1) { //snake head - line[c * 2] = '@'; - line[(c * 2) + 1] = ' '; + printf("%s@ %s", GRN, COLOR_RESET); } else if(type == 2) { //snake body - line[c * 2] = '*'; - line[(c * 2) + 1] = ' '; + printf("%s* %s", GRN, COLOR_RESET); } else if(type == 3) { - //snake body - line[c * 2] = 'F'; - line[(c * 2) + 1] = ' '; + //food + printf("%sF %s", MAG, COLOR_RESET); } } - printf(line); printf("\n"); - free(line); } } |
