When you play Hangman with a computer, the computer needs a way to find puzzles for you to solve. When I first wrote my Hangman game, I included several themes, each with a pre-written list of puzzles. Later, I devised a way so that users could embed their own custom puzzles, with encrypted URLs so they could be emailed to friends (see Custom Hangman Puzzles for Valentine’s). Now there’s a way to point to a favorite Twitter account, and use tweets as the source for puzzles.
I call this game-ification: turning user-generated content into a game. My first project was using Flickr photos as puzzles for my Concentration game (see Game-ifying Flickr via Concentration. I thought Twitter’s 140-character limit would be a good fit, but it turns out 140-character puzzles are uninteresting, partially because with that many letters they are too easy to solve. So, I implement a limit of 100 characters. I’d prefer even shorter puzzles, but most tweets are longer. I also limit the number of different letters used. A puzzle with 22 or more different letters is impossible to lose, since it takes 5 wrong guesses to lose. Thus, I use only tweets with 17 different letters, or fewer. I also replace all links with “«»”. Twitter now converts links to “t.co” URLs, which are shorter but made up of gibberish.
The program is written in PHP, using Twitter’s Search API. The great thing about this API is there is no need to sign up; no keys are needed. They also offer more robust APIs (REST API and Streaming API), but they would be overkill. The hardest part was finding a regex (regular expression) to match URLs. Because using the preg_split function with PREG_SPLIT_DELIM_CAPTURE works funny if you have sub-expressions, I settled for /\b(HTTPS?\:\/\/[a-zA-Z0-9\-\.\/\?\&\=]+)\b/.
To play, you can enter a Twitter user ID on the Hangman home page, or just add “?twitter=username” to the URL. (Do not mix with themes.) For example, try using tweets from kathygriffin (Kathy Griffin) or theonion (The Onion) or DRUNKHULK (Drunk Hulk).