rp-scrabble
Simple, terminal-based Scrabble game
utils.h
Go to the documentation of this file.
1 
4 #ifndef UTILS_H
5 #define UTILS_H
6 #include <iostream>
7 #include <algorithm>
8 #include <vector>
9 
10 class Tile;
11 class Square;
12 class Play;
13 
15 #define DEBUG_PRINT(x, y) std::cout << x << ":" << y << std::endl
17 #define NUM_ROWS 15
19 #define NUM_COLS 15
20 
24 const std::string alphabets = "abcdefghijklmnopqrstuvwxyz";
25 
26 /*
27  * ANSI escape codes for colour
28  *
29  * \033[38;2;<r>;<g>;<b>m #Select RGB foreground color
30  * \033[48;2;<r>;<g>;<b>m #Select RGB background color
31  *
32  * Use like this-
33  * Pinkish text on a brownish background
34  * \033[38;2;255;82;197;48;2;155;106;0mHello
35  */
36 // Start colour helper functions
37 inline void BOLD(std::string x)
38 {
39  std::cout << "\033[1m" + x + "\033[0m";
40 }
41 
42 inline void BOLD_BRIGHT_GREEN_FG(std::string x)
43 {
44  std::cout << "\033[1;38;2;0;255;19m" + x + "\033[0m";
45 }
46 
47 inline void BOLD_CYAN_FG(std::string x)
48 {
49  std::cout << "\033[1;38;2;51;177;255m" + x + "\033[0m";
50 }
51 
52 inline void BOLD_BLUE_FG(std::string x)
53 {
54  std::cout << "\033[1;38;2;0;0;255m" + x + "\033[0m";
55 }
56 
57 inline void BOLD_PINK_FG(std::string x)
58 {
59  std::cout << "\033[1;38;2;203;6;104m" + x + "\033[0m";
60 }
61 
62 inline void BOLD_ORANGE_FG(std::string x)
63 {
64  std::cout << "\033[1;38;2;248;28;28m" + x + "\033[0m";
65 }
66 
67 inline void BOLD_BROWN_FG(std::string x)
68 {
69  std::cout << "\033[1;38;2;149;0;19m" + x + "\033[0m";
70 }
71 
72 inline void BOLD_WHITE_FG(std::string x)
73 {
74  std::cout << "\033[1;38;2;255;255;255m" + x + "\033[0m";
75 }
76 
77 inline void BOLD_RED_FG(std::string x)
78 {
79  std::cout << "\033[1;38;2;255;0;0m" + x + "\033[0m";
80 }
81 
82 inline void PALE_GREEN_FG(std::string x)
83 {
84  std::cout << "\033[38;2;50;193;110m" + x + "\033[0m";
85 }
86 
87 inline void BOLD_LIGHT_GRAY_FG(std::string x)
88 {
89  std::cout << "\033[1;38;2;232;232;232m" + x + "\033[0m";
90 }
91 
92 inline void BOLD_BLACK_FG(std::string x)
93 {
94  std::cout << "\033[1;38;2;0;0;0m" + x + "\033[0m";
95 }
96 
97 inline void BROWN_BG(std::string x)
98 {
99  std::cout << "\033[48;2;104;0;13m" + x + "\033[0m";
100 }
101 
102 inline void RED_BG(std::string x)
103 {
104  std::cout << "\033[48;2;255;26;26m" + x + "\033[0m";
105 }
106 
107 inline void PINK_BG(std::string x)
108 {
109  std::cout << "\033[48;2;225;0;109m" + x + "\033[0m";
110 }
111 
112 inline void DARK_BLUE_BG(std::string x)
113 {
114  std::cout << "\033[48;2;101;11;218m" + x + "\033[0m";
115 }
116 
117 inline void LIGHT_BLUE_BG(std::string x)
118 {
119  std::cout << "\033[48;2;145;128;255m" + x + "\033[0m";
120 }
121 
122 inline void OFF_WHITE_BG(std::string x)
123 {
124  std::cout << "\033[48;2;255;198;179m" + x + "\033[0m";
125 }
126 
127 inline void TILE_COLOURS(std::string x)
128 {
129  std::cout << "\033[1;38;2;0;0;0;48;2;255;255;255m" + x + "\033[0m";
130 }
131 
132 inline void BOARD_COLOURS(std::string x)
133 {
134  std::cout << "\033[1;38;2;232;232;232;48;2;77;0;9m" + x + "\033[0m";
135 }
136 // End colour helper functions
137 
141 bool squarePresent(std::vector<Square*> s, Square* target);
142 bool tilePresent(std::vector<Tile*> t, Tile* target);
143 bool charPresent(std::string str, char target);
144 std::vector<std::string> parsePlay(std::string in);
145 void log(std::string logFilePath, std::string str);
146 std::string RawTimeToString(const time_t& t);
147 
148 #endif
Definition: play.h:23
Definition: square.h:30
Definition: tile.h:22
bool charPresent(std::string str, char target)
void PINK_BG(std::string x)
Definition: utils.h:107
void BROWN_BG(std::string x)
Definition: utils.h:97
void BOARD_COLOURS(std::string x)
Definition: utils.h:132
void PALE_GREEN_FG(std::string x)
Definition: utils.h:82
void RED_BG(std::string x)
Definition: utils.h:102
void BOLD_BRIGHT_GREEN_FG(std::string x)
Definition: utils.h:42
void DARK_BLUE_BG(std::string x)
Definition: utils.h:112
void log(std::string logFilePath, std::string str)
const std::string alphabets
Definition: utils.h:24
void BOLD_ORANGE_FG(std::string x)
Definition: utils.h:62
bool squarePresent(std::vector< Square * > s, Square *target)
Definition: utils.cc:24
void BOLD_BROWN_FG(std::string x)
Definition: utils.h:67
void BOLD_CYAN_FG(std::string x)
Definition: utils.h:47
void BOLD_RED_FG(std::string x)
Definition: utils.h:77
void BOLD_WHITE_FG(std::string x)
Definition: utils.h:72
bool tilePresent(std::vector< Tile * > t, Tile *target)
Definition: utils.cc:43
void BOLD_BLACK_FG(std::string x)
Definition: utils.h:92
void BOLD(std::string x)
Definition: utils.h:37
void BOLD_PINK_FG(std::string x)
Definition: utils.h:57
void BOLD_BLUE_FG(std::string x)
Definition: utils.h:52
void BOLD_LIGHT_GRAY_FG(std::string x)
Definition: utils.h:87
void TILE_COLOURS(std::string x)
Definition: utils.h:127
std::vector< std::string > parsePlay(std::string in)
Definition: utils.cc:78
std::string RawTimeToString(const time_t &t)
Definition: utils.cc:127
void OFF_WHITE_BG(std::string x)
Definition: utils.h:122
void LIGHT_BLUE_BG(std::string x)
Definition: utils.h:117