public void SetupProperBoard() { foreach (var board in boardsOrderedByPlayerNumber) { board.gameObject.SetActive(false); } properBoard = boardsOrderedByPlayerNumber[GameManager.instance.GetPlayers().Count - 2]; properBoard.gameObject.SetActive(true); for (int p = 0; p < properBoard.GetComponent <BoardDDB>().playerNames.Length; p++) { properBoard.GetComponent <BoardDDB>().playerNames[p].text = GameManager.instance.GetPlayerNumber(p); } counters = new int[GameManager.instance.GetPlayers().Count]; countersEnabled = new bool[counters.Length]; for (int c = 0; c < counters.Length; c++) { countersEnabled[c] = false; counters[c] = 1000; properBoard.marcadorText[c].text = counters[c].ToString(); } playersReady = 0; counterRunning = false; currentReductionPerSecond = UnityEngine.Random.Range(minReductionPerSecond, maxReductionPerSecond); }
public static void GetUserBoard(string identityID, string boardID) { State.gameBoardID = ""; State.gameBoardIdentityID = ""; Debug.LogFormat("Retrieving board {0} for {1}", boardID, identityID); BoardDDB ddbBoard = new BoardDDB(); Board retrievedBoard = new Board(); Context.LoadAsync <BoardDDB>(identityID, boardID, (result) => { if (result.Exception == null) { ddbBoard = result.Result; State.gameBoardID = boardID; State.gameBoardIdentityID = identityID; retrievedBoard = ddbBoard.UserBoard; State.gameBoard = retrievedBoard; AddBoardMetric(metricType.play); State.gameState = GameState.boardData; State.TaskDone("GetBoardData"); Debug.LogWarning("Set gamestate to boardData"); } else { Debug.LogError("Unable to LoadAsync board " + boardID); State.TaskDone("GetBoardData"); Debug.LogError(result.Exception); } }); }
public static void AddBoardMetric(metricType metric) { if (State.gameBoardID == "" || State.gameBoardIdentityID == "") { return; } // Retrieve the ddbBoard BoardDDB ddbBoard = new BoardDDB(); Context.LoadAsync <BoardDDB>(State.gameBoardIdentityID, State.gameBoardID, (result) => { if (result.Exception == null) { ddbBoard = result.Result as BoardDDB; switch (metric) { case metricType.vote: // votes will be negative so we can sort-descending with most-voted first ddbBoard.Votes_D = ddbBoard.Votes_D - 1; ddbBoard.Votes_A = ddbBoard.Votes_A + 1; ddbBoard.VotesPlaysRatio = Math.Abs(ddbBoard.Votes_A) / (float)Math.Abs(ddbBoard.Plays_A); break; case metricType.play: // plays will be positive so we can sort-ascending with least-played first ddbBoard.Plays_D = ddbBoard.Plays_D - 1; ddbBoard.Plays_A = ddbBoard.Plays_A + 1; ddbBoard.VotesPlaysRatio = Math.Abs(ddbBoard.Votes_A) / (float)Math.Abs(ddbBoard.Plays_A); ddbBoard.WinsPlaysRatio = Math.Abs(ddbBoard.Wins_A) / (float)Math.Abs(ddbBoard.Plays_A); break; case metricType.win: // wins will be positive so we can sort-ascending with least-won first ddbBoard.Wins_D = ddbBoard.Wins_D - 1; ddbBoard.Wins_A = ddbBoard.Wins_A - 1; ddbBoard.WinsPlaysRatio = Math.Abs(ddbBoard.Wins_A) / (float)Math.Abs(ddbBoard.Plays_A); break; } Context.SaveAsync <BoardDDB>(ddbBoard, (res) => { if (res.Exception == null) { Debug.Log("User board metric " + metric + " incremented."); } }); } }); }
public static void SaveUserBoard(Board myBoard, string userBoardName) { State.TaskAdd("SaveUserBoard"); userBoardName = userBoardName.ToLower(); // Create DynamoDB wrapper BoardDDB ddbBoard = new BoardDDB(); string identityID = Identity.Credentials.GetIdentityId(); ddbBoard.IdentityID = identityID; ddbBoard.BoardID = System.Guid.NewGuid() + delimiter + userBoardName; ddbBoard.BoardName = userBoardName; ddbBoard.UserBoard = myBoard; ddbBoard.Votes_A = 0; ddbBoard.Votes_D = 0; // the plays are set initially to 1 because // the board is always played once during creation // this also prevents divide-by-zero errors ddbBoard.Plays_A = 1; ddbBoard.Plays_D = -1; ddbBoard.Wins_A = 0; ddbBoard.Wins_D = 0; ddbBoard.VotesPlaysRatio = 0f; ddbBoard.WinsPlaysRatio = 0f; string printJSON = ActorGameManager.SerializeGameBoard(myBoard); Debug.Log("Saving Board: " + printJSON); // Save the board Context.SaveAsync(ddbBoard, (result) => { if (result.Exception == null) { Debug.Log("Board saved to UserBoards table"); State.gameState = GameState.boards; SceneManager.LoadScene("boards"); State.TaskDone("SaveUserBoard"); } else { Debug.LogWarning("Board save to UserBoards table failed."); State.TaskDone("SaveUserBoard"); } }); }