Tuesday, 29 July 2014

Word Score

I went for a long weekend away at Centre Parcs in April this year and played a needlessly long game of Scrabble. Part of the reason this game was so long was because people kept having to recalculate their scores. After returning home, I decided to work on an app for that, entitled Word Score. This has resulted in a published Android app and an experimental C++ console window version.

With Android, I am more familiar with pushing my own graphics to the screen. I never really used the layouts because there are a ton of different devices out this can mean designing different layouts for different devices. I'd much prefer to have a one size fits all design, using some kind of scaling system. Previously I had only had my phone, which only runs 2.2, to develop and test on, however I had recently purchased a tablet that was capable of running 4.4 meaning I could test on both the lowest and highest supported Android versions that I chose to target, and a small and large screen.
The coding itself was fairly straight forward. Each time the user updated the word they required a score for, a function called ParseText() would be called. In here, ParseScore() would get called for each letter in the word to add up the score of each letter, and then ParseLetters() would get called which checked if multipliers were enabled, and if so it would apply them to the score. After that, both the word and the score would get displayed on the screen.

ParseLetters() would get the score of the currently selected letter on the drop-down box (spinner), and if the letter was contained within the word the user gave then the multiplier score would be applied.

ParseScore() used a switch statement that would check against each character of the alphabet and return the score that the letter was worth.
The app as it appears on a 7" tablet.
After testing that the code was working, which took a bit of refining, I decided to add a couple of extra features - a list of recently looked up word and adverts to attempt to get a bit of revenue. Whilst this was something I had put a couple of days into, it wasn't something I wanted to charge for, so I decided to include adverts.

The Recent Words box is a simple string array that updates each time so that the latest word gets added and the rest get pushed down the list. I also decided to add the scores that each word was worth. As everything up to this point had just been done within the same class, I created a RecentWords class so each word could be stored as an object that had the string, flag up whether multipliers were enabled and the score.

Whilst the layouts for the tablet were relatively straight forward, getting it to work on the phone so there was enough space was more of a challenge. Once adverts were placed into the tablet, I discovered that there was not enough screen space on the phone. As such, adverts are not displayed on the phone. However looking over the code again, I'm not sure the solution I used actually removed them from all smaller devices, but instead merely removed it from lower end devices incapable of accessing Google Play.
The app on a lower-end phone
More recently, after becoming better versed in C++, I revisited the idea and created a simple console application of Word Score. It is missing the letter multipliers, however, mainly because I could not decide on a simple enough solution for how a user would input which letter they would like a multiplier enabled on (toggling the multiplier would be virtually the same code as toggling word multipliers).

The Android version is available to download on the Google Play Store.
The C++ source project is also available to download (written in VS2012)*.

*The source is CopyPasta++ because I got the name mixed up with my earlier C# project.