void InitializeGames() { int spotUIIndex = 0; int localGameUIIndex = 1; // first GameUI is global UI SpotUI[] spotUIs = GetComponentsInChildren <SpotUI>(); GameUI[] gameUIs = GetComponentsInChildren <GameUI>(); LocalGame[,] localGames = new LocalGame[3, 3]; for (int boardRow = 0; boardRow < 3; boardRow++) { for (int boardCol = 0; boardCol < 3; boardCol++) { // a grid of spots represents each local board Spot[,] spots = new Spot[3, 3]; for (int spotRow = 0; spotRow < 3; spotRow++) { for (int spotCol = 0; spotCol < 3; spotCol++) { // each spot SpotUI spotUI = spotUIs[spotUIIndex]; Spot spot = new Spot( new Location(spotRow, spotCol), null, true); spotUI.Spot = spot; spots[spotRow, spotCol] = spot; spotUIIndex++; } } // each local game Location loc = new Location(boardRow, boardCol); LocalGame localGame = new LocalGame(spots, true, loc); localGames[boardRow, boardCol] = localGame; gameUIs[localGameUIIndex].Game = localGame; localGameUIIndex++; } } Player p1 = menu ? Settings.NewPlayer(true, true) : Settings.p1; Player p2 = menu ? Settings.NewPlayer(false, true) : Settings.p2; // initialize the global game, its view and its controller GlobalGame game = new GlobalGame(localGames, true, p1, p2, true); if (p1 is AI) { ((AI)p1).Game = game; } if (p2 is AI) { ((AI)p2).Game = game; } GetComponent <GameUI>().Game = game; GetComponent <GameController>().Game = game; globalGame = game; }