diff options
author | 2025-05-22 07:53:15 +0200 | |
---|---|---|
committer | 2025-05-22 07:53:15 +0200 | |
commit | 50bc168a8ba2a7eb341fec8f688f0c6cd1cd0acc (patch) | |
tree | ae74a7b055bba93b0d03a33aa8372ed781f2020f | |
parent | 9d25cfc7fa3a93cb4bee41a6aab9b76d86ad7298 (diff) | |
download | tris-50bc168a8ba2a7eb341fec8f688f0c6cd1cd0acc.tar.gz tris-50bc168a8ba2a7eb341fec8f688f0c6cd1cd0acc.zip |
Add logic to set the sign inside the cell
-rw-r--r-- | src/main/game/cell.c | 12 | ||||
-rw-r--r-- | src/main/game/cell.h | 3 | ||||
-rw-r--r-- | src/main/game/game.c | 12 |
3 files changed, 23 insertions, 4 deletions
diff --git a/src/main/game/cell.c b/src/main/game/cell.c index 9227da5..cb56330 100644 --- a/src/main/game/cell.c +++ b/src/main/game/cell.c @@ -71,3 +71,15 @@ cell_is_filled(Cell *cell) { if (cell == NULL) return false; return cell->filled; } + +char +cell_get_sign(Cell *cell) +{ + return cell->sign; +} + +void +cell_set_sign(Cell *cell, char sign) +{ + cell->sign = sign; +}
\ No newline at end of file diff --git a/src/main/game/cell.h b/src/main/game/cell.h index 9a0a213..e912ec0 100644 --- a/src/main/game/cell.h +++ b/src/main/game/cell.h @@ -26,11 +26,14 @@ typedef struct Cell { float left, right, top, bottom; float cx, cy; bool filled; + char sign; } Cell; Cell *cell_new(float left, float right, float top, float bottom); bool cell_within_bounds(Cell *cell, float x, float y); void cell_set_filled(Cell *cell, bool filled); bool cell_is_filled(Cell *cell); +char cell_get_sign(Cell *cell); +void cell_set_sign(Cell *cell, char sign); #endif /* __GAME_CELL_H__ */ diff --git a/src/main/game/game.c b/src/main/game/game.c index 7d756a9..b813906 100644 --- a/src/main/game/game.c +++ b/src/main/game/game.c @@ -41,14 +41,18 @@ static void game_draw_field(TrisGame *game, float box_size); static char game_next_sign(TrisGame *game); static void -draw_sign(TrisGame *game, float x, float y) +draw_sign(TrisGame *game, Cell *cell) { + float x = cell->cx; + float y = cell->cy; float l = 0.20f; + char sign = game_next_sign(game); - if (game_next_sign(game) == SIGN_CIRCLE) { + cell_set_sign(cell, sign); + if (sign == SIGN_CIRCLE) { engine_draw_circle(x, y, l, 120, 1); game->sign = SIGN_CROSS; - } else if (game_next_sign(game) == SIGN_CROSS) { + } else if (sign == SIGN_CROSS) { engine_draw_line(x - l, y + l, x + l, y - l); engine_draw_line(x + l, y + l, x - l, y - l); game->sign = SIGN_CIRCLE; @@ -66,7 +70,7 @@ loop_cells(TrisGame *game, float x, float y) do { Cell *cell = current->data; if (!cell_is_filled(cell) && cell_within_bounds(cell, x, y)) { - draw_sign(game, cell->cx, cell->cy); + draw_sign(game, cell); cell_set_filled(cell, true); } current = current->next; |