extracted border characters to a config header

This commit is contained in:
2025-10-22 12:29:30 +03:00
parent 57d2aba783
commit 77f3f937bb
2 changed files with 20 additions and 8 deletions

View File

@@ -2,6 +2,7 @@
#include <stdio.h>
#include <assert.h>
#include "config.h"
#include "Board.h"
#include "Snake.h"
@@ -27,20 +28,20 @@ Board board_alloc(const int width, const int height) {
const int height_with_borders_last_i = board.height_with_borders - 1;
// Vertical bars
for (int i = 1; i < height_with_borders_last_i; i++) {
MAT_INDEX(board.squares, board.width_with_borders, i, 0) = '|';
MAT_INDEX(board.squares, board.width_with_borders, i, width_with_borders_last_i) = '|';
MAT_INDEX(board.squares, board.width_with_borders, i, 0) = CHAR_BORDER_VER;
MAT_INDEX(board.squares, board.width_with_borders, i, width_with_borders_last_i) = CHAR_BORDER_VER;
}
// Horizontal lines
for (int j = 1; j < width_with_borders_last_i; j++) {
MAT_INDEX(board.squares, board.width_with_borders, 0, j) = '-';
MAT_INDEX(board.squares, board.width_with_borders, height_with_borders_last_i, j) = '-';
MAT_INDEX(board.squares, board.width_with_borders, 0, j) = CHAR_BORDER_HOR;
MAT_INDEX(board.squares, board.width_with_borders, height_with_borders_last_i, j) = CHAR_BORDER_HOR;
}
// Corners
MAT_INDEX(board.squares, board.width_with_borders, 0, 0) = '+';
MAT_INDEX(board.squares, board.width_with_borders, height_with_borders_last_i, 0) = '+';
MAT_INDEX(board.squares, board.width_with_borders, 0, width_with_borders_last_i) = '+';
MAT_INDEX(board.squares, board.width_with_borders, height_with_borders_last_i, width_with_borders_last_i) = '+';
MAT_INDEX(board.squares, board.width_with_borders, 0, 0) = CHAR_BORDER_CORNER_TL;
MAT_INDEX(board.squares, board.width_with_borders, height_with_borders_last_i, 0) = CHAR_BORDER_CORNER_BL;
MAT_INDEX(board.squares, board.width_with_borders, 0, width_with_borders_last_i) = CHAR_BORDER_CORNER_TR;
MAT_INDEX(board.squares, board.width_with_borders, height_with_borders_last_i, width_with_borders_last_i) = CHAR_BORDER_CORNER_BR;
return board;
}

11
src/headers/config.h Normal file
View File

@@ -0,0 +1,11 @@
#ifndef CONFIG_H_
#define CONFIG_H_
#define CHAR_BORDER_VER '|'
#define CHAR_BORDER_HOR '-'
#define CHAR_BORDER_CORNER_TL '+'
#define CHAR_BORDER_CORNER_TR '+'
#define CHAR_BORDER_CORNER_BL '+'
#define CHAR_BORDER_CORNER_BR '+'
#endif // CONFIG_H_