Tuesday, 12 July 2011

Open Source Game: TicTacToe Ver 2.00

After about a week's hard work, I finally merged TicTacToe Ver 1 with the multi-view switching project and created a updated version of TicTacToe called Ver 2.00 which has multiple view controllers. Some high level information as below.

  1. Instead of "everything in single main.m file" as in Ver 1, Ver 2 is splited into different files.
  2. There are total of 4 View Controllers. The main one only in charge of switching between the 3 child view controllers. The 3 child view controllers are Intro, GamePlay and Ending. Each looks after different parts of the game. 
  3. Added 3 different difficulty levels for single player mode: beginner, advanced and expert. In beginner mode, computer will always play randomly. Advanced mode is with the 2 special conditions disabled. Expert mode has those conditions included. 
  4. Intro View Controller looks after collect info about single/two player mode and the 3 difficulty levels.
  5. GamePlay View Controller mostly remain unchanged from Ver 1 except now it highlights the winning row at the end.
  6. Ending View Controller shows the final score/result, and ask player to choose whether try again or start a new game.
  7. Also created a new class "GameData" to store all game related data. This isolates the game logic and data, plus makes it easier to handle the data, in case say need to export/store the data into file system or whatever other purpose.
Another thing I learned, was to always use "@class xxxxclassname" in ".h" header files to reference other classes, only use "#import" in the ".m" files to avoid looping declaration errors.

Original plan was to use this as practice and build a simple multi-view template/platform so that I can further expand it into more complicate projects in the future.

However, I felt like been punched on the face after I did a quick run using "Instruments". As shown below it's leaking memory quite badly - see the purple little bars on top of the screen.

Don't have much knowledge about how to use "Instruments" to work out which part is leaking yet, so there's surely still a lot of things to learn before I can build more complicate stuffs.

Any way, if any of you still interested in the "leaky" TicTacToe V2", the link is below.

[UPDATE 2] Please see this post for TicTacToe V2.1 (Memory Leak Fixed)

TicTacToeV2

No comments:

Post a Comment