24 char filenameBuffer[60];
27 strftime(filenameBuffer, 60,
"-%F-scrabble.log", localtime(&rawTime));
29 logFilePath = LOG_PATH + gameID + string(filenameBuffer);
34 gameBoard =
new Board;
38 addPlayer(
new Player(to_string(1)));
83 bool complete =
false;
86 log(logFilePath,
"Log start\n");
90 BOLD_RED_FG(
" You can set the path of the log file in CMakeLists.txt\n");
95 BOLD(
" Welcome to Scrabble!");
99 cout <<
" Name of Player " + p->getName() +
": ";
102 log(logFilePath,
"Player 1: "+ tempName);
106 BOLD_RED_FG(
" You can set the path of the log file in CMakeLists.txt\n");
110 p->setName(tempName);
113 cout <<
" Would you like to add more players? (y/n)? ";
115 if(response ==
'y') {
117 cout <<
" How many more (max 3 more)? ";
120 for(j = 0; j < i; j++) {
121 cout <<
" Name of Player " + to_string(j + 2) +
": ";
123 addPlayer(
new Player(tempName));
125 log(logFilePath,
"Player " + to_string(j + i) +
": " + tempName);
129 BOLD_RED_FG(
" You can set the path of the log file in CMakeLists.txt\n");
138 BOLD(
" You can only add upto 3 more players!\n");
146 else if(response ==
'n') {
171 for(
unsigned long j = col; j < col + tileStr.length(); j++) {
172 if(j == 7 && row == 7) {
177 else if(dir ==
'v') {
178 for(
unsigned long i = row; i < row + tileStr.length(); i++) {
179 if(i == 7 && col == 7) {
201 BOLD(
" Enter the tiles you want to place ");
202 cout <<
"(? for help, - to quit) ";
207 else if(tempIn ==
".") {
210 else if(tempIn ==
"-") {
213 else if(tempIn ==
"!") {
216 else if(tempIn ==
"#") {
220 for(
char ch : tempIn) {
222 throw(
string(
"Invalid character input\n"));
225 input.append(tempIn +
"-");
228 BOLD(
" Enter the row where the first tile will go ");
229 cout <<
"(? for help, - to quit) ";
234 else if(tempIn ==
".") {
237 else if(tempIn ==
"-") {
240 else if(tempIn ==
"!") {
243 else if(tempIn ==
"#") {
250 catch(
const invalid_argument& ia) {
251 throw(
string(
"Invalid integer input\n"));
253 input.append(tempIn +
"-");
256 BOLD(
" Enter the column where the first tile will go ");
257 cout <<
"(? for help, - to quit) ";
262 else if(tempIn ==
".") {
265 else if(tempIn ==
"-") {
268 else if(tempIn ==
"!") {
271 else if(tempIn ==
"#") {
278 catch(
const invalid_argument& ia) {
279 throw(
string(
"Invalid integer input"));
281 input.append(tempIn +
"-");
284 BOLD(
" Enter the direction of placement ");
285 cout <<
"(? for help, - to quit) ";
290 else if(tempIn ==
".") {
293 else if(tempIn ==
"-") {
296 else if(tempIn ==
"!") {
299 else if(tempIn ==
"#") {
303 if(tempIn.length() != 1 && (tempIn !=
"h" || tempIn !=
"v")) {
304 throw(
string(
"Invalid direction\n"));
306 input.append(tempIn);
319 PALE_GREEN_FG(
"\n The tiles you want to place are entered in order of placement using the respective letter\n\n");
320 PALE_GREEN_FG(
" The row and column of the square to place can be seen outside the edge of the board\n\n");
321 PALE_GREEN_FG(
" The placement direction can either be 'v' (place tiles vertically downward one after the other) or\n");
322 PALE_GREEN_FG(
" 'h' (place tiles horizontally from left to right one after the other)\n\n");
328 cout <<
"Show this help text\t";
330 cout <<
"Show the board\t";
332 cout <<
"Skip turn\n";
334 cout <<
"Show scores\t\t";
336 cout <<
"Quit the game\n\n";
338 BOLD(
" Board legend\n");
339 BOLD(
" ------------\n");
343 cout <<
" Triple Word Score\t";
347 cout <<
" Double Word Score\t";
351 cout <<
" Triple Letter Score\t";
355 cout <<
" Double Letter Score\n\n";
367 bool allEmpty =
false;
369 bool firstTurn =
true;
374 vector<string> parsed;
379 for(
Player* p : players) {
384 log(logFilePath,
"\nGame start\n");
388 BOLD_RED_FG(
" You can set the path of the log file in CMakeLists.txt\n");
395 for(
Player* currPlayer : players) {
396 if(!currPlayer->rackIsEmpty()) {
397 plays.push_back(
new Play(currPlayer));
398 Play* currPlay = plays.back();
403 currPlayer->toggleTurn();
412 BOLD(
" " + currPlayer->getName());
428 BOLD_RED_FG(
" Are you sure you want to quit? (y/n) ");
431 for(
Player* p : players) {
432 log(logFilePath, p->getName() +
": " + to_string(p->getScore()));
440 throw(
string(
"Invalid input\n"));
448 currPlayer->toggleTurn();
455 throw(
string(
"Invalid input\n"));
459 for(
Player* p : players) {
466 vector<vector<Tile*>> connnectedWords;
467 vector<Tile*> tileStrVec;
470 log(logFilePath, in);
474 BOLD_RED_FG(
" You can set the path of the log file in CMakeLists.txt\n");
482 row = stoi(parsed[1]);
483 col = stoi(parsed[2]);
485 playValid = currPlay->
validate(tileStr, gameBoard, row, col, dir);
488 if(!firstTurnCheck(tileStr, row, col, dir)) {
490 BOLD_RED_FG(
" This is the first turn of the game, please make sure the centre square is covered by your word\n");
499 tileStrVec = currPlayer->placeTileStr(tileStr, gameBoard, row, col, dir);
500 connnectedWords = currPlay->
getWords(tileStrVec, gameBoard, row, col, dir);
507 currPlayer->draw(tileStr.length(), gameBag);
508 currPlayer->toggleTurn();
512 for(
Tile* t : tileStrVec) {
513 currPlayer->returnToRack(t, gameBoard);
529 allEmpty = players.front()->rackIsEmpty();
530 for(
Player* p : players) {
531 allEmpty = allEmpty && p->rackIsEmpty();
536 BOLD(
" You have placed all tiles!!! Final scores are-\n");
537 for(
Player* p : players) {
538 log(logFilePath,
"\n");
539 log(logFilePath, p->getName() +
": " + to_string(p->getScore()) +
"\n");
540 BOLD_WHITE_FG(p->getName() +
": " + to_string(p->getScore()) +
"\n");
bool firstTurnCheck(std::string str, int r, int c, char dir)
void addPlayer(Player *p)
void calculatePoints(std::vector< std::vector< Tile * >> words, std::vector< Tile * > tileStrVec)
std::vector< std::vector< Tile * > > getWords(std::vector< Tile * > tilesInStr, Board *b, int r, int c, char dir)
bool validate(std::string tileStr, Board *b, int r, int c, char dir)
string RawTimeToString(const time_t &t)
void log(string logFilePath, string str)
std::vector< std::string > parsePlay(std::string in)
bool charPresent(string str, char ch)
void PINK_BG(std::string x)
void PALE_GREEN_FG(std::string x)
void RED_BG(std::string x)
void BOLD_BRIGHT_GREEN_FG(std::string x)
void DARK_BLUE_BG(std::string x)
const std::string alphabets
void BOLD_RED_FG(std::string x)
void BOLD_WHITE_FG(std::string x)
void LIGHT_BLUE_BG(std::string x)