|
1 | 1 | #include "../coords.hpp" |
| 2 | +#include "../input.hpp" |
2 | 3 | #include "../tui.hpp" |
3 | 4 | #include <algorithm> |
4 | 5 | #include <chrono> |
| 6 | +#include <cstddef> |
| 7 | +#include <cstdint> |
5 | 8 | #include <iostream> |
6 | | -#include <limits> |
| 9 | +// #include <limits> // needed if MAX_MS is used |
7 | 10 | #include <random> |
8 | 11 | #include <string> |
9 | 12 | #include <thread> |
10 | 13 | #include <vector> |
11 | 14 |
|
12 | | -using namespace tui::input; |
13 | | - |
14 | 15 | // this is how the apple/food will be displayed |
15 | 16 | const tui::string APPLE_TEXT = tui::string('@').red().bold(); |
16 | 17 | // where the score count will be printed |
17 | 18 | const Coord SCORE_COUNT = Coord{2, 4}; |
18 | 19 | // this is the default duration a frame lives for in ms, it's 23.8 fps |
19 | 20 | const std::chrono::milliseconds SLEEP_MS = std::chrono::milliseconds(42); |
20 | 21 | const std::chrono::milliseconds ADD_MS = std::chrono::milliseconds(1); |
21 | | -const std::chrono::milliseconds MAX_MS = std::chrono::milliseconds(std::numeric_limits<unsigned>::infinity()); |
| 22 | +// const std::chrono::milliseconds MAX_MS = std::chrono::milliseconds(std::numeric_limits<unsigned>::infinity()); |
22 | 23 | // initial size/lenght of the snake: at the game start |
23 | 24 | const unsigned INIT_LEN = 5; |
24 | 25 |
|
25 | 26 | // direction |
26 | | -enum Dir { |
| 27 | +enum class Dir : std::uint8_t { |
27 | 28 | Up = 0, |
28 | 29 | Down, |
29 | 30 | Left, |
@@ -100,16 +101,16 @@ Dir meets_at(const Coord& lhs, const Coord& rhs, const Coord& screen_size) { |
100 | 101 | // we set both row and col to x-1 as it's needed :D |
101 | 102 | auto teleport = Coord{screen_size.row - 1, screen_size.col - 1}; |
102 | 103 |
|
103 | | - if (row_diff == 1 || teleport.row == -row_diff) { |
| 104 | + if (row_diff == 1 || static_cast<int>(teleport.row) == -row_diff) { |
104 | 105 | return Dir::Up; |
105 | 106 | } |
106 | | - if (row_diff == -1 || teleport.row == row_diff) { |
| 107 | + if (row_diff == -1 || static_cast<int>(teleport.row) == row_diff) { |
107 | 108 | return Dir::Down; |
108 | 109 | } |
109 | | - if (col_diff == 1 || teleport.col == -col_diff) { |
| 110 | + if (col_diff == 1 || static_cast<int>(teleport.col) == -col_diff) { |
110 | 111 | return Dir::Left; |
111 | 112 | } |
112 | | - if (col_diff == -1 || teleport.col == col_diff) { |
| 113 | + if (col_diff == -1 || static_cast<int>(teleport.col) == col_diff) { |
113 | 114 | return Dir::Right; |
114 | 115 | } |
115 | 116 | return Dir::None; |
@@ -157,7 +158,7 @@ struct App { |
157 | 158 | static Snake default_snake() { |
158 | 159 | auto mid = Coord::screen_size() / 2; |
159 | 160 | Snake snake; |
160 | | - for (auto i = 0; i < INIT_LEN; ++i) { |
| 161 | + for (auto i = 0; i < static_cast<int>(INIT_LEN); ++i) { |
161 | 162 | snake.push_back(mid.with_col(mid.col - i)); |
162 | 163 | } |
163 | 164 | return snake; |
@@ -259,7 +260,7 @@ struct App { |
259 | 260 | // delete the last one off the screen by overwriting it with a space |
260 | 261 | this->snake.back().print(' '); |
261 | 262 | auto old_snake = this->snake; |
262 | | - for (auto i = 1; i < this->snake.size(); ++i) { |
| 263 | + for (size_t i = 1; i < this->snake.size(); ++i) { |
263 | 264 | this->snake.at(i) = old_snake.at(i - 1); |
264 | 265 | } |
265 | 266 |
|
|
0 commit comments