Showing posts with label dungeon crawler. Show all posts
Showing posts with label dungeon crawler. Show all posts

Tuesday, January 3, 2012

Learning How to Abstract Code

In my last post, I was talking about how to deal with coder's block. I've been working on my current project, Dungeon Crawler, for about a month and I'd really hit a wall.

The problem was due to a couple of things. First, I'd gotten a lot of really good advice that I didn't quite understand, and I felt bad that I wasn't getting it, so I was reluctant to ask for more advice. Second, I'd already spent so much time without making any progress that I was getting sick of the project.

But I think I've gotten through my lack of motivation and I've made some progress with this project, but the code is an explicit, redundant mess. So the question at this point becomes is it better for me to make some progress coding in a way that I know is bad, or to not make progress at all?

Obviously it's better to make progress (and I did learn a bit about YAML tonight, so it's not entirely a wash) but it's about time I got better at writing code. I've noticed a problem with the way I write code: I'm far too heavy handed and I repeat myself too much. I need to get better at abstracting my code, so that's my current goal.

Maybe this is easier said than done, but at least I'm losing track of time while coding again, right?

Friday, December 30, 2011

How do you deal with coder's block?

I've kind of fallen into a trap with my Ruby work. I've been working on Dungeon Crawler for so long that I'm getting sick of it. I've had help from several friendly Rubyists (@jqr, @mileszs, @netshade, I am looking at you here) and I simply can't figure out how to make a proper redirect based on a form input.

This is extra irritating because I'm pretty sure I DO get how routing with Sinatra works, but starting a user out on one page with an input form, then redirecting that user to another page based on his input, seems to be escaping me.

I've gotten this to work in a limited capacity, when all of the logic is thrown into the

get '/input' do

method, but using a case/when statement here always uses the same logic. For example, dais_room will be north of torch_room, but vine_room will be north of dais_room, and I was always being redirected to dais_room with input "go north."

I also had a problem of simply being redirected to a white page with black text pulling the description of the room. I believe this was the method @netshade showed me for automatically creating a room without explicitly coding it, but for some reason it was not loading a view file.

Here's a full gist of what I've got, if anyone wants to give me some srs help:

Dungeon Crawler full gist

What do you guys do when you get so frustrated with a project? Do you power through, work on something else, or just take a break? I feel like since the holidays began, I've found a ton of great excuses not to code. It's Christmas Eve! It's Christmas! I just had LASIK surgery done!

But I'm sick of making excuses and I want to get back into working on a project without feeling like a gigantic dummy or just tearing my hair out because I can't figure it out. That makes sense, right?

It's not all bad news, though. @netshade and @annamul gave me The Pragmatic Programmer, a philosophical/theoretical book about coding. I really like the PragProg guys, and this book has been a lot of fun to read so far.

I think I need some way of setting goals for myself each week with coding. As in, "This week get better with using Git for source control," or "This week, get more comfortable with Javascript." Any recommendations for simple goal setting applications, or methods you've used? I use Tadalist for simple day-to-day chores and things, but that's not quite what I want. Maybe Evernote would work? I still haven't checked into that.

Either way, thanks for all your help, everyone! And Happy New Year!

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.