make the game more tolerant of DOS limitations

This commit is contained in:
Gregory Gauthier 2026-01-28 08:33:37 +00:00
parent 3ce64b9984
commit 8bf21c3efd
11 changed files with 27 additions and 20 deletions

View File

@ -17,10 +17,10 @@
/* DOS path definitions */ /* DOS path definitions */
#define PATH_SEP "\\" #define PATH_SEP "\\"
#define WORDLIST_PATH_1 "words" #define WORDLIST_PATH_1 "WORDS"
#define WORDLIST_PATH_2 "C:\\CORDLE\\words" #define WORDLIST_PATH_2 "D:\\CORDLE\\WORDS"
#define WORDLIST_PATH_4 "D:\\CORDLE\\words" #define WORDLIST_PATH_3 "C:\\CORDLE\\WORDS"
#define WORDLIST_PATH_3 NULL #define WORDLIST_PATH_4 NULL
/* DOS doesn't have HOME environment variable */ /* DOS doesn't have HOME environment variable */
#define HAS_HOME_ENV 0 #define HAS_HOME_ENV 0
@ -30,9 +30,10 @@
/* Unix path definitions */ /* Unix path definitions */
#define PATH_SEP "/" #define PATH_SEP "/"
#define WORDLIST_PATH_1 "words" #define WORDLIST_PATH_1 "WORDS"
#define WORDLIST_PATH_2 "/usr/local/share/cordle/words" #define WORDLIST_PATH_2 "/usr/local/share/cordle/WORDS"
#define WORDLIST_PATH_3_FMT "%s/.local/share/cordle/words" #define WORDLIST_PATH_3 "%s/.local/share/cordle/WORDS""
#define WORDLIST_PATH_3_FMT "%s/.local/share/cordle/WORDS"
#define HAS_HOME_ENV 1 #define HAS_HOME_ENV 1
#endif #endif

View File

@ -19,30 +19,30 @@ static void parse_arguments(int argc, char **argv, char *filename, char *difficu
int i; int i;
/* Default values */ /* Default values */
strcpy(filename, "cordle_words_easy.txt"); strcpy(filename, "default.txt");
strcpy(difficulty, "EASY"); strcpy(difficulty, "DEFAULT");
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "--easy") == 0) { if (strcmp(argv[i], "--easy") == 0) {
strcpy(filename, "cordle_words_easy.txt"); strcpy(filename, "easy.txt");
strcpy(difficulty, "EASY"); strcpy(difficulty, "EASY");
} else if (strcmp(argv[i], "--medium") == 0) { } else if (strcmp(argv[i], "--medium") == 0) {
strcpy(filename, "cordle_words_medium.txt"); strcpy(filename, "medium.txt");
strcpy(difficulty, "MEDIUM"); strcpy(difficulty, "MEDIUM");
} else if (strcmp(argv[i], "--hard") == 0) { } else if (strcmp(argv[i], "--hard") == 0) {
strcpy(filename, "cordle_words_hard.txt"); strcpy(filename, "hard.txt");
strcpy(difficulty, "HARD"); strcpy(difficulty, "HARD");
} else if (strcmp(argv[i], "--techy") == 0) { } else if (strcmp(argv[i], "--techy") == 0) {
strcpy(filename, "cordle_words_techy.txt"); strcpy(filename, "techy.txt");
strcpy(difficulty, "TECHNICAL"); strcpy(difficulty, "TECHNICAL");
} else if (strcmp(argv[i], "--literary") == 0) { } else if (strcmp(argv[i], "--literary") == 0) {
strcpy(filename, "cordle_words_literary.txt"); strcpy(filename, "literary.txt");
strcpy(difficulty, "LITERARY"); strcpy(difficulty, "LITERARY");
} else if (strcmp(argv[i], "--cultural") == 0) { } else if (strcmp(argv[i], "--cultural") == 0) {
strcpy(filename, "cordle_words_cultural.txt"); strcpy(filename, "cultural.txt");
strcpy(difficulty, "CULTURAL"); strcpy(difficulty, "CULTURAL");
} else if (strcmp(argv[i], "--full") == 0) { } else if (strcmp(argv[i], "--full") == 0) {
strcpy(filename, "cordle_words_full.txt"); strcpy(filename, "full.txt");
strcpy(difficulty, "FULL"); strcpy(difficulty, "FULL");
} else if (strcmp(argv[i], "--wordlist") == 0 && i + 1 < argc) { } else if (strcmp(argv[i], "--wordlist") == 0 && i + 1 < argc) {
strcpy(filename, argv[i + 1]); strcpy(filename, argv[i + 1]);
@ -90,8 +90,8 @@ static int main_game_loop(int argc, char *argv[]) {
if (!load_words(&game, filename)) { if (!load_words(&game, filename)) {
/* Try fallback */ /* Try fallback */
if (strcmp(filename, "cordle_words.txt") != 0 && if (strcmp(filename, "default.txt") != 0 &&
load_words(&game, "cordle_words.txt")) { load_words(&game, "default.txt")) {
strcpy(difficulty, "DEFAULT"); strcpy(difficulty, "DEFAULT");
} else { } else {
mvaddstr(0, 0, "Error: Could not load word list"); mvaddstr(0, 0, "Error: Could not load word list");

View File

@ -18,16 +18,22 @@ static FILE *open_wordlist(const char *filename) {
const char *home; const char *home;
#endif #endif
/* Try 1: wordlists/ relative to the current directory (for development) */ /* Try 1: WORDS/ relative to the current directory (for development) */
sprintf(filepath, "%s%s%s", WORDLIST_PATH_1, PATH_SEP, filename); sprintf(filepath, "%s%s%s", WORDLIST_PATH_1, PATH_SEP, filename);
file = fopen(filepath, "r"); file = fopen(filepath, "r");
if (file) return file; if (file) return file;
/* Try 2: system installation path */ /* Try 2: D drive installation path */
sprintf(filepath, "%s%s%s", WORDLIST_PATH_2, PATH_SEP, filename); sprintf(filepath, "%s%s%s", WORDLIST_PATH_2, PATH_SEP, filename);
file = fopen(filepath, "r"); file = fopen(filepath, "r");
if (file) return file; if (file) return file;
/* Try 2: C drive installation path */
sprintf(filepath, "%s%s%s", WORDLIST_PATH_3, PATH_SEP, filename);
file = fopen(filepath, "r");
if (file) return file;
#if HAS_HOME_ENV #if HAS_HOME_ENV
/* Try 3: ${HOME}/.local/share/cordle/wordlists/ (Unix user installation) */ /* Try 3: ${HOME}/.local/share/cordle/wordlists/ (Unix user installation) */
home = getenv("HOME"); home = getenv("HOME");