Add words and their synonyms
This commit is contained in:
parent
a09f7106de
commit
204bf6c3c9
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
|||||||
raylib.h
|
raylib.h
|
||||||
game
|
game
|
||||||
|
|
||||||
data/*.c
|
*/data/*.c
|
@ -3,10 +3,10 @@ CFLAGS=-Wall -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
|
|||||||
|
|
||||||
.PHONY: clean run
|
.PHONY: clean run
|
||||||
|
|
||||||
game: rooms.data transitions.data *.c
|
game: data/rooms.c data/transitions.c data/words.c *.c
|
||||||
$(CC) *.c $(CFLAGS) -o game
|
$(CC) *.c $(CFLAGS) -o game
|
||||||
|
|
||||||
%.data: data/%.txt
|
data/%.c: data/%.txt
|
||||||
echo -n "char *data_$*_txt = \"" > data/$*.c
|
echo -n "char *data_$*_txt = \"" > data/$*.c
|
||||||
cat data/$*.txt | perl -pe 's/\n/\\n/g' >> data/$*.c
|
cat data/$*.txt | perl -pe 's/\n/\\n/g' >> data/$*.c
|
||||||
echo "\";" >> data/$*.c
|
echo "\";" >> data/$*.c
|
||||||
|
@ -70,7 +70,7 @@ NORTH | IN(other_room) | 2 | You enter the opulent room. | GOTO(opulent_room
|
|||||||
I'm sure we want a gallery of synonyms for most verbs and nouns. I assume we split the string
|
I'm sure we want a gallery of synonyms for most verbs and nouns. I assume we split the string
|
||||||
by spaces, making an array of canonical words, then write the actions around those canonical
|
by spaces, making an array of canonical words, then write the actions around those canonical
|
||||||
words.
|
words.
|
||||||
PULL | PULL,YANK,TUG
|
PULL|PULL,YANK,TUG
|
||||||
ROPE | ROPE,CORD,STRING,CABLE
|
ROPE|ROPE,CORD,STRING,CABLE
|
||||||
With the above words, "PULL ROPE", "YANK CORD", or "TUG STRING" would all check for
|
With the above words, "PULL ROPE", "YANK CORD", or "TUG STRING" would all check for
|
||||||
actions as "PULL ROPE".
|
actions as "PULL ROPE".
|
||||||
|
2
01_text_adventure/data/words.txt
Normal file
2
01_text_adventure/data/words.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
PULL|PULL,YANK,TUG
|
||||||
|
ROPE|ROPE,CORD,STRING,CABLE
|
@ -30,6 +30,9 @@ Game *game_create(void) {
|
|||||||
|
|
||||||
g->input = input;
|
g->input = input;
|
||||||
|
|
||||||
|
g->words = malloc(sizeof(Words));
|
||||||
|
g->words->count = 0;
|
||||||
|
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ typedef enum Command {
|
|||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "transition.h"
|
#include "transition.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "word.h"
|
||||||
|
|
||||||
struct Game {
|
struct Game {
|
||||||
bool should_close;
|
bool should_close;
|
||||||
@ -26,6 +27,7 @@ struct Game {
|
|||||||
Rooms *rooms;
|
Rooms *rooms;
|
||||||
Room *current_room;
|
Room *current_room;
|
||||||
Transitions *transitions;
|
Transitions *transitions;
|
||||||
|
Words *words;
|
||||||
};
|
};
|
||||||
|
|
||||||
Game *game_create(void);
|
Game *game_create(void);
|
||||||
|
@ -17,6 +17,7 @@ int main(void) {
|
|||||||
game_load_rooms(g);
|
game_load_rooms(g);
|
||||||
g->current_room = &g->rooms->rooms[0];
|
g->current_room = &g->rooms->rooms[0];
|
||||||
game_load_transitions(g);
|
game_load_transitions(g);
|
||||||
|
game_load_words(g);
|
||||||
|
|
||||||
game_run_until_close(g);
|
game_run_until_close(g);
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
27
01_text_adventure/word.c
Normal file
27
01_text_adventure/word.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "word.h"
|
||||||
|
#include "game.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
void load_word(Game *g, char *line) {
|
||||||
|
char *token = strtok(line, "|");
|
||||||
|
Word *word = &g->words->words[g->words->count];
|
||||||
|
word->word = malloc(strlen(token) + 1);
|
||||||
|
strcpy(word->word, token);
|
||||||
|
|
||||||
|
word->synonyms_count = 0;
|
||||||
|
while ((token = strtok(NULL, ",")) != NULL) {
|
||||||
|
word->synonyms[word->synonyms_count] = malloc(strlen(token) + 1);
|
||||||
|
strcpy(word->synonyms[word->synonyms_count], token);
|
||||||
|
word->synonyms_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
g->words->count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "data/words.c"
|
||||||
|
void game_load_words(Game *g) {
|
||||||
|
parse_multiline_string(g, data_words_txt, &load_word);
|
||||||
|
}
|
21
01_text_adventure/word.h
Normal file
21
01_text_adventure/word.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef _FD_WORD_
|
||||||
|
#define _FD_WORD_
|
||||||
|
typedef struct Word Word;
|
||||||
|
typedef struct Words Words;
|
||||||
|
|
||||||
|
#include "game.h"
|
||||||
|
|
||||||
|
struct Word {
|
||||||
|
char *word;
|
||||||
|
char* synonyms[100];
|
||||||
|
int synonyms_count;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Words {
|
||||||
|
Word words[200];
|
||||||
|
int count;
|
||||||
|
};
|
||||||
|
|
||||||
|
void game_load_words(Game *g);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user