Handle END and GOTO footers

This commit is contained in:
Dane Johnson 2021-12-23 17:20:05 -06:00
parent 106786279f
commit f3d3bd2cd1
3 changed files with 17 additions and 6 deletions

View File

@ -3,7 +3,7 @@ START
One day Dane took a really big shit. One day Dane took a really big shit.
Dane: "Wow, that was a really big shit" Dane: "Wow, that was a really big shit"
1) Don't die [NEXT] GOTO NEXT
NEXT NEXT

View File

@ -1,5 +1,6 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <iostream>
#include "storybook.h" #include "storybook.h"
@ -24,7 +25,7 @@ int main(int argc, const char *argv[]) {
sb.Find("START"); sb.Find("START");
sb.Play(); sb.Play();
while (!sb.IsEnded()) { while (!sb.IsEnded) {
sb.Play(); sb.Play();
} }
@ -50,8 +51,18 @@ void Storybook::Find(const char* id) {
void Storybook::Play() { void Storybook::Play() {
printf(current->body); printf(current->body);
}
bool Storybook::IsEnded() { switch (current->footer.type) {
return true; // TODO case FooterType::End:
printf("The End.");
IsEnded = true;
break;
case FooterType::Goto:
Find(current->footer.link);
printf("Press ENTER to continue...");
std::cin.get();
break;
default:
IsEnded = true; // TODO
}
} }

View File

@ -13,7 +13,7 @@ public:
Storybook(FILE* fin); Storybook(FILE* fin);
void Find(const char*); void Find(const char*);
void Play(); void Play();
bool IsEnded(); bool IsEnded = false;
}; };
#endif /* STORYBOOK_H */ #endif /* STORYBOOK_H */