Added enColor and disColor to simplify colors

This commit is contained in:
2017-11-26 17:20:50 +01:00
parent 70f7fb0a13
commit 3440226ad3
3 changed files with 17 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
# Changelog # Changelog
## V1.1 (unreleased): ## V1.1 (unreleased):
* Added color mode
## V1.0 (30.08.2017): ## V1.0 (30.08.2017):
* Initial release * Initial release

View File

@@ -116,11 +116,11 @@ void quitProgram(void) {
} }
void showStartScreen(game_state *gs) { 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 - 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)); disColor(1);
refresh(); refresh();
getch(); getch();
clear(); clear();
@@ -450,7 +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 enColor(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, " ");
@@ -466,7 +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 disColor(3); //Disable red color
} }
} }
@@ -526,3 +526,13 @@ void animateLineClear(game_state *gs, int line, int offsetMultiplier) {
mvprintw(line, k, " "); mvprintw(line, k, " ");
} }
} }
void enColor(int color) {
attron(COLOR_PAIR(color));
}
void disColor(int color) {
attroff(COLOR_PAIR(color));
}

View File

@@ -69,3 +69,5 @@ void trollHandleImpressive(hitfeed *hf, game_state *gs, int hits);
void drawFigure(game_state *gs, int drawNext); void drawFigure(game_state *gs, int drawNext);
void animateLineClear(game_state *gs, int line, int offsetMultiplier); void animateLineClear(game_state *gs, int line, int offsetMultiplier);
void printHitFeed(game_state *gs, hitfeed *hf); void printHitFeed(game_state *gs, hitfeed *hf);
void enColor(int color);
void disColor(int color);