fix word validation logic
This commit is contained in:
parent
e055d9eee4
commit
9a6f8e16d5
2
build.sh
2
build.sh
@ -3,7 +3,7 @@
|
|||||||
mkdir -p build/cordle
|
mkdir -p build/cordle
|
||||||
|
|
||||||
echo "Building application."
|
echo "Building application."
|
||||||
gcc -std=c90 -o build/cordle/cordle src/*.c -Iinclude -lncurses
|
gcc -std=c90 -pedantic -Wall -o build/cordle/cordle src/*.c -Iinclude -lncurses
|
||||||
export RESULT=$?
|
export RESULT=$?
|
||||||
|
|
||||||
if (( RESULT == 0 )); then
|
if (( RESULT == 0 )); then
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
/* game.c - Game logic implementation */
|
/* game.c - Game logic implementation */
|
||||||
#include "../include/game.h"
|
#include "../include/game.h"
|
||||||
#include "../include/ui.h"
|
#include "../include/ui.h"
|
||||||
|
#include "../include/words.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
@ -99,6 +100,10 @@ int make_guess(GameState *game, const char *guess) {
|
|||||||
upper_guess[i] = toupper(upper_guess[i]);
|
upper_guess[i] = toupper(upper_guess[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!is_valid_word(game, upper_guess)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
strcpy(game->guesses[game->guess_count], upper_guess);
|
strcpy(game->guesses[game->guess_count], upper_guess);
|
||||||
check_guess(game, guess, game->guess_colors[game->guess_count]);
|
check_guess(game, guess, game->guess_colors[game->guess_count]);
|
||||||
game->guess_count++;
|
game->guess_count++;
|
||||||
|
|||||||
@ -176,11 +176,9 @@ int main_game_loop(int argc, char *argv[]) {
|
|||||||
game.current_guess_length = 0;
|
game.current_guess_length = 0;
|
||||||
strcpy(message, "");
|
strcpy(message, "");
|
||||||
} else {
|
} else {
|
||||||
/* Check if word is valid */
|
/* Validation failed in make_guess or is_valid_word */
|
||||||
if (!is_valid_word(&game, temp_guess)) {
|
strcpy(message, "Not in word list!");
|
||||||
strcpy(message, "Not in word list!");
|
message_color = COLOR_ABSENT;
|
||||||
message_color = COLOR_ABSENT;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sprintf(message, "Word must be %d letters!", WORD_LENGTH);
|
sprintf(message, "Word must be %d letters!", WORD_LENGTH);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user