summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2023-02-06 01:35:49 -0800
committerKai Stevenson <kai@kaistevenson.com>2023-02-06 01:35:49 -0800
commitdf22092a336543c0f6d2c605e0aa96df7d2ccae2 (patch)
tree67ce5086ae83d0c93dda362a18cb8fb78d0b9b3d
parente9459fc46af4f934faaee5f806df0b73bd494124 (diff)
added colours. draw_board is no longer line based
-rw-r--r--snake.c17
1 files 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);
}
}