Code Example – Scattering Toys

I came up with a neat little toy project (literally!) the other day. I’m going to keep putting these up. I’m not sure how many of them will actually turn out to be original, but it motivates me to keep going, so *shrug*

"Scattering Toys" by xyzoe

[An example to demonstrate scattering a collection of toys around some rooms]

Bedroom is a room. Hallway is south of Bedroom. Bathroom is west of Hallway. Living Room is east of Hallway. Kitchen is south of Living Room.

A toy is a kind of thing. lego, ball, fire engine, capsulas, Kitty, Owlie, airplane, Gameboy, yo-yo and Simon are toys.

Every turn:
	repeat with room running through adjacent rooms:
		say "[room] [are] [best route from the location to room].[line break]";

When play begins:
	repeat with item running through toys:
		now item is in a random room;

Listing toys is an action applying to nothing. Understand "list toys" as listing toys.

Scattering toys is an action applying to nothing. Understand "scatter toys" as scattering toys.

Carry out scattering toys:
	repeat with toy running through toys:
		now toy is in a random room.

Carry out listing toys:
	repeat with r running through rooms containing toys:
		say "[list of toys in r] [are] in [r].[line break]".

test me with "list toys / scatter toys / list toys".