Added color mode
This commit is contained in:
15
hangman.c
15
hangman.c
@@ -35,7 +35,16 @@ int main(int argc, char **argv) {
|
||||
/* Initialization */
|
||||
initscr();
|
||||
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);
|
||||
gs.allowedMoves = DEFAULTTRIES;
|
||||
|
||||
@@ -107,9 +116,11 @@ void quitProgram(void) {
|
||||
}
|
||||
|
||||
void showStartScreen(game_state *gs) {
|
||||
attron(COLOR_PAIR(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));
|
||||
refresh();
|
||||
getch();
|
||||
clear();
|
||||
@@ -439,6 +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
|
||||
for (i = -1; i < HITFEEDSLOTS; i++) {
|
||||
for (z = 0; z <= gs->maxx - 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);
|
||||
mvprintw(newMaxy - 1, newMaxx, message);
|
||||
}
|
||||
attroff(COLOR_PAIR(3)); //Disable red color
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user