Added color mode

This commit is contained in:
2017-11-26 01:08:42 +01:00
parent 6ca31e2bec
commit 70f7fb0a13

View File

@@ -35,7 +35,16 @@ int main(int argc, char **argv) {
/* Initialization */ /* Initialization */
initscr(); initscr();
atexit(quitProgram); atexit(quitProgram);
start_color(); //Enables multi color mode
/* Initialize custom color pairs */
/* Color pair index must be > 0 */
/* init_pair(index, foreground color, background color); */
/* Color pairs are called by attron(COLOR_PAIR(1)); */
init_pair(1, COLOR_CYAN, COLOR_BLACK); //Start screen
init_pair(2, COLOR_GREEN, COLOR_BLACK); //
init_pair(3, COLOR_RED, COLOR_BLACK); //Hitfeed
initCoordinates(&gs); initCoordinates(&gs);
gs.allowedMoves = DEFAULTTRIES; gs.allowedMoves = DEFAULTTRIES;
@@ -107,9 +116,11 @@ void quitProgram(void) {
} }
void showStartScreen(game_state *gs) { void showStartScreen(game_state *gs) {
attron(COLOR_PAIR(1));
mvprintw(gs->centery - 1, gs->centerx - 15, "Welcome to hangman in ncurses."); mvprintw(gs->centery - 1, gs->centerx - 15, "Welcome to hangman in ncurses.");
mvprintw(gs->centery, gs->centerx - 5, "Have fun!"); mvprintw(gs->centery, gs->centerx - 5, "Have fun!");
mvprintw(gs->centery + 1, gs->centerx - 17, "https://gitlab.com/STRUCTiX/hangman"); mvprintw(gs->centery + 1, gs->centerx - 17, "https://gitlab.com/STRUCTiX/hangman");
attroff(COLOR_PAIR(1));
refresh(); refresh();
getch(); getch();
clear(); clear();
@@ -439,6 +450,7 @@ void printHitFeed(game_state *gs, hitfeed *hf) {
int newMaxy = gs->maxy - HITFEEDSLOTS; int newMaxy = gs->maxy - HITFEEDSLOTS;
int newMaxx = gs->maxx - (gs->centerx / 2); int newMaxx = gs->maxx - (gs->centerx / 2);
int i, z; int i, z;
attron(COLOR_PAIR(3)); //Enable red color
for (i = -1; i < HITFEEDSLOTS; i++) { for (i = -1; i < HITFEEDSLOTS; i++) {
for (z = 0; z <= gs->maxx - newMaxx; z++) { for (z = 0; z <= gs->maxx - newMaxx; z++) {
mvprintw(newMaxy + i, newMaxx + z, " "); mvprintw(newMaxy + i, newMaxx + z, " ");
@@ -454,6 +466,7 @@ void printHitFeed(game_state *gs, hitfeed *hf) {
sprintf(message, "Best: %s (%i hits)", hf->beststreak, hf->besthit); sprintf(message, "Best: %s (%i hits)", hf->beststreak, hf->besthit);
mvprintw(newMaxy - 1, newMaxx, message); mvprintw(newMaxy - 1, newMaxx, message);
} }
attroff(COLOR_PAIR(3)); //Disable red color
} }
} }