From 3440226ad324b0efb87a20661251db37b30350d3 Mon Sep 17 00:00:00 2001 From: structix Date: Sun, 26 Nov 2017 17:20:50 +0100 Subject: [PATCH] Added enColor and disColor to simplify colors --- CHANGELOG.md | 2 +- hangman.c | 18 ++++++++++++++---- hangman.h | 2 ++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23b3dca..f78b91c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog ## V1.1 (unreleased): - +* Added color mode ## V1.0 (30.08.2017): * Initial release diff --git a/hangman.c b/hangman.c index beb9560..3f1e175 100644 --- a/hangman.c +++ b/hangman.c @@ -116,11 +116,11 @@ void quitProgram(void) { } void showStartScreen(game_state *gs) { - attron(COLOR_PAIR(1)); + enColor(1); mvprintw(gs->centery - 1, gs->centerx - 15, "Welcome to hangman in ncurses."); mvprintw(gs->centery, gs->centerx - 5, "Have fun!"); mvprintw(gs->centery + 1, gs->centerx - 17, "https://gitlab.com/STRUCTiX/hangman"); - attroff(COLOR_PAIR(1)); + disColor(1); refresh(); getch(); clear(); @@ -450,7 +450,7 @@ void printHitFeed(game_state *gs, hitfeed *hf) { int newMaxy = gs->maxy - HITFEEDSLOTS; int newMaxx = gs->maxx - (gs->centerx / 2); int i, z; - attron(COLOR_PAIR(3)); //Enable red color + enColor(3); //Enable red color for (i = -1; i < HITFEEDSLOTS; i++) { for (z = 0; z <= gs->maxx - newMaxx; z++) { mvprintw(newMaxy + i, newMaxx + z, " "); @@ -466,7 +466,7 @@ void printHitFeed(game_state *gs, hitfeed *hf) { sprintf(message, "Best: %s (%i hits)", hf->beststreak, hf->besthit); mvprintw(newMaxy - 1, newMaxx, message); } - attroff(COLOR_PAIR(3)); //Disable red color + disColor(3); //Disable red color } } @@ -526,3 +526,13 @@ void animateLineClear(game_state *gs, int line, int offsetMultiplier) { mvprintw(line, k, " "); } } + + +void enColor(int color) { + attron(COLOR_PAIR(color)); +} + + +void disColor(int color) { + attroff(COLOR_PAIR(color)); +} diff --git a/hangman.h b/hangman.h index a70c3a1..cb18d38 100644 --- a/hangman.h +++ b/hangman.h @@ -69,3 +69,5 @@ void trollHandleImpressive(hitfeed *hf, game_state *gs, int hits); void drawFigure(game_state *gs, int drawNext); void animateLineClear(game_state *gs, int line, int offsetMultiplier); void printHitFeed(game_state *gs, hitfeed *hf); +void enColor(int color); +void disColor(int color);