November 2011
Beginner
238 pages
6h 19m
English
In the section “Making the First Move,” we saw a call to a method called checkWinner. In this section, we take a look at that method. For tic-tac-toe, we are using a brute force approach to see if we have a winner, by checking all the rows and columns for three repeating characters. We also need to check for a tie if there are no more places to move.
- (NSString*)checkWinner
{
//top row
if ([gameButton1.titleLabel.text isEqualToString:gameButton2.titleLabel.text] &&
[gameButton2.titleLabel.text isEqualToString:gameButton3.titleLabel.text])
return gameButton1.titleLabel.text;
//middle row
if ([gameButton4.titleLabel.text isEqualToString:gameButton5.titleLabel.text] && [gameButton5.titleLabel.text isEqualToString:gameButton6.titleLabel.text]) ...