diff options
author | eug-vs <eugene@eug-vs.xyz> | 2022-04-15 14:04:03 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2022-04-15 14:04:03 +0300 |
commit | 0333b7fa851e222c4a4d183ef9ae6d6dab7559cb (patch) | |
tree | 12942f8e71351ec3e08674fc9159fa7a08d7a3f5 | |
parent | 7f0647e07b6a14e6f4a5ace6dbd4e688f424b8dd (diff) | |
download | carcassonne-engine-c-0333b7fa851e222c4a4d183ef9ae6d6dab7559cb.tar.gz |
feat: add game tileset
-rw-r--r-- | src/carcassonne.h | 27 | ||||
-rw-r--r-- | src/main.c | 10 | ||||
-rw-r--r-- | src/tile.c | 26 | ||||
-rw-r--r-- | src/tile.h | 3 |
4 files changed, 38 insertions, 28 deletions
diff --git a/src/carcassonne.h b/src/carcassonne.h index 2bb136c..63ff725 100644 --- a/src/carcassonne.h +++ b/src/carcassonne.h @@ -2,30 +2,3 @@ #include "tile.h" #include "meeple.h" #include "structure.h" - -static const Tile TILESET[19] = { - /* cities */ - { "FFFF", 'F', 0 }, - { "CFFF", 'F', 0 }, - { "FCFC", 'C', 0 }, - { "FCFC", 'F', 0 }, - { "CCFF", 'C', 0 }, - { "CCFF", 'F', 0 }, - { "CCCF", 'C', 0 }, - { "CCCC", 'C', 0 }, - - /* roads */ - { "FFFR", 'R', 0 }, - { "FRFR", 'R', 0 }, - { "FFRR", 'R', 0 }, - { "FRRR", '+', 0 }, - { "RRRR", '+', 0 }, - - /* mix */ - { "CRFR", 'R', 0 }, - { "CFRR", 'R', 0 }, - { "CRRF", 'R', 0 }, - { "CRRR", '+', 0 }, - { "CCRR", '*', 0 }, - { "CCCR", 'C', 0 }, -}; @@ -17,16 +17,19 @@ int main() { WINDOW* messages_win = create_framed_window("Log", BOARD_ROW_UNITS + 2, 80, 0, BOARD_ROW_UNITS + 3); scrollok(messages_win, 1); + Tile tileset[69]; BoardUnit board[BOARD_UNITS]; int available_meeples[PLAYERS]; int meeple_map[MAX_STRUCTURES * PLAYERS]; Tile tile; + initialize_tileset(tileset); initialize_board(board); initialize_available_meeples(available_meeples); place_tile((Tile){ "FRCR", 'R', 0 }, translate_coordinate(BOARD_WIDTH * BOARD_WIDTH / 2), board, 1); /* main loop */ + int tile_index; char input_key; for (int move = 0; ; move++) { int player = (move % PLAYERS) + 1; @@ -40,7 +43,11 @@ int main() { wrefresh(messages_win); /* tile placement */ - tile = TILESET[rand() % 19]; + while (1) { + tile_index = rand() % 69; + tile = tileset[tile_index]; + if (tile.center != USED) break; + } int position = 0; BoardUnit board_preview[BOARD_UNITS]; @@ -102,6 +109,7 @@ int main() { } else wprintw(messages_win, "Could not place meeple at %c\n", board[meeple_index].feature); } + tileset[tile_index].center = USED; wrefresh(messages_win); } @@ -39,3 +39,29 @@ void rotate_tile(Tile* tile, int increment) { } } +void initialize_tileset(Tile* tileset) { + int index = 0; + for (int i = 0; i < 4; i++) tileset[index++] = (Tile){ "FFFF", 'F', 0 }; + for (int i = 0; i < 5; i++) tileset[index++] = (Tile){ "CFFF", 'F', 0 }; + for (int i = 0; i < 1; i++) tileset[index++] = (Tile){ "FCFC", 'C', 0 }; + for (int i = 0; i < 2; i++) tileset[index++] = (Tile){ "FCFC", 'C', 1 }; + for (int i = 0; i < 3; i++) tileset[index++] = (Tile){ "CCFF", 'C', 0 }; + for (int i = 0; i < 2; i++) tileset[index++] = (Tile){ "CCFF", 'C', 1 }; + for (int i = 0; i < 2; i++) tileset[index++] = (Tile){ "CCFF", 'C', 1 }; + for (int i = 0; i < 3; i++) tileset[index++] = (Tile){ "CFCF", 'F', 0 }; + for (int i = 0; i < 2; i++) tileset[index++] = (Tile){ "CCFF", 'F', 0 }; + for (int i = 0; i < 1; i++) tileset[index++] = (Tile){ "FFRF", 'R', 0 }; + for (int i = 0; i < 1; i++) tileset[index++] = (Tile){ "FFRF", 'R', 0 }; + for (int i = 0; i < 8; i++) tileset[index++] = (Tile){ "FRFR", 'R', 0 }; + for (int i = 0; i < 9; i++) tileset[index++] = (Tile){ "FFRR", 'R', 0 }; + for (int i = 0; i < 4; i++) tileset[index++] = (Tile){ "FRRR", '+', 0 }; + for (int i = 0; i < 1; i++) tileset[index++] = (Tile){ "RRRR", '+', 0 }; + for (int i = 0; i < 4; i++) tileset[index++] = (Tile){ "CRFR", 'R', 0 }; + for (int i = 0; i < 3; i++) tileset[index++] = (Tile){ "CFRR", 'R', 0 }; + for (int i = 0; i < 3; i++) tileset[index++] = (Tile){ "CRRF", 'R', 0 }; + for (int i = 0; i < 3; i++) tileset[index++] = (Tile){ "CRRR", '+', 0 }; + for (int i = 0; i < 3; i++) tileset[index++] = (Tile){ "CCRR", 'R', 0 }; + for (int i = 0; i < 2; i++) tileset[index++] = (Tile){ "CCRR", 'R', 1 }; + for (int i = 0; i < 1; i++) tileset[index++] = (Tile){ "CCRC", 'C', 0 }; + for (int i = 0; i < 2; i++) tileset[index++] = (Tile){ "CCRC", 'C', 1 }; +} @@ -7,6 +7,9 @@ typedef struct { int shield; } Tile; +static const char USED = '!'; + +void initialize_tileset(Tile* tileset); int is_allowed_placement(Tile tile, int index, BoardUnit* board); int place_tile(Tile tile, int index, BoardUnit* board, int force); void rotate_tile(Tile* tile, int increment); |