troll mode added #7

This commit is contained in:
2017-05-03 19:38:10 +02:00
parent d0d3c6e7bd
commit fbf1d10af1
2 changed files with 44 additions and 6 deletions

View File

@@ -4,17 +4,19 @@
#include <string.h>
#include <ctype.h> //tolower
#include <getopt.h>
#include <time.h>
#include <time.h> //time(null)
#include "prng.h"
#include <unistd.h> //usleep
int main(int argc, char **argv) {
const char *short_options = "w:hf:c";
const char *short_options = "w:hf:ct";
struct option long_options[] = {
{"word", required_argument, NULL, 'w'},
{"help", no_argument, NULL, 'h'},
{"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 */
char filename[255];
@@ -30,7 +32,7 @@ int main(int argc, char **argv) {
gs->allowedMoves = DEFAULTTRIES;
gs->moves = 0;
gs->guesses = 0;
gs->trollEnabled = 0;
curs_set(0);
while ( (c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1 ) {
@@ -50,6 +52,10 @@ int main(int argc, char **argv) {
break;
case 'c':
break;
case 't':
/* troll option */
gs->trollEnabled = 1;
break;
default:
@@ -172,8 +178,8 @@ int playerInput(game_state *gs) {
for (i = 0; i < gs->wordLength; i++) {
if (inp == gs->guessWord[i]) {
found = 1;
break;
found++;
//break;
}
}
if (found) {
@@ -181,6 +187,7 @@ int playerInput(game_state *gs) {
if (fillCurrentWord(gs, inp)) {
//gs->moves++;
gs->guesses++;
trollHitScreen(gs, found);
}
} else {
/* no valid character found */
@@ -284,3 +291,32 @@ void readRandomLine(char *file, char *result) {
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, " ");
}
}
}
}

View File

@@ -15,6 +15,7 @@ typedef struct {
int wordLength;
char currentWord[MAXWORDLENGTH];
char wrongCharacters[DEFAULTTRIES];
int trollEnabled;
} game_state;
typedef struct word {
@@ -40,3 +41,4 @@ void startGame(game_state *gs);
void showHelp(game_state *gs);
int centerDiff(int coordinate, char *str);
void readRandomLine(char *file, char *result);
void trollHitScreen(game_state *gs, int hits);