Wednesday, December 7, 2011

More work on Dungeon Crawler

So my current project is coming along pretty well. I had an "AHA!" moment the other day (partly thanks to @jqr's hint about how to interpret gets.chomp) when I realized I need to use a form to collect that data. Once I've actually GOT some input from a user, it's easy enough to manipulate that information and make things happen.

I've drawn out the map of the entire dungeon (to help with actually laying it out when coding) and I've written methods and routes for all the rooms. Currently I'm loading a separate view for each room, since I eventually plan to have hand-drawn images representing the rooms themselves (which get updated when things happen, such as chests are opened, items discovered or moved, etc) so I thought this was the best way to handle it.

I've thought of ways to do the entire dungeon with a single view file and simply loading different information when the player makes certain choices, but for now I'm leaving that for a refactoring. Strangely enough, I think the hardest part of doing it this way would be figuring out a method for changing the image that represents the room, not the actual routing or the get method that would change the room. Strange!

I'm also not worrying about the individual features of rooms just yet, such as locked doors, traps, monsters and so on. My immediate goal is to be able to move throughout the entire dungeon, making sure all the routing works correctly and that you can't move into a room you shouldn't be able to.

Sinatra has proved a lot of fun to work with, in addition to being incredibly simple. It's kind of fun to have to do my own routing, too.

Also, I think it's important to name a project, so I'm calling this one Dungeon Crawler. (This was always the name of this project, even when it just lived in a Terminal window, but I'm not sure if I've mentioned that here or not)

Finally, I learned a great trick. I'd originally named my .rb file "dungeon_crawler.rb" and it quickly became tedious to type "ruby dungeon_crawler.rb" in the Terminal every time I make a change and have to reboot Sinatra, so I renamed it to "dc.rb". Much less tedious! My guess is that coders learn tons of tricks like this over the years.

Sunday, December 4, 2011

Making a web game with Ruby

Tonight I sat down to work through a bit more of Learn Ruby the Hard way (seriously, I'm on lesson 47 out of 52, I really should just finish it) but it didn't take long for me to get antsy to work on an actual program. Here's my current idea:

Building on AAN and Skyrim Stories, I want to take the dungeon crawler I made back in the summer, add some "awesome" hand-drawn graphics, and make it playable online. So far I'm picturing this as a Sinatra app, since it's pretty small and I won't need a database, and I can use Yaml for room descriptions. I've thought about ways to display different graphics for rooms when certain events happen, and I need to figure out how to take input from a user when an application is running on the web.

How do you collect information from a user, manipulate it, and trigger other functions based on the input when an application is running on the web? I'm unclear as to what the web equivalent of input = gets.chomp() is.

This project is largely just an excuse to take code I've already written (for the most part, it'll have to be refactored a bit for the web) and get more comfortable with getting a Ruby application to run on the internet. On top of that, I'm big into video games myself, and I'd love to have a hand in making games. Ruby probably isn't the best choice for making a game, but whatever!