Monday, September 26, 2011

Dice Emulator

The Merry Game of Floundering
The other day Caroline came home with a charity shop find - The Merry Game of Floundering* - which I'm sure we used to play as kids (although my Mum claims never to have heard of it).

All the pieces were there with the exception of one of the dice (it needs to two). So rather than search for another die I did what any self-respecting programmer would do, and knocked up a dice emulator in Python.

Thanks to the pygame library and Unicode characters U+2680 - U+2685 I was able to get a program together quickly which we then triggered using the Apple Remote (using Remote Buddy's Virtual Mouse behaviour). Simple as that!

dice.py
The program is presented below. Be aware, though, it makes some assumptions about running on my MacBook. If you're running it on non-1280x800 screen size you'll probably need to change the font sizes, and if you're running on a non-Apple system you'll probably need to change the font for the die characters (or go back to using ASCII numbers, as it was originally), and the location of the sound that is played when the dice is rolled. Also there is some code there to highlight special scores (doubles, and 6 and 1), which are specific to the Floundering game - take them out, or define your own. Enjoy!



[*] While searching for more information on the game I found someone selling a set on eBay as "The Messy Game of Floundering".