Sunday, 3 July 2011

Open Source Game: TicTacToe Ver 1.00

Finally got ver 1.00 of my first game - TicTacToe completed. As usual, it's a NIB-less design. I have put everything in one "main.m" but it shouldn't be too difficult for you to split into separate files if required.

Link to full source code listed below, I tried to make the code looks tidy and put in as many comments as possible within limited time. Drop me some comments on the blog or email me if you need any further info.

Well, actually the 2 players mode has been fully working for a few days. It's just that in the single player mode, computer player wasn't "smart" enough until now.



Some information about the game:
1) I use "buttons" instead of "touch" events like the others
2) Originally I used NSMutableArray for "gameArray" (to store board status) and "checkWinArray" (to check each of the 8 possible winning conditions), but wasn't very comfortable about it. In the end both switched back to use simple arrays.
3) Original plan was to show a separate view for users to pick single/two player mode, but couldn't get it to work, so just use the UIAlertView.

Known issues/limitation:
1) Doesn't support device rotation "yet" --> will fix that later if I can find some time
2) Won't save application status if interrupted --> will fix that later if I can find some time
3) No music/sound --> I have to admit that I have read some examples from books/net about how to play music, but haven't actually try any, this will be for future versions.

I am not very sure if there's any memory leak as I am still not experienced with it, please let me know if you found any!! Please also kindly let me know if you found any bug or problem with it.

Oh yes, one more very important thing: So far, I wasn't able to beat the computer player in single player mode. Let me know if any of you can find a way to win her!!!

Enjoy!

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

Note: I quite like the "Take a kid fishing or hunting license" by Nicholas Vellios (http://www.vellios.com). To make it easier for people living in big cities like me, I slightly modified a bit and call it "Take your kids, family or love ones for a few hours of outdoor activity license"...ha ha...
Source Code for TicTacTow Ver 1.00 (Updated)

6 comments:

  1. Thank you for posting this, I am attempting to learn objective c and I am interested in making a tic tac toe game as well, this will be very helpful.

    ReplyDelete
  2. I fully support your license. ;)

    ReplyDelete
  3. Thanks Nick! Looking forward to see more open source projects on your site!

    ReplyDelete
  4. I just take ur project and modify it (hope u dont have any inconvenience). I can make it more beautiful and totally functional in landscape mode (but only in landscape, not rotate). And i add it in my app.

    I fix some problems too, and i win to the computer (u can try it, moves: 6,7,9,3)

    ;)

    ReplyDelete
  5. No problem for improving my code, please send me a copy so I can learn new stuff too, thanks!

    ReplyDelete
  6. Thanks for posting this....

    ReplyDelete