cags Posted January 2, 2010 Share Posted January 2, 2010 There are a few different types of books available but the type I'm referring to are the ones where you will read a piece of text and at the end of that description you will receive a list of options 'walk left (turn to 100)', 'walk right (turn to 342)', 'take a nap (turn to 563)'. As an educational process I was thinking about how such a book could be implemented through a programming language. I suppose the obvious choice is to store each location in a database with at least id and description. You could then have a separate table for links which would include parent_id, link_text, link_id. From there it is fairly simple to have a system up and running that would allow you to be able to navigate around the world. The mental road block I hit was how exactly to expand upon this. For example, upon arriving at certain locations you may find an item or gain a password. Alternatively you may get automatically sent elsewhere if you have a specific item or password. I'm assuming it will require creation of some kind of scripting language. For example each location item in the database could have an action field, which would contain something like add_item:12, I could then parse this out and simply add item 12 to the characters inventory or check_item:12,goto:14 and then parse that out as if user has item 12 then goto location 14. In theory I suppose the action field could contain multiple actions that get parsed out in order. Another thing that may occur during the course of a game is a fight encounter. When you reach a square you fight an opponent if you win you move to location x if you loose you either move to location y or game over. I suppose this could be written into a similar sort of scripting language structure. One thing that is used in the books I have read (Fabled Lands) is perform a certain action if a location has been visited more than x amount of times, I have no idea how I could track this. From a purely programmatic standpoint I could perhaps envision a location class that could be inherited from to create sub-classes that could have extra functions for performing such actions, the problem I have is, I have no idea how to wrap that around a storage medium such as a database. Overall I'm not really sure if I'm thinking along the right sort of lines or completely off at a tangent. I'm just wondering if anyone else has any thoughts or opinions on the best approach. Quote Link to comment https://forums.phpfreaks.com/topic/186929-role-playing-adventure-books/ Share on other sites More sharing options...
phant0m Posted January 2, 2010 Share Posted January 2, 2010 To track how many times a player has visited a location, you could use a table like this: player_id | location_id | count Everytime a player visits a certain location, you update count. I agree on the scripting part, however, I would also add "scripting support" for each individual link. Perhaps you have actions that you want to occur every time you access a certain location, but then again, you may want to have actions that only get executed when you click on a certain link. You might also want to consider to have an ability to group your commands if you need the same sequence of commands perfomed often. Quote Link to comment https://forums.phpfreaks.com/topic/186929-role-playing-adventure-books/#findComment-987145 Share on other sites More sharing options...
SoccerGloves Posted January 2, 2010 Share Posted January 2, 2010 You might want to look into interactive fiction - that may be a little different than what you are thinking of, but I think it's very similar. There are scripting languages and standards that allow you to write these interactive books, and then there are interpreters that will play them. You can do all the things you are talking about, from picking up items to using passwords to talking to other characters and exploring. http://www.andybrain.com/archive/interactive_fiction.htm http://www.web-adventures.org/ http://en.wikipedia.org/wiki/Interactive_fiction I don't know of any PHP tools, but there are some web-based ones, like the web-adventures.org Quote Link to comment https://forums.phpfreaks.com/topic/186929-role-playing-adventure-books/#findComment-987181 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.