Grid

public class Grid

This class refers to the main game grid. It contains a 2-D array of smaller grids, called BattleGrounds

Note

The battleGrounds array is not mutable. This is because each BattleGround is unique and does not need to change.
  • This array contains the 9 BattleGround objects in which the players can place their X’s and O’s.

    Declaration

    Swift

    let battleGrounds: [[BattleGround]]
  • This tuple contains the row and column of the next battleground the player will be forced to play on, based on the last move)

    Declaration

    Swift

    var nextBattleground: (row: Int, column: Int)?
  • This computed property calculates which player’s turn it is based on the total count of X’s and O’s in the game.

    Declaration

    Swift

    var currentPlayer: Tile
  • This computed property is an 81 count array of all battleGrounds in the grid

    Declaration

    Swift

    var queryItems: [URLQueryItem]
  • This computer property stores the winner of the game, if there is one

    Declaration

    Swift

    var winner: Tile?
  • This initializer creates a fresh game with 9 empty battleGrounds

    Declaration

    Swift

    init()
  • This initializer takes an array of 81 Tile objects represented as URLQueryItem objects, and builds the battleGrounds array using them.

    Declaration

    Swift

    init(queryItems: [URLQueryItem])
  • This convenience initializer, taken from Apple’s sample Ice Cream Builder app, extracts the URLQueryItem array out of a MSMessage object.

    Declaration

    Swift

    convenience init?(message: MSMessage?)