From df22092a336543c0f6d2c605e0aa96df7d2ccae2 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Mon, 6 Feb 2023 01:35:49 -0800 Subject: added colours. draw_board is no longer line based --- snake.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/snake.c b/snake.c index 8afd71c..9af8df7 100644 --- a/snake.c +++ b/snake.c @@ -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); } } -- cgit v1.3.1