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
|
||||
game
|
||||
|
||||
data/*.c
|
||||
*/data/*.c
|
@ -3,10 +3,10 @@ CFLAGS=-Wall -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
|
||||
|
||||
.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
|
||||
|
||||
%.data: data/%.txt
|
||||
data/%.c: data/%.txt
|
||||
echo -n "char *data_$*_txt = \"" > data/$*.c
|
||||
cat data/$*.txt | perl -pe 's/\n/\\n/g' >> data/$*.c
|
||||
echo "\";" >> data/$*.c
|
||||
|
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->words = malloc(sizeof(Words));
|
||||
g->words->count = 0;
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ typedef enum Command {
|
||||
#include "room.h"
|
||||
#include "transition.h"
|
||||
#include "log.h"
|
||||
#include "word.h"
|
||||
|
||||
struct Game {
|
||||
bool should_close;
|
||||
@ -26,6 +27,7 @@ struct Game {
|
||||
Rooms *rooms;
|
||||
Room *current_room;
|
||||
Transitions *transitions;
|
||||
Words *words;
|
||||
};
|
||||
|
||||
Game *game_create(void);
|
||||
|
@ -17,6 +17,7 @@ int main(void) {
|
||||
game_load_rooms(g);
|
||||
g->current_room = &g->rooms->rooms[0];
|
||||
game_load_transitions(g);
|
||||
game_load_words(g);
|
||||
|
||||
game_run_until_close(g);
|
||||
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