|
|
|
@@ -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";
|
|
|
|
@@ -35,7 +43,23 @@ int main(int argc, char **argv) {
|
|
|
|
|
/* Initialization */
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|