Managing the Game State
There’s one more bit of housekeeping to attend to before you can implement the AI algorithm: You need to keep track of the overall game state. This entails tracking when the game ends and issuing an alert to say who won. Call a method named checkForWin
after the imageClicked
function that you created in the previous section:
func imageClicked(reco: UITapGestureRecognizer) {// Other code in this method is left out for brevity checkForWin()}
Running your code at this point will cause an error because checkForWin
doesn’t exist yet, but you’ll create it shortly.
The checkForWin
method scans the game board for winning tile combinations:
func checkForWin(){ var ...
Get Learning Swift™ Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.