Hi Group,

I've been looking for an excuse to get started with web and python. Finally
I thought up this little game for a friend, but how to port it to web2py?

The game is like one of those old adventure books. There is a story, but at
some point the player must decide on an action. For each option the story
then forks. this happens again and again, until the story finishes, one way
or the other. (actually in this particular case we are writing a poem... But
the principle is the same).

This game is being built for my friends birthday party. The plan is to have
each of the attending friends each write three chapters of the story. The
script assumes that the friends will upload / mail me the chapters as a yaml
file.

The yaml template looks like this.

ChapterTitel: Whatever # The title is not really used in this version.
> txt: |                  # Write chapter text below. The text must be
> indented
>     This is the chapter text. Notice the first line is indented?
>     And so forth.

    You can make paragraphs, and what ever you like.
>     Just keep the text indented.
> Option:
>     a:
>         option_txt: Write option one
>         next: option_file_name.yaml #the name of the next chapter (file
> name)
>     b:
>         option_txt: Option two
>         next: fantastic_option_yes.yaml
>     c:
>         option_txt: You get the idea...
>         next: You_got_right.yaml #dont use spaces or weird punctuation in
> file names

This is the script. I am sure it can and should be improved in countless
ways. Please tell me which :-)


from sys import exit
> import yaml
> class Spil(object):
>     def __init__(self,start="start.yaml"):
>         self.start = start
>     def play(self):
>         next = self.start
>         while True:
>             print "\n--------"
>             next = self.show_poem(next)
>
>     def show_poem(self,next):
>         with open(next) as digt:
>             digt = yaml.load(digt)
>         print(digt["txt"])
>         print("-------------------------\n")
>         print("A > "+digt["option"]["a"]["option_txt"])
>         print("B > "+digt["option"]["b"]["option_txt"])
>         print("C > "+digt["option"]["c"]["option_txt"])
>         user = raw_input("What do you choose (A, B or C)? > ").lower()
>
>         if user in ["a","b","c"]:
>             next = digt["option"][user]["next"]
>             if next == "end.yaml":
>                 print("Finished :-) Thanks for playing :-)")
>                 exit(1)
>             else:
>                 return next

I hope that makes sense. Now to my question. What would be the best strategy
to move move forward here? In the terminal it works fine, but I guess each
new part of the story must be presented as a new html page? Prefereable I'd
like to show each new chapter as an extension of the first, so that the
player can see the story as one whole. And preferable with out a new page
loading... How ever - simplicity is priority number one.

So how to display the next chapter, and how to collect user input?

Would it be better to use a database than yaml files? Should I make a
webform to collect stories instead of asking people to mail me the yaml
files?

This is completely new for me. But I guess the task it simple. So for
starters I hope to get some advice about good practice and maybe specific
pointers to relevant sections/chapters in the web2py book. E.g if I need to
make a new web page for each html, I need to create that dynamically?

Sincerely and thanks in advance,

Andreas

Reply via email to