Checking Our Inventory

Finally, let’s create a function that lets players see an inventory of objects they are carrying:

(defun inventory ()
  (cons 'items- (objects-at 'body *objects* *object-locations*)))

This inventory function uses the objects-at function to retrieve a list of objects at a requested location. What location does it search for? If you remember, when an object was picked up by the player, we changed its location to 'body: This is the location we now use to query.

Let’s try out this inventory function:

> (inventory)
(ITEMS- WHISKEY)

As you can see, we are carrying only one item right now: the whiskey bottle we just picked up.

There you have it! We now have a basic engine for a text adventure game. We can look around the world with look; walk between places with walk; pick up objects with pickup; and check our inventory with inventory.

Of course, we don’t really have much of a game, since we can’t do anything with the objects we find. We’ll add a mechanism for actually manipulating objects in Chapter 17. In the next chapter, we’ll focus on improving our game’s user interface. Even though the REPL is perfect for prototyping our game, adding a custom text game interface will make the game play more seamless for the player.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.211.106