les couleurs

This commit is contained in:
2025-02-25 19:21:08 +01:00
parent 23068b8e61
commit a26d699388
8 changed files with 99 additions and 59 deletions

View File

@@ -5,9 +5,9 @@
/**
* Every possible colors a block can take
*/
enum Color {
enum ColorEnum {
NOTHING,
OUT_OF_BOUND,
OUT_OF_BOUNDS,
GARBAGE,
PURPLE,
ORANGE,
@@ -19,32 +19,30 @@ enum Color {
GREEN
};
struct Color {
std::uint8_t r;
std::uint8_t g;
std::uint8_t b;
};
/**
* Returns the first color a piece can take
*/
inline Color firstPieceColor() {
return Color(PURPLE);
inline ColorEnum firstPieceColor() {
return ColorEnum::PURPLE;
}
const Color& getColor(ColorEnum color);
/**
* Sets the color to the next available piece color
*/
inline void nextPieceColor(Color& color) {
color = (color == GREEN) ? PURPLE : Color(color + 1);
void setNextPieceColor(ColorEnum& color);
inline std::string getColorCode(const Color& color) {
return "\033[38;2;" + std::to_string(color.r) + ";" + std::to_string(color.g) + ";" + std::to_string(color.b) + "m";
}
static const std::string COLOR_RESET = "\033[38;2;255;255;255m"; // color code to reset the console color
static const std::string COLOR_CODES[] = { // color codes to change the console color
COLOR_RESET, // NOTHING
COLOR_RESET, // OUT_OF_BOUND
"\033[38;2;150;150;150m", // GARBAGE
"\033[38;2;150;0;255m", // PURPLE
"\033[38;2;255;150;0m", // ORANGE
"\033[38;2;0;255;255m", // CYAN
"\033[38;2;255;0;200m", // PINK
"\033[38;2;255;255;0m", // YELLOW
"\033[38;2;255;0;0m", // RED
"\033[38;2;0;100;255m", // BLUE
"\033[38;2;0;255;0m" // GREEN
};
inline std::string getColorCode(ColorEnum color) {
return getColorCode(color);
}