Finish up the cli driver
This commit is contained in:
@@ -153,22 +153,6 @@ void append_body(Page *page, char *str) {
|
||||
}
|
||||
}
|
||||
|
||||
void print_page(Page *page) {
|
||||
printf("HEADER: %s\nBODY: %s\n", page->id, page->body);
|
||||
switch (page->footer.type) {
|
||||
case FooterType::End:
|
||||
printf("THE END\n");
|
||||
break;
|
||||
case FooterType::Goto:
|
||||
printf("GOTO %s\n", page->footer.link);
|
||||
break;
|
||||
case FooterType::Choices:
|
||||
printf("CHOICES:\n");
|
||||
// TODO
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Page*> CyoaParse(FILE *file) {
|
||||
yyin = file;
|
||||
yyparse();
|
||||
|
||||
@@ -56,10 +56,9 @@ void Storybook::Advance() {
|
||||
}
|
||||
}
|
||||
|
||||
void Storybook::Advance(int choice_option) {
|
||||
// TODO throw an exception if the ending type is not choices.
|
||||
void Storybook::Advance(int choice_option) {
|
||||
if (!IsChoiceAvailable(choice_option)) {
|
||||
// TODO throw exception?
|
||||
throw IllegalChoiceException();
|
||||
}
|
||||
|
||||
Choice* choice = (*current->footer.choices)[choice_option];
|
||||
@@ -122,9 +121,13 @@ void Storybook::Play() {
|
||||
printf("Make a selection: ");
|
||||
int choice_option;
|
||||
std::cin >> choice_option;
|
||||
Advance(choice_option);
|
||||
try {
|
||||
Advance(choice_option);
|
||||
} catch (IllegalChoiceException e) {
|
||||
printf("You can't do that!\n\n");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
IsEnded = true; // TODO
|
||||
IsEnded = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,12 @@ public:
|
||||
|
||||
// This will probably be moved to the cli driver
|
||||
void Play();
|
||||
|
||||
class IllegalChoiceException : std::exception {
|
||||
virtual const char *what() const noexcept {
|
||||
return "Illegal Choice.";
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* STORYBOOK_H */
|
||||
|
||||
Reference in New Issue
Block a user