Everything is an object. Let’s start with that. Also, this is an application with a GUI, so there’s no need to do lots of crazy infinite loops to wrap everything.
Using Objects means that you can put the right function in the right place, lets say you want to have an Item respond to the drink command. You can create a subclass (subclass?!?) of the Item class and then add the didRespondToCommand method that will respond to the command drink.
Every object that you place in game has the ability to respond to commands, that means you could add slay to the Dragon class, or sleep in the Bedroom class. You just have to think about the best place to put the command.
A lot of the time you won’t need to subclass a Room object, you can create a room easily, it’s normal to only create a subclass when you want to allow / disallow, add respond to examine to the room or add your own commands inside the room.
Rooms have a name and description that is called when you enter that room, and they also have an id so you can use getRoomByID on the WQ class.
You can add multiple objects that can be examined in a room very easily by making an nsdictionary of what you want to say vs what you want people to type. This is great for a quick examine item command that prints out some text. But if you want to do things like add Items to the players inventory or the room, you’ll have to add them as custom commands.
It’s normal to have rooms connected that you still may not have permission to access yet, say for example if you need a key or some other items to enter the room, you can use the method playerShouldEnterRoom and allow players to not enter if they do not have the required items.
To find out the current room (for example in an Item’s use method), you can use [Room current] to get the room the player is in right now.
People are objects that respond to say, and are added to a room using room.person they are a simplified version of the Creature class. You can make people respond to when you have entered a room that a player has gone into. This is useful for starting up a conversation, let the Person talk first.
The API for whether an item is on the player is all in the Player class, with the functions hasItemByID, getItemByID and removeItemByID, you can see them in use below in the snippet below
In this case we’re asking if the player has picked up an Item with an id called bubba, if they have then get a copy of it ( for later use ) and remove the one from the inventory.
As Items can have their own commands it makes sense to put commands in them, this also means they can keep their own variables, like this drink command which keeps drinking till drinksLeft is 0.
And in the implementation file
Common Item use cases
Here are some example onUse functions to help you get an idea of how to make Items do what you want.
Unlocking a door
Teleporting a Player
Mixing two Items to make one
To do this we have to use didRespondToCommand, in this example I get the first word from the command array and check if that is give. Then I narrate, and remove the Item from their inventory.
Creatures are things you want to fight. The are a subclass of People but have additional functions like responding to commands like fight.
To use them you need to have your player have some health, and a damageRange. Usually this is added in the ready function.
A fightable character is an instance or subclass of a Creature, they have name, damageRange, and Max Health variables that are self explanatory.
These go inside the creature subclass .m file:
What is less obvious is that you can do lots with what the creature says and how you attack it. There is a handy method called damageModifier which allows you to modify the damage after it’s been rolled. For example, in this case the damage is doubled if the user has picked up a keytar.
The way that the battle is described is quite interesting too, you supply a collection of strings in the form of an array that lets you describe each attack given and received, this means you don’t have to have generic “you hit the hippogruff for 5 damage” messages, you can make your own up. Like below.
There is a lot of methods you can override in order to get your creatures to be realistic, override as many as you want.
Once you’re happy with your class, you just need to add the creature to a room to make everything connect up.
Where do I put my code?
If you download one of the example applications, you’ll see they have a folder for the WibbleQuest framework as well as a game folder. In the game folder there is a usually files called [something]Game.m and [something]Game.h this is your main Game class, and where you do a lot of setting up your game.
It will come with a method already called ready which is where you can safely set up your game. Once ready is finished then the game starts but saying your Game’s Title and Description and puts the player in the first room.
Write on the screen
Depending on what style of text you’ll want to use these 6 commands on WQ
I want to have some ASCII art (Like a map or a ‘drawing’)
Awesome, you can do that by using the art function on WQ, this will give you monospaced text, you have up to 32 characters per line (on the iPhone) and the lines are separated by dollar signs ‘$’ the final gotcha is that all backslashes ‘\’ have to be two backslashes ‘\\’ as they are normally used to do things other than draw skeleton arms.
What is the id property on all these objects for?
You use the object.id whenever you are trying to find a specific object like
TLDR; always add one.
Make any object do a custom command
You want the Objject to override did respond to command. In this example it looks to see if the command is play and if it is, it says something. We the return YES, otherwise it will continue to look for other commands.
Find out what room I’m in
You want to get access to the shared WibbleQuest object, and then call currentRoom on it
Create a room
Make a room do something when you enter it
Make a room subclass, in it you can the override which will let you act when they leave / join
If you want to control whether they can leave or join a room, you can override
which expect a bool as to whether you can move out or in. These do not say anything so that’s left to the room to deal with informing the player why.
Move to another room
You can use teleport to room with ID, make sure to have done [wq addRoom: room] and that the room has an id and everything should be fine
Make it possible to examine things in the room
You need to subclass the Room object and add the method dictionaryForExamine. For example, this one says something if you write “examine clothes” in the room.
Make a room deny entry until you’ve got certain items
In your Room subclass you can ban someone to enter the room by returning NO. You also have a way of not letting someone leave the room, by using playerShouldLeaveRoom.
Add a Person to talk to you in a room
Create the person’s class, as a subclass of Person
Make them respond to words that are said by using
You can use the helpful method array contains to allow people to dig deeply into the conversation tree, or to allow them to react to multiple words with the same speech.
make a person give you something
You can just add an item to the players inventory for example like below
Make an item that you can pick up in a room
Create an Item subclass, add it to a room’s inventory, it can have multiple items.
Make an item do something when picked up or dropped
override onPickup in your class
Allow the player to use an object
override the method and that will be called when the player does “use [item]”
Make a person say Hello the first time you enter a room
In your Person subclass override respondToPlayerForTheFirstTime and this will only be called once
Add a Help command from an object in your inventory
You want to make it pretty obvious what is possible with the objects you have (right?!?) so it’s possible to dynamically add and remove text to the help system based on what Item’s are inside your Inventory. This is done by adding and removing commands when you pick up, or drop the object.