Click here to Skip to main content
13,900,598 members
Click here to Skip to main content
Add your own
alternative version


19 bookmarked
Posted 5 Jan 2006

WURDZ, an addictive word game - make words from random letters!

, 5 Jan 2006
Rate this:
Please Sign up or sign in to vote.
Written using pure C# WinForms, WURDZ is a completely new idea in the world of word games! This will be one game which will be as much fun to play as it will be to study its code, if not more. You make meaningful words from a random stream of letters, and score points.


After playing scrabble, I always wanted to be the inventor of a new word game (okay, you can laugh). New, meaning an idea not thought of before. There are a zillion word games out there, but not many offer literally infinite never-repeating scenarios like scrabble. No two scrabble games are the same. I dreamt of inventing something like that.

WURDZ is my feeble attempt at it. I seriously don't believe that such a noble ambition can be truly fulfilled at first try. So guys out there - please give me a shout if you have already seen something like this before, or with ideas and suggestions that will make this game unique.

The idea is simple - there will be a random stream of never ending letters. The player will use the random letters to create words. To make the game challenging, it has to be multiple words at the same time - so that a player needs to juggle and weigh where to put the next random letter. Once a meaningful word has been constructed - the player will be rewarded with points. The game will also have a resemblance with TETRIS - meaning, the more letters you place, the more restricted for space you will become - and only if you make a correct word, you will regain the space back. So, double reward for making a word - points and space!

That was my vague idea when I first clicked on "New Project..." in Visual Studio 7.0...

How to play

I will not use this article as a help manual for the game. For that, I have spent an hour writing the rules of the game in the HELP.TXT that comes with the game. Rather, I will use this article to highlight the interesting aspects of the code, befitting a CodeProject article.

Points about the code

Any word game writer faces most of these issues described below at some time or the other.

Random letters

Not only are my letters random (to the extent of pseudo-randomness that computer algorithms allow), but I faced the problem of providing a fair mix of vowels and high frequency alphabets. For example, if a 'Q' turns up 4 out of 10 times, that will not be much helpful. After you get a 'P', 'G' and 'T', you are probably desperately looking for a vowel. If the game cannot provide you with a timely vowel, you will soon get frustrated. How to solve this problem? Simple - look at the scrabble's sack of tiles. What do you see? 9 'A'-s, X 'B'-s, and so on. The ratio of the number of times you place an alphabet in your sack determines how frequently a particular letter will appear. I began with that proportion. Then I found out that for WURDZ, that was a good starting point, but not enough. As WURDZ has more simultaneous openings than scrabble, I need, for example, more 'Z'-s than only 1. So I multiplied some low frequency numbers by 4 or 5 and some high frequency numbers by 1.5 or 2.

The implementation is simple - declare an array of characters containing all the letters in the right quantities as explained above. Then run a "scramble" loop thousands of times to make your original array (where you will pick from later) totally scrambled. Then, when you need a random letter, generate a random number and return the letter at that index.

Dictionary and encryption

Age old problem - huh? How to sense a correct English word? You need a dictionary. I took it from NETWORDZ, the online scrabble game, which provides you with a giant text file, one word per line. I needed all meaningful words of length 3 through 8 (that is the length range supported by WURDZ). So I wrote programs to break the list into individual sub lists of same length - 6 lists now, each containing words of the same length, 3 through 8. Then, specifically for the purpose of WURDZ, I do not need CATAPULT in the 8 letter list, because it starts with CAT, and as soon as the player constructs CAT, he will be awarded points. So I wrote another program to shorten each dictionary file by eliminating words that share the beginning with some shorter word. Now, I have my dictionary files ready - 6 files. I will simply use an ArrayList to load them. As for checking the existence of a word, ArrayList.Contains() is quite efficient. If I need to check if "SUGT" exists, I call Contains() on the ArrayList containing words of length 4 only - so the search time is minimized.

