Blackjax 3.0

May 05, 2006 0 comments

First off, sorry about the downtime. Dreamhost and Typo haven’t been playing nice lately. But, I made a slew of improvements to Blackjax that I thought I’d push back out to the world since it’s been my most popular software project to date (Over 1200 downloads!).

There’s still basic functionality, like not being able to wager more than you have, that isn’t implemented yet, but I’m more interested in getting the framework setup instead of sweating the small stuff like that.

The major update is my inclusion of a database…again. I took it out of the equation previously, because it slowed the game down to a crawl, but I haven’t compromised speed this time around.

I’m using it to store accounts, meaning that you are given a unique url when you visit the site, and can continue to access that url to keep playing with the same bankroll. This mimicks 37Signals’ Backpack functionality, so have a look at how I did it.

I’ll spoil the surprise, this is all there is to it:


redirect_to :action => 'index', :id => session.session_id if params[:id].nil?
session[:user] = (User.find_by_password(params[:id]) || User.create({:password => params[:id], :bankroll => 500}))

Update: I replaced the “readable” code with the “unreadable” code, because the more and more I looked at it, the more it made sense to use the one-liner. I’m comfortable admitting when I’m wrong ;-) But, this does go into a longer discussion about Rubyists trying too hard to make crafty code that compromises readibility.

I originally generated a SHA1 digest to create a unique id based off of the current time, but it then occurred to me that rails has already generated a perfectly good id I can use.

I thought about doing some sanity checking on the id, but I decided it was more fun to be able to save your game as “http://blackjax.pjhyett.com/PJ’sAwesomeGame” if you felt inclined instead of the standard hex string. Then you wouldn’t even have to bookmark the url, because how could you forget an address like that ;-)

I haven’t updated http://blackjax.pjhyett.com with the new code yet, but feel free to download the source here:

BlackJax.zip (144kb)

Blackjax 3.0

0 comments


Sorry, comments have been closed for this post.