Sniff is a "Scratch-like" programming language that's designed to help Scratchers move gently from Scratch to more conventional languages. They can start writing programs, without having to learn a new language because Sniff is based on Scratch. They learn a little more about variables, compiling, syntax errors (!), and they can have fun controlling real hardware while they're doing it.

Wednesday, 14 May 2014

Text Adventures in Sniff

Last week I went on the Year 2 school trip and spent a fun (and tiring!) day helping 7 and 8 year olds draw maps of the beach and park. There was also an article going around online about someone who'd ported the Zork engine to Arduino. Seeing the four walls of the classroom labeled N/S/E/W got me thinking about putting that all together and thinking about text based games in Sniff.

Text based games run at a slower pace than video games, and encourage discussion and problem solving rather than just blasting. You actually have to read stuff, and I've still got old notebooks with maps for most the Level 9 games. I wasn't that great at the games but I did love drawing the maps.

I also wrote a bunch of adventure games for the BBC Micro. One called Atlantis (which made up in size what it lacked in quality), was co-authored with a less techy kid from school who was into the games, and did most of the text, while I focused on the core code, and trickier parts of the game logic. The best one I wrote was based on the book "Help! I'm a prisoner in a toothpaste factory" by John Antrobus (It's great - read it!), and featured some pretty impressive mode 7 graphics loaded from floppy disc (I wrote a mode 7 paint package to generate the images!). The last BBC Micro effort which never got past the engine stage used an AMX Mouse to click icons for each action. At Uni I moved on to Sun workstations, and one of my side projects for a number of years was a multi user adventure.

You can use text adventures with kids in a bunch of different ways - start by just letting them play (it's reading!), and pretty soon they'll start making maps of the game world. These are "topological" maps as they connect rooms together rather than (necessarily) making an coherent 3D space (they may even be directed graphs if you want to explore that idea!). From there they can make topological maps of a real place.

Once you've got a "map" its pretty easy to put that into a game engine. You can do this without writing any code, though it does require careful planning and organisation. Any adventure game will basically have a core engine which lets you walk round a map, and manipulate basic objects. The idea is that this handles 90% of the interactions, and then specific code is added to handle the actual progress through the game (if you're on the space ship with the ham sandwich, then the elephant will share his lunch with you).

Lets start with the basic stuff: back in the "old days" we had to squeeze adventure games into 16K of memory, but now we can just store all the text in files, and we can make the games as big as we like. In the Sniff Adventure Engine (SAE!), start by making a folder called "rooms". Give each room on your map a number, and then for each of them create a file named 1.txt, 2.txt, 3.txt and so on with a description of the room. These descriptions get displayed every time you enter that room.

The next step is to connect the rooms up. Also in the rooms folder are files called 1.dat, 2.dat etc. These contain the rooms that will you will go to when you move N,S,E,W,Up,Down from the room. For example the first line of 1.dat indicates what happens when you go north from room 1. There is no room zero, so a zero means you can't go in that direction.

There's also a folder for objects, which contains a file called startInfo.txt. This contains pairs of lines, giving objects names and the rooms the can be found in. For example:


makes lamp object number 1, and places it in room 2. The sword (object number 3) is in room 4. As previously noted there is no room 0 so that means the player is carrying the pen. In the objects folder there's also a file lamp.txt which contains a description of the lamp (and similarly for there objects).

Just by creating these files, we get to make a world that we can walk around in (It's like minecraft with words!). While I've described the steps in sequence, in practise you'd probably want to develop small areas of the game, and play test them before moving on to the next area.

Just getting this far with a project, we've done mapping, lots of organisation and file management, team working, and descriptive writing. If you're working in a group you've probably had some heated debates. You could make a virtual school, or you could tie this into a book the class is reading: What are the places in the book, how are they related, are there key events or objects (what's the MacGuffin?).

That's before we've even started coding! It's really important to tie together things like descriptive writing, and story telling with technical subjects. We all remember counting how many pieces of cake the hungry caterpillar ate! Computing (or maths) is a tool for doing things, so projects should do interesting things, rather than just learning a technique.

You can download SAE along with an example game, which has 7 rooms and 4 objects. There are two versions of the engine included: adv.sniff is the generic game engine which you can use to walk round maps, while demo.sniff contains a simple example with a couple of puzzles. As written it won't run on an Arduino, as it use native file access, and in any case all that string handling eats memory, so run it on a Pi, Mac or Linux machine.

This has turned into another multi-part post, as this si getting a bit long, but in a future post I'll explain how SAE works internally, and how you can add your own puzzles. In the meantime, please leave a comment, and let us know if you're using games like these.

No comments:

Post a Comment