mis en place la PR de simon sur les couleurs

This commit is contained in:
2025-02-28 18:42:04 +01:00
parent f0f391ade6
commit 26f501f7e8
29 changed files with 713 additions and 665 deletions

View File

@@ -1,51 +1,55 @@
#pragma once
#include <String>
#include "Block.h"
#include "string"
/**
* Every possible colors a block can take
* A color encoded in RGB
*/
enum Color {
NOTHING,
OUT_OF_BOUND,
GARBAGE,
PURPLE,
ORANGE,
CYAN,
PINK,
YELLOW,
RED,
BLUE,
GREEN
struct Color {
unsigned char red; // the red component of the color
unsigned char green; // the green component of the color
unsigned char blue; // the blue component of the color
};
/**
* Returns the first color a piece can take
*/
inline Color firstPieceColor() {
return Color(PURPLE);
}
/**
* Sets the color to the next available piece color
*/
inline void nextPieceColor(Color& color) {
color = (color == GREEN) ? PURPLE : Color(color + 1);
}
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
static const Color EMPTY_BLOCK_COLOR = {255, 255, 255}; // color of an empty block
static const Color BLOCKS_COLOR[] = { // color for each block type
EMPTY_BLOCK_COLOR, // NOTHING
EMPTY_BLOCK_COLOR, // OUT_OF_BOUNDS
{150, 150, 150}, // GARBAGE
{150, 0, 255}, // PURPLE
{255, 150, 0}, // ORANGE
{0, 255, 255}, // CYAN
{255, 0, 200}, // PINK
{255, 255, 0}, // YELLOW
{255, 0, 0}, // RED
{0, 100, 255}, // BLUE
{0, 255, 0} // GREEN
};
/**
* Translates the color into a color code to change the console's color
* @return A string to print in the console
*/
inline std::string getConsoleColorCode(const Color& color) {
return "\033[38;2;" + std::to_string(color.red) + ";" + std::to_string(color.green) + ";" + std::to_string(color.blue) + "m";
}
/**
* Translates the color into a color code to change the console's color
* @return A string to print in the console
*/
inline std::string getConsoleColorCode(const Block block) {
return getConsoleColorCode(BLOCKS_COLOR[block]);
}
/**
* Gets a color code to reset the console's color
* @return A string to print in the console
*/
inline std::string getResetConsoleColorCode() {
return getConsoleColorCode(EMPTY_BLOCK_COLOR);
}