So, where does the question of encryption come? You need to ship these dictionary files with the game, and to maintain some developer's clothing, you will probably not want the user to browse to the game folder, open the TXT files containing the words, add his or her own fancy words, and fool the game. I used the .NET encryption - decryption mechanism. Look at this article. I encrypted each of the 6 files using this method. I used different keys, and named the files with the keys. In the WURDZ code, I wrote the decryption routine - using the file name (not the extension) as the key. I used the extension to let the game find out words of what length are contained in this file. So a file with name ")_(=!^`{.F5@O0+" means that it contains words of length 6 (the length of its extension) and it can be decrypted using the key ")_(=!^`{". The user will see meaninglessly named binary files which he/she cannot view or edit.

Drag Drop of controls on a WinForm after dynamic creation

The basic requirement of this game is that the user needs to drag a letter tile to one of the four vertical slots. With the game timer producing one new letter every second, maintaining drag state was never going to be easy. If you see the mouse-down, mouse-move, and mouse-up handlers for the buttons that I create dynamically to behave as letter tiles, you will know the technique. Focus on the blocks of code that are dependent on the bDragging variable - the rest are not related to dragging but to game functionality.

I faced a problem - with just the pieces of code I just mentioned, dragging was happening, but while dragging, if you moved the mouse with a jerk (or very fast), the dragged button was not following the cursor. Suddenly you lost the button. Slow dragging was OK. I solved this problem in a round about way - I handled the form's mouse-move event this time (as opposed to the button's mouse-move event). If bDragging is true, I just repainted the dragged button at the new mouse location - and now even if you move the mouse around using a supersonic jet plane, the dragged button will hang on to you!


I needed many timers! The Threading.Timers class was a disappointment. Somehow, it ends up in disabling other timers. I have used only Timers.Timer. The blinking effect (after a correct word is created) uses a timer. Once you place a letter tile, the game gives you up to four seconds to remove it. In those four seconds, it draws yellow boundaries around the letter, to visually convey that "you can remove me now before it is too late". That implementation uses a timer. There is a helpful comment text at the bottom - it keeps on relaying what happened. But it must revert back to some meaningful text after the displayed information loses context. A timer has been used for that purpose. In addition to all these, the game is controlled by a master timer.

Other interesting points

The code will show:

  1. How to fit a picture in a picture box without stretching or skewing it (I learnt this technique by Googling) - in the About dialog box.
  2. How to maintain a binary high scores data file.
  3. How to dynamically place buttons/ controls based on screen size.
  4. How to create controls at runtime and control their behavior.


I borrowed the letter icons from

My wife helped me by testing the game and suggesting great ideas!


Please send me feedback and suggestions so that I can improve this game.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Koushik Biswas
Architect Yahoo! Inc
United States United States
Koushik is an Architect who also manages a team of developers and architects at Yahoo Cloud Organization, including Media Content Serving and Storage. An Electronics Engineer from Jadavpur University, he has been a consultant throughout most of his career. Apart from spending time with work and projects, he loves playing cricket, listening to old songs, watching science fiction movies, camping and fishing, all kinds of food, sea beaches and his gas grill.

You may also be interested in...

Comments and Discussions

GeneralMy vote of 4 Pin
Jordan Wilde24-Jan-13 11:58
memberJordan Wilde24-Jan-13 11:58 
QuestionDictionary Pin
agprathiba6-May-11 20:05
memberagprathiba6-May-11 20:05 
GeneralMy vote of 4 Pin
agprathiba6-May-11 20:02
memberagprathiba6-May-11 20:02 
GeneralLicense regd Pin
AlwaysACreator3-Jul-09 23:54
memberAlwaysACreator3-Jul-09 23:54 
QuestionOther games like this? Pin
rrrado11-Nov-08 2:05
memberrrrado11-Nov-08 2:05 
GeneralA couple of thoughts Pin
Sean Michael Murphy5-Jan-06 10:48
memberSean Michael Murphy5-Jan-06 10:48 
GeneralRe: A couple of thoughts Pin
Koushik Biswas6-Jan-06 9:00
memberKoushik Biswas6-Jan-06 9:00 
GeneralRe: A couple of thoughts Pin
mausum20-Sep-07 1:31
membermausum20-Sep-07 1:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05 | 2.8.190306.1 | Last Updated 5 Jan 2006
Article Copyright 2006 by Koushik Biswas
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid