Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
7adcaf4d72 | |||
3440226ad3 | |||
70f7fb0a13 | |||
6ca31e2bec |
7
CHANGELOG.md
Normal file
7
CHANGELOG.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Changelog
|
||||
|
||||
## V1.1 (unreleased):
|
||||
* Added color mode
|
||||
|
||||
## V1.0 (30.08.2017):
|
||||
* Initial release
|
39
hangman.c
39
hangman.c
@@ -13,8 +13,16 @@
|
||||
#include "prng.h"
|
||||
#include <unistd.h> //usleep
|
||||
#include "figures.h"
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
void handle_winch(int sig) {
|
||||
/* This function handles the console resizing */
|
||||
endwin();
|
||||
clear();
|
||||
refresh();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
const char *short_options = "w:hf:ct";
|
||||
@@ -36,6 +44,22 @@ int main(int argc, char **argv) {
|
||||
initscr();
|
||||
atexit(quitProgram);
|
||||
|
||||
//Windows resize handler
|
||||
struct sigaction sa;
|
||||
memset(&sa, 0, sizeof(struct sigaction));
|
||||
sa.sa_handler = handle_winch;
|
||||
sigaction(SIGWINCH, &sa, NULL);
|
||||
|
||||
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;
|
||||
|
||||
@@ -96,6 +120,7 @@ void startGame(game_state *gs, hitfeed *hf) {
|
||||
noecho(); /* Don't show the player input */
|
||||
time(&gs->startTime);
|
||||
while (checkWin(gs)) {
|
||||
initCoordinates(gs); //Necessary for window resizing
|
||||
updateScreen(gs);
|
||||
playerInput(gs, hf);
|
||||
printHitFeed(gs, hf);
|
||||
@@ -107,9 +132,11 @@ void quitProgram(void) {
|
||||
}
|
||||
|
||||
void showStartScreen(game_state *gs) {
|
||||
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");
|
||||
disColor(1);
|
||||
refresh();
|
||||
getch();
|
||||
clear();
|
||||
@@ -439,6 +466,7 @@ void printHitFeed(game_state *gs, hitfeed *hf) {
|
||||
int newMaxy = gs->maxy - HITFEEDSLOTS;
|
||||
int newMaxx = gs->maxx - (gs->centerx / 2);
|
||||
int i, z;
|
||||
enColor(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 +482,7 @@ void printHitFeed(game_state *gs, hitfeed *hf) {
|
||||
sprintf(message, "Best: %s (%i hits)", hf->beststreak, hf->besthit);
|
||||
mvprintw(newMaxy - 1, newMaxx, message);
|
||||
}
|
||||
disColor(3); //Disable red color
|
||||
}
|
||||
}
|
||||
|
||||
@@ -513,3 +542,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));
|
||||
}
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user