Tic Tac Toe and iOS MVC
So far, I've been writing a lot of basic iOS apps that uses only one button. On the storyboard, you can drag buttons (clickable objects) and labels (basic text) onto your view controllers so you can program what is being displayed or what happens when a certain button is clicked. My basic apps have just been changing colors/fonts or changing texts when buttons are pressed such as the Ninja Gold (which is tradition by now). Now today's assignment is Tic Tac Toe where there is a bit more logic. The first thing that I thought of was how to differentiate the buttons being clicked (as there 9 on the storyboard). There is a .tag attribute that can help with this, as I changed the sender tag of the 9 buttons from 1 to 9.
I linked all the buttons to a UIButton action outlet, with the tags being the only difference. Now, how do I determine a winner? I wrote all the possible ways of winning and I used sets to ID winners. For example, after every button clicked, each player has a 'moves array' that will take in that tag, and I wrote out all possible winning moves (8) and changed the arrays to sets so that I can check for if the players move array contains a winning combo. Anyways, one of the things I learned doing this assignment is definitely how much (and sometimes how little) an object from the storyboard has.
This weekend I'm planning on getting ahead on the assignments and learning about iOS MVCs.
This weekend I'm planning on getting ahead on the assignments and learning about iOS MVCs.
No comments:
Post a Comment