public void renderVisualTree() { clearOldTree(); List <List <TournamentRound> > serverTree = tournament.getTree(); float roundHeight = 3f; //Should not have to be hardcoded here //Create appropirate y spacing in the rows int biggestLayerSize = serverTree.OrderByDescending(l => l.Count).ToArray()[0].Count; Dictionary <int, float> layerSizeToYIncrement = new Dictionary <int, float>(); int counter = 0; for (int i = biggestLayerSize; i > 0; i /= 2) { layerSizeToYIncrement.Add(i, Mathf.Pow(2, counter) * firstRowSpacing); counter++; } bool passedFinal = false; int singleLayerCounter = 0; for (int col = 0; col < serverTree.Count; col++) { float yIncrement = layerSizeToYIncrement[serverTree[col].Count]; List <VisualTournamentRound> visualCol = new List <VisualTournamentRound>(); float rowHeight = (serverTree[col].Count - 1) * yIncrement + roundHeight; float startY = -rowHeight / 2; for (int i = 0; i < serverTree[col].Count; i++) { Vector3 spawnPos = new Vector3(col * colSpacing, startY + yIncrement * i, 0); GameObject tempObj = Instantiate(gamePrefab, spawnPos, Quaternion.identity); VisualTournamentRound game = tempObj.GetComponent <VisualTournamentRound>(); game.init(serverTree[col][i], calcRoundType(passedFinal, singleLayerCounter)); visualCol.Add(game); if (serverTree[col].Count == 1 && passedFinal == false) { singleLayerCounter++; if (singleLayerCounter == 2) { passedFinal = true; } } } tree.Add(visualCol); } }
public static void playGame(int col, int row) { tree.getRound(col, row).forceRandomWinner(); List <TournamentRoundDTO> temp = new List <TournamentRoundDTO>(); foreach (List <TournamentRound> layer in tree.getTree()) { foreach (TournamentRound r in layer) { temp.Add(r.createDTO()); } } visualSingleton.updateRounds(temp.ToArray(), true); }