diff options
| author | Christian Krinitsin <mail@krinitsin.com> | 2025-03-26 20:47:12 +0100 |
|---|---|---|
| committer | Christian Krinitsin <mail@krinitsin.com> | 2025-03-26 20:47:12 +0100 |
| commit | 32a24182ad8cd2fc3a9125cb8f70de3b9c22f9a4 (patch) | |
| tree | f2d3a9a1696d50ae28e88e9ba94684bf5ffee5d3 /firmware/include/game | |
| parent | 6b3fb653f8b342d8ecfc093a000e9f6fa479c644 (diff) | |
| download | tetris-console-32a24182ad8cd2fc3a9125cb8f70de3b9c22f9a4.tar.gz tetris-console-32a24182ad8cd2fc3a9125cb8f70de3b9c22f9a4.zip | |
add preliminary public apis
Diffstat (limited to 'firmware/include/game')
| -rw-r--r-- | firmware/include/game/blocks.h | 9 | ||||
| -rw-r--r-- | firmware/include/game/game_state.h | 38 |
2 files changed, 47 insertions, 0 deletions
diff --git a/firmware/include/game/blocks.h b/firmware/include/game/blocks.h new file mode 100644 index 0000000..7e9b75f --- /dev/null +++ b/firmware/include/game/blocks.h @@ -0,0 +1,9 @@ +#pragma once + +#include <stdint.h> + +namespace game { + +enum class Block : uint8_t { T, L, J, O, I, Z, S, NONE }; + +} diff --git a/firmware/include/game/game_state.h b/firmware/include/game/game_state.h new file mode 100644 index 0000000..0878545 --- /dev/null +++ b/firmware/include/game/game_state.h @@ -0,0 +1,38 @@ +#pragma once + +#include <array> +#include <stdint.h> + +#include "game/blocks.h" +#include "inputs/input.h" + +namespace game { + +constexpr uint8_t NUM_ROWS { 20 }; +constexpr uint8_t NUM_COLS { 10 }; + +class GameState { +public: + GameState(); + + void update(const inputs::Input& input); + + uint32_t get_score(); + uint8_t get_level(); + + Block get_next_block(); + + Block get_block(uint8_t row, uint8_t col); + +private: + void move_down(); + void move_right(); + void move_left(); + + void rotate_right(); + void rotate_left(); + + std::array<Block, NUM_ROWS * NUM_COLS> grid; +}; + +} |