Elementals

elementals

Elementals  is a Windows Phone games application which has four paper-based games: Noughts & Crosses (Tic Tac Toe), Hangman, Snakes and Ladders and Dots & Boxes.

Here is a link to the app: http://www.windowsphone.com/en-GB/store/publishers?publisherId=Subby

There is too much to cover in terms of code so I shall be showing you come snippets worthy of showing.

I created Elementals for my University dissertation whilst I was studying at the University of Bradford, England. It comprises of the following platform/technologies:

Windows Phone, C# and XAML.

Pretty box standard right? I chose C# because I began to get drawn to how easy yet powerful it is. Even today, I’m working as a Software Developer using C# and i’m always amazed at the design patterns and the architecture which you can implement for your super-sonic jaw-drobbing finger-licking software! Oh, you should know by the way, I find all software amazing! Even a helloWorld app!

Note: This was done during my time at University, optimisation and best practices in programming were being drip fed by none other than myself as the development of this project continued. Therefore, please consider this whilst reading some of the code that I paste :)

The lecturers at the University told us, the hygienically questionable students to come up with a project and present our ideas to our tutors which in turn will either accept or decline the proposal. Which makes perfect sense if you think about it – I could waltz right in University and propose an program that alerts “h1 br0, h0ws it g0iN?”. So I started to think, think hard. I wanted to do something out of the ordinary and something which the average student hasn’t attempted, and then it hit me like a wet trout slapping me across my face, a Windows Phone app with paper-based games! OK – so that doesn’t seem like the most exciting thing on the planet but, to me, at that time, it sounded like something that even Chuck Norris could not accomplish.

I started to plan and think how the game will be like and drew class diagrams to understand what each class will contain. I then started to think about the animation – cause’ there HAS to be some form of animation in a game right?…Right?

Main Screen

The main screen comprises of four tiles which if touched, navigate the user to the respective game. For animation, I wanted to randomly select one of four themes: Fire, Water, Wind and Earth. Each game is based on one of these themes and the main screen simply randomly selects of those themes and changes it’s background and animation accordingly.

The leafs oscillate from left to right continuously while falling. In order to program the logic of this, I simply implemented a finite state machine which was ran by a DispatcherTimer object running 30 times per second, which is the recommended amount.

The above code initialises each leaf within the  array and subscribes each leaf to an Event Handler.

When the user navigated to this page, I randomly selected a theme and kick-started the finite state machine for that theme. Below is the code for the leaf animation for the earth theme:

Yes – I know what you’re thinking:  “But, but, that’s all Hard Coded!”. It certainly is, and if I was to re-do this entire project, i’d most certainly go about it in a different way! I should use the phone’s Canvas.Height value to detect if the leaf has fallen beneath the phone’s screen, I should create a temporary variable within the for loops which helps me not to repeatedly do things like: leafLocation[i].Y ….Instead, I can just do: yAxis ….

Game Design

In terms of the how I implemented the games, I used a GameHelper class for each game which encapsulated functions such as, ChangeGo, Win, Draw, Lose, GetPoints, etc. This helped me constantly access the state of the game. If a player lost, I would call “NewGame();” for example to create a new game and reset all the objects currently in state.

Artificial Intelligence

The Noughts & Crosses game contained a lookup so to speak which allowed the CPU to detect which move was the best to play. At the time, this was a viable option and I wasn’t using a specific technique to solve the problem. For the Dots & Boxes game however, I created a Alpha Beta Pruning algorithm, with the help of my personal tutor, Peter Cowling and his research lab assistants Edward Powley and Daniel Whitehouse who are now all based in the University of York.

Alpha Beta Pruning is amazing. It creates a virtual scoring system and a board which looks in to the future. Given a particular state of the game, it decides which move is the best by applying a move for the opponent and then for itself. A lengthier and more definitive explanation of how it works can be found on Wikipedia.

Separated Games

Elementals cost 79p or 99 cents – I have however published each game individually with some ads. Click <here> to navigate to my profile page. If you have a Windows Phone, download them for free and let me know what you think :)

  • Client: University of Bradford
  • Date: Dec 11, 2013
  • Visit Site