Old school adventure
Some of the very first computer programs (after hello world) were text adventure games. New ones continue to appear even today.
If you haven't played a game of this type, you should try one out. They provide a valuable lesson in how a lot of vibe can be created with some well-crafted words. They succeed because they focus on the idea of telling a Story.
Building a Story
Balladeer puts the idea of Story front and centre. In fact the first thing you do is create a new Python file (usually main.py) and add this import(ant) line:
from balladeer import StoryBuilder
As a simple exercise, why not add these lines too:
from balladeer import Dialogue story = StoryBuilder( Dialogue("Here's a joke..."), Dialogue("<ADAM> Knock, knock."), Dialogue("<BETH> Who's there?"), Dialogue("<ADAM> Doctor."), Dialogue("<BETH> Doctor who?"), Dialogue("<ADAM> You just said it."), Dialogue("Press Ctrl-C to finish."), ) while True: with story.turn() as turn: for line in turn.speech: print(*line.words)
We all know that timing is the most important part of telling a joke.
How would you modify this code so that each line appears a second or two after the previous one?
Hint: take a look at Python's time module.
When you run the code you'll see:
Here's a joke...
Then one by one the other lines appear:
ADAM Knock, knock. BETH Who's there? ADAM Doctor. BETH Doctor who? ADAM You just said it. Press Ctrl-C to finish.
Well done if this is your first Python program. And congratulations if you figured out the solution.
Or maybe you found this far too simple and you want to move on to the grown-up stuff.
Well either way it looks like you're ready.
In the next article, I promise there'll be fewer lines to type. And I'll show you how to run this Story from your own Web Server.