Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions include/color_handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef COLOR_HANDLER_H_
#define COLOR_HANDLER_H_

#include <string_view>

#include "curses.h"

namespace roadrun {
const int kColorRed = COLOR_RED;
const int kColorGreen = COLOR_GREEN;
const int kColorYellow = COLOR_YELLOW;
const int kColorBlue = COLOR_BLUE;
const int kColorMagenta = COLOR_MAGENTA;
const int kColorCyan = COLOR_CYAN;
const int kColorWhite = COLOR_WHITE;
class ColorHandler {
public:
static void InitializeColorPairs();
static void PrintColor(WINDOW* window, int y, int x, const char* str,
int color_pair, ...);
static void PrintRed(WINDOW* window, int y, int x, const char* str, ...);
static void PrintGreen(WINDOW* window, int y, int x, const char* str, ...);
static void PrintYellow(WINDOW* window, int y, int x, const char* str, ...);
static void PrintBlue(WINDOW* window, int y, int x, const char* str, ...);
static void PrintMagenta(WINDOW* window, int y, int x, const char* str, ...);
static void PrintCyan(WINDOW* window, int y, int x, const char* str, ...);
static void PrintWhite(WINDOW* window, int y, int x, const char* str, ...);
};
} // namespace roadrun

#endif
47 changes: 47 additions & 0 deletions src/color_handler.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "color_handler.h"

namespace roadrun {
void ColorHandler::InitializeColorPairs() {
init_pair(kColorRed, COLOR_RED, COLOR_BLACK);
init_pair(kColorGreen, COLOR_GREEN, COLOR_BLACK);
init_pair(kColorYellow, COLOR_YELLOW, COLOR_BLACK);
init_pair(kColorBlue, COLOR_BLUE, COLOR_BLACK);
init_pair(kColorMagenta, COLOR_MAGENTA, COLOR_BLACK);
init_pair(kColorCyan, COLOR_CYAN, COLOR_BLACK);
init_pair(kColorWhite, COLOR_WHITE, COLOR_BLACK);
}
void ColorHandler::PrintColor(WINDOW* window, int y, int x, const char* str,
int color_pair, ...) {
attron(COLOR_PAIR(color_pair));
mvwprintw(window, y, x, str);
attroff(COLOR_PAIR(color_pair));
}
void ColorHandler::PrintRed(WINDOW* window, int y, int x, const char* str,
...) {
PrintColor(window, y, x, str, kColorRed);
}
void ColorHandler::PrintGreen(WINDOW* window, int y, int x, const char* str,
...) {
PrintColor(window, y, x, str, kColorGreen);
}
void ColorHandler::PrintYellow(WINDOW* window, int y, int x, const char* str,
...) {
PrintColor(window, y, x, str, kColorYellow);
}
void ColorHandler::PrintBlue(WINDOW* window, int y, int x, const char* str,
...) {
PrintColor(window, y, x, str, kColorBlue);
}
void ColorHandler::PrintMagenta(WINDOW* window, int y, int x, const char* str,
...) {
PrintColor(window, y, x, str, kColorMagenta);
}
void ColorHandler::PrintCyan(WINDOW* window, int y, int x, const char* str,
...) {
PrintColor(window, y, x, str, kColorCyan);
}
void ColorHandler::PrintWhite(WINDOW* window, int y, int x, const char* str,
...) {
PrintColor(window, y, x, str, kColorWhite);
}
} // namespace roadrun
2 changes: 2 additions & 0 deletions src/game_environment.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "game_environment.h"
#include "color_handler.h"

namespace roadrun
{
Expand All @@ -20,6 +21,7 @@ namespace roadrun

int GameEnvironment::PlayGame()
{
ColorHandler::InitializeColorPairs();
while(1)
{
main_menu->PrintMenu();
Expand Down
9 changes: 5 additions & 4 deletions src/main_menu.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "main_menu.h"
#include "color_handler.h"

using namespace std;

Expand All @@ -21,10 +22,10 @@ namespace roadrun
wattron(menu_win, A_REVERSE);
mvwprintw(menu_win, y, x, "%s", MenuItemToString(choices, menu_item_list[i]));
wattroff(menu_win, A_REVERSE);
}
else
{
mvwprintw(menu_win, y, x, "%s", MenuItemToString(choices, menu_item_list[i]));
} else {
ColorHandler::PrintGreen(menu_win, y, x, "%s",
MenuItemToString(choices, menu_item_list[i]));
// mvwprintw(menu_win, y, x, "%s", MenuItemToString(choices, menu_item_list[i]));
}
++y;
}
Expand Down