A Simple Word Puzzle

A few weeks back my young son showed me some work that he’d been doing at school – constructing a simple word puzzle by hiding a few known words within a grid of letters. His approach to this was very simplistic – but got me thinking that writing an application to do the same would be trivial and thus something that could keep me busy on the bus trips to and from work.

One night to get started and then a few bus trips later and I’ve got the following:

Word Puzzle 1

The puzzle board itself is actually two ItemsControls layered on top of each other. The lower control has its items laid out using a UniformGrid and each item represents a letter tile. The topmost control superimposes the “solved” words on top of the lower grid. I originally tried doing this just be altering the style of the individual tiles – but this didn’t achieve the effect I was after and got overly complex when a single letter was used by multiple words.

            <Grid VerticalAlignment="Center" HorizontalAlignment="Center">
                <ItemsControl x:Name="letterItemsControl"
 ItemsSource="{Binding LetterStream}"
                            <UniformGrid Rows="{Binding Height}" Columns="{Binding Width}"/>
                <ItemsControl x:Name="wordItemsControl" ItemsSource="{Binding Words}"
                              ItemTemplate="{StaticResource WordSelection}">

Of course it was pointed out to me that having each letter tile rendered as a set of controls wouldn’t scale well at all. Sure enough, even at 20×20 things start to slow down. Rendering a grid at 100×100 is painfully slow – although to be fare you can’t read the letter tiles at that size either – and it wouldn’t be much fun looking for words on a 10000 letter grid. Whilst a better implementation probably lies down the path of creating a BoardControl that renders all the tiles as one geometry group, I just liked the idea of being able to easily apply styles to the letter tiles, word selection etc.

As it stands this isn’t really finished – but its probably as close as I’ll get. I showed it to my son – he was bored of it after about 30 seconds .

I’ve posted an XBAP version here.

2 thoughts on “A Simple Word Puzzle”

  1. I am very interested in your word puzzle game especially the way in which you are checking if the user is attempting to make some sort of “weird” selection – such as making a right angle. Are you willing to share/post the full code? Thank you.

Comments are closed.