Tic-tac-toe for Apple platforms. Written in Swift with SpriteKit and GameplayKit.
- Xcode 9
- Swift 4
Clone the repo and open the project in Xcode.
The game is designed to run on iOS, tvOS, and macOS by using a shared codebase for the core logic and SpriteKit for the gameplay and mechanics. The platform specific pieces are written using UIKit and AppKit.
The game logic centers are three distinct types. A TTTPiece
is an enum
with two possible states, X and O. A TTTPosition
is either empty or contains an associated piece. A TTTBoard
is composed of 9 position, all initially empty. As the game played, the empty positions on the board are filled with pieces until one player wins or the game ends in draw.
Building on top of the core types, the game play model is defined using GameplayKit
. This includes defining a player, what the game model looks like, and how the model changes using gameplay. The GKGameModelPlayer
, GKGameModel
, and GKGameModelUpdate
protocols are all conformed to by various classes in order to model the game.
There are two state machines there are built using GameplayKit. The scene state machine manages transitions between the menu and gameplay states. The gameplay state machine manages the moves made during the course of the game. This includes making moves for player X and O, checking for wins, and deciding whose move is next.