public void RestartGame() { foreach (CellGUI cellGUI in MatchCells.Values) { cellGUI.SetPlayer(null); } boardScore = CellValue.None; NetworkIdentity[] keys = new NetworkIdentity[matchPlayerData.Keys.Count]; matchPlayerData.Keys.CopyTo(keys, 0); foreach (NetworkIdentity identity in keys) { MatchPlayerData mpd = matchPlayerData[identity]; mpd.currentScore = CellValue.None; matchPlayerData[identity] = mpd; } RpcRestartGame(); startingPlayer = startingPlayer == player1 ? player2 : player1; currentPlayer = startingPlayer; }
public void CmdMakePlay(CellValue cellValue, NetworkConnectionToClient sender = null) { // If wrong player or cell already taken, ignore if (sender.identity != currentPlayer || MatchCells[cellValue].playerIdentity != null) { return; } MatchCells[cellValue].playerIdentity = currentPlayer; RpcUpdateCell(cellValue, currentPlayer); MatchPlayerData mpd = matchPlayerData[currentPlayer]; mpd.currentScore = mpd.currentScore | cellValue; matchPlayerData[currentPlayer] = mpd; boardScore = boardScore | cellValue; if (CheckWinner(mpd.currentScore)) { mpd.wins += 1; matchPlayerData[currentPlayer] = mpd; RpcShowWinner(currentPlayer); currentPlayer = null; } else if (boardScore == CellValue.Full) { RpcShowWinner(null); currentPlayer = null; } else { // Set currentPlayer SyncVar so clients know whose turn it is currentPlayer = currentPlayer == player1 ? player2 : player1; } }
public void UpdateWins(SyncDictionary <NetworkIdentity, MatchPlayerData> .Operation op, NetworkIdentity key, MatchPlayerData matchPlayerData) { if (key.gameObject.GetComponent <NetworkIdentity>().isLocalPlayer) { winCountLocal.text = $"Player {matchPlayerData.playerIndex}\n{matchPlayerData.wins}"; } else { winCountOpponent.text = $"Player {matchPlayerData.playerIndex}\n{matchPlayerData.wins}"; } }