Sunday, 17 August 2014

Tic Tac Toe

There are plenty of free games on the App Store and Play Store. There are usually one or two catches with them though - they have ads to provide revenue, or they use in-app purchases to unlock extra content (or to simply remove the ads). I wanted to make something simple that was completely free, no strings attached. No ads. No IAPs.

I've been working on my own 2D Android game engine and most of my projects have been experiments revolving around it. One of the experiments was connecting to the Google Play Services to implement achievements and leaderboards. I decided to be clever about it and integrate it into the engine itself, to save the hassle of implementing it on a game by game basis later down the line. That turned out to be a bit of a mistake.

Because the underlying engine requires access to the services, any game that uses the engine must connect to the service. This means implementing something at a basic level. I didn't want to store any data locally so the easiest thing to do was have incremental achievements that are all handled by Google Play. Whenever they need to be incremented in the code it sends a call to the service, with the achievement ID, to increase progress made. The minimum number of achievements you are allowed is 5. For the game I was making, there wasn't a lot of variety to be had.

As you may have guessed from the title, Tic Tac Toe is a simple noughts and crosses game that can be played against the device or with a friend. And it's fairly easy to do from an art perspective, as my art tends not to be that good. I decided to go with a paper-drawn look. That meant my art could be very simplistic, and also look as if somebody had actually drawn it on a piece of paper.
The playable area of the game - currently Player 1's turn
Besides having to include Google Play, there weren't many other hurdles to overcome. The major one was that certain components of Eclipse had to be updated and in clicking update, Eclipse decided to delete itself. Fortunately once it was reinstalled and told where the workspace was, all of my projects were intact.

There were a few times that the game wouldn't actually end. All 9 squares would be occupied but the "Player x Wins!" text would not display. Initially this was because I wasn't checking to see if there was a tie, but there was an issue in the AI's code where it would check for a tie but then go on to try and take a move anyway, resulting in an infinite loop. After shuffling a few lines of code around this doesn't seem to happen any more.

In a previous project, when attempting to unlock achievements, or simply invoke the achievement screen, the game would crash on my phone which runs an outdated version of the Google Play Services. I had encapsulated that code in a try/catch statement, but it would continue to crash anyway. Here I modified the code so that in the try statement, it checks to see if the user is signed in and connected to the services first. If not, it will try to sign them in. If not successful there, it will then continue as normal but with the achievements not unlocked (which isn't a big deal since they probably don't work on other games for that version either).

I quite like the art style in this game and plan to use it in some more simple projects in the future.

Tic Tac Toe is available now in the Google Play Store for Android devices 2.2 and above.