troll mode added #7
This commit is contained in:
48
hangman.c
48
hangman.c
@@ -4,17 +4,19 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h> //tolower
|
#include <ctype.h> //tolower
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <time.h>
|
#include <time.h> //time(null)
|
||||||
#include "prng.h"
|
#include "prng.h"
|
||||||
|
#include <unistd.h> //usleep
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
const char *short_options = "w:hf:c";
|
const char *short_options = "w:hf:ct";
|
||||||
struct option long_options[] = {
|
struct option long_options[] = {
|
||||||
{"word", required_argument, NULL, 'w'},
|
{"word", required_argument, NULL, 'w'},
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
{"file", required_argument, NULL, 'f'},
|
{"file", required_argument, NULL, 'f'},
|
||||||
{"credits", no_argument, NULL, 'c'}
|
{"credits", no_argument, NULL, 'c'},
|
||||||
|
{"troll", no_argument, NULL, 't'}
|
||||||
};
|
};
|
||||||
int c, startscr = 1; /* Show startscreen by default */
|
int c, startscr = 1; /* Show startscreen by default */
|
||||||
char filename[255];
|
char filename[255];
|
||||||
@@ -30,7 +32,7 @@ int main(int argc, char **argv) {
|
|||||||
gs->allowedMoves = DEFAULTTRIES;
|
gs->allowedMoves = DEFAULTTRIES;
|
||||||
gs->moves = 0;
|
gs->moves = 0;
|
||||||
gs->guesses = 0;
|
gs->guesses = 0;
|
||||||
|
gs->trollEnabled = 0;
|
||||||
|
|
||||||
curs_set(0);
|
curs_set(0);
|
||||||
while ( (c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1 ) {
|
while ( (c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1 ) {
|
||||||
@@ -50,6 +52,10 @@ int main(int argc, char **argv) {
|
|||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
/* troll option */
|
||||||
|
gs->trollEnabled = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
@@ -172,8 +178,8 @@ int playerInput(game_state *gs) {
|
|||||||
|
|
||||||
for (i = 0; i < gs->wordLength; i++) {
|
for (i = 0; i < gs->wordLength; i++) {
|
||||||
if (inp == gs->guessWord[i]) {
|
if (inp == gs->guessWord[i]) {
|
||||||
found = 1;
|
found++;
|
||||||
break;
|
//break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (found) {
|
if (found) {
|
||||||
@@ -181,6 +187,7 @@ int playerInput(game_state *gs) {
|
|||||||
if (fillCurrentWord(gs, inp)) {
|
if (fillCurrentWord(gs, inp)) {
|
||||||
//gs->moves++;
|
//gs->moves++;
|
||||||
gs->guesses++;
|
gs->guesses++;
|
||||||
|
trollHitScreen(gs, found);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* no valid character found */
|
/* no valid character found */
|
||||||
@@ -284,3 +291,32 @@ void readRandomLine(char *file, char *result) {
|
|||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void trollHitScreen(game_state *gs, int hits) {
|
||||||
|
if (gs->trollEnabled) {
|
||||||
|
char *strings[] = {"Double Hit", "Triple Hit", "Multi Hit", \
|
||||||
|
"Ultra Hit", "Monster Hit", "Rampage", \
|
||||||
|
"Unstoppable", "Wicked sick", "Godlike"};
|
||||||
|
int selection[] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||||
|
int i, len, z, found = 0;
|
||||||
|
for (i = 0; i < 9; i++) {
|
||||||
|
if (selection[i] == hits) {
|
||||||
|
found = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found) {
|
||||||
|
flash(); /* flash the screen */
|
||||||
|
mvprintw(5, centerDiff(gs->centerx, strings[i]), strings[i]);
|
||||||
|
refresh();
|
||||||
|
/* sleep and vanish */
|
||||||
|
usleep(500000);
|
||||||
|
len = strlen(strings[i]);
|
||||||
|
for (z = centerDiff(gs->centerx, strings[i]); z < gs->centerx + len; z++) {
|
||||||
|
mvprintw(5, z, " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -15,6 +15,7 @@ typedef struct {
|
|||||||
int wordLength;
|
int wordLength;
|
||||||
char currentWord[MAXWORDLENGTH];
|
char currentWord[MAXWORDLENGTH];
|
||||||
char wrongCharacters[DEFAULTTRIES];
|
char wrongCharacters[DEFAULTTRIES];
|
||||||
|
int trollEnabled;
|
||||||
} game_state;
|
} game_state;
|
||||||
|
|
||||||
typedef struct word {
|
typedef struct word {
|
||||||
@@ -40,3 +41,4 @@ void startGame(game_state *gs);
|
|||||||
void showHelp(game_state *gs);
|
void showHelp(game_state *gs);
|
||||||
int centerDiff(int coordinate, char *str);
|
int centerDiff(int coordinate, char *str);
|
||||||
void readRandomLine(char *file, char *result);
|
void readRandomLine(char *file, char *result);
|
||||||
|
void trollHitScreen(game_state *gs, int hits);
|
||||||
|
Reference in New Issue
Block a user