I have finally completed a small game project: Tic Tac Toe!
Because of the awesomeness that is Unity it is available on the web, however it is currently hosted on my own tiny server so this might be a bit slow and access to it might be intermittent.
Over the last few weeks I stopped posting game updates and focused on getting a VERY small game project done. The result was this Tic Tac Toe implementation. I decided to finish the simplest thing possible and I am happy with that choice. I also decided to accept help from a great artist friend of mine in order to finish. Now that it is basically done I thought I would chat through a bit of how it was made for those interested.
I was really excited to do an iPhone project but told myself I couldn’t spend money on it until I could finish a project using just the simulator. In roughly 8-12 hours I wrote a version of Tic Tac Toe that looked roughly like the Unity one that I completed later. Only the main board was working and only 2 player (no A.I.). At this point in the project another artist friend of mine bugged me to try out Unity. In 4 hours I caught up to where I was and it looked like it would go even faster in Unity AND it would give me the ability to have an OS X, Windows, Web and iPhone version! So I happily switched.
Tic Tac Toe in Unity
Phase 1 – Play board and scoring (4-8 hours)
The first thing I did was create a grid of 9 buttons and a storage array in to say what buttons were set. You can pass a GUI.Button an image so based on what space was taken I would select one of the button images. After this worked, I wrote some code to see if an entire row, column or diagonal was filled and then I would score points for that row. Next I added in detection for a draw. Finally I wrote some code to display the score and had a basic Tic Tac Toe game going with myself.
Phase 2 – Functionality and A.I. (4-8 hours)
With the basic game running I was moving into new territory for this code (I had already done the above in xcode). I started with simple A.I. Easy – Pick a random open space. Medium – Win if you can, block other player from winning, random. Hard – Same as medium. Then I went through and enabled a turn indicator (lights up X or O for whose turn it is), reset board button, reset score button and sliders for 1 player/2 players and easy/medium/hard difficulty.
Phase 3 – “Polish” and audio (4 – 8 hours)
My final phase of work on the demo was finishing the audio and making all of the graphics look great (alignment, correct textures, etc.). To customize sliders I had to use the GUISkin class and I noticed that all of the button, box, label and slider classes all have padding and borders on them. This is what was causing my misalignment. After removing those all I needed to do was override the slider and slider thumb textures and my application looked great! Audio was probably the most fun and surprising part of making the game for me. I used the terminal “say” command to output the generated speech to an audio file. Adding this and a button press file from this site and my audio was complete.
I don’t even think I used Unity in the way it was intended and I still found it very easy to use!
Thoughts on building Tic Tac Toe
I’m very happy that I picked such a small project and actually finished it. The project took a total of 12-24 coding hours and roughly 4-5 art hours. Had you asked me before starting how long Tic Tac Toe would take and I probably would have said 4-8 hours. Without polish that was true, but to actually “finish” the game it took three times as long. The range is because I didn’t journal my time working on the game. If I had to pick a number I would say the project took 24 hours or three full-time working days including the time to learn Unity. This information will help me plan my future projects to make sure that they are accomplish-able. I will probably post more intermediate progress steps on future projects.
If people are interested in the source code or a tutorial on this please let me know in the comments and I will write-up a follow-up post, otherwise I will be happily working on the next game.
Thanks for posting these details. Unity is something I should really try out at some point. Now that you can try it for free, I have no excuse not to at least look at it. 🙂
This is a pretty nice little game you made, I actually ended up playing it for at least 15+ minutes or so on medium diffulty 🙂
I would be very interested in seeing the source for this or a tutorial if you’re still interested in writing something like that 🙂
I’m quite new to programming and Unity myself, so everything that relates to java/programming for unity is of interest to me 🙂
Also, I am looking forward to seeing the results of your next game 🙂
Keep up the good work!
Thanks for the feedback tastygraph. I do plan on returning to this code for a tutorial but two things will delay it a little:
Given that this was my first unity project and I did not read the manual, I think I should have another project under my belt before doing a tutorial. Check back for more! If you are interested in the code without a tutorial I would email it to you.
Very impressive! I would also very much like to see the source code.
The fact that you’re using Unity in a way that others may not be is interesting. Even without a full-blown tutorial I think the source would be more useful to the community than you may think.
Glad to hear this may be of some interest to the community, that is probably the most encouraging thing I could read. My thoughts on doing a tutorial are that I would rather do it “right” and take the time to do it well but as a result you may have to wait a little while before I do the tutorial.
Did you end up releasing the source code for the iphone version of tic tac toe? let me know..
I haven’t yet but I am hoping to soon (within the next two weeks). I’m trying to put together a the unity project and a video tutorial on it. Might be over kill but thought I would give it a go.
Thanks.. much appreciated.. keep me posted..
Great game, congrats!
I would be very interested in any tutorials you could make regarding this game. It would be a great way for me to get started.
For those interested I have posted the tutorial with a link to a video and the source code as well here:
nice tutorial, can your create tutorial how to make game like bejeweled?
Thanks for taking a look at the tutorial! Due to time limitations I don’t think I will be doing a bejeweled like game in the future. If more people are interested in this please let me know and I will put it in the queue when I do find time for more tutorials in the future.
Thanks again, Jaysen