private async Task UpdateGameState() { BlackjackContractClient.GetGameStateOutput gameState = await this.client.Game.GetGameState(this.currentRoomId); UpdatePlayerView( () => this.gameState.DealerView, pv => this.gameState.DealerView = pv, this.PlayerPositionsContainer.Dealer.anchoredPosition3D, gameState.DealerHand ); this.gameState.DealerView.UIContainer.PlayerName.text = "Dealer"; this.gameState.DealerView.UIContainer.ActivePlayerMarker.SetActive(false); for (int i = 0; i < gameState.Players.Count; i++) { BlackjackContractClient.GetGameStatePlayerOutput playerState = await this.client.Game.GetGameStatePlayer(this.currentRoomId, gameState.Players[i]); int playerIndex = i; UpdatePlayerView( () => this.gameState.PlayerViews[playerIndex], pv => this.gameState.PlayerViews[playerIndex] = pv, this.PlayerPositionsContainer.Players[playerIndex].anchoredPosition3D, playerState.Hand ); this.gameState.PlayerViews[playerIndex].UIContainer.PlayerName.text = "Player " + (i + 1); this.gameState.PlayerViews[playerIndex].UIContainer.ActivePlayerMarker.SetActive(gameState.PlayerIndex == i); } }
public async Task UpdateGameState() { if (this.gameState.Stage == GameStage.Destroyed) { this.StateChanged?.Invoke(); return; } BlackjackContractClient.GetGameStateOutput updatedGameState = await this.client.Game.GetGameState(this.gameState.RoomId); if (this.gameState.Players == null || this.gameState.Players.Length != updatedGameState.Players.Count) { this.gameState.Players = new GameState.PlayerState[updatedGameState.Players.Count]; } this.gameState.Dealer.Address = (Address)updatedGameState.Dealer; this.gameState.Dealer.Hand = updatedGameState.DealerHand.Select(cardIndex => new Card(cardIndex)).ToArray(); //this.gameState.Dealer.Winning = (int) updatedGameState.DealerWinning; for (int i = 0; i < updatedGameState.Players.Count; i++) { BlackjackContractClient.GetGameStatePlayerOutput playerState = await this.client.Game.GetGameStatePlayer(this.gameState.RoomId, updatedGameState.Players[i]); if (this.gameState.Players[i] == null) { this.gameState.Players[i] = new GameState.PlayerState(); } this.gameState.Players[i].Address = (Address)updatedGameState.Players[i]; this.gameState.Players[i].Hand = playerState.Hand.Select(cardIndex => new Card(cardIndex)).ToArray(); this.gameState.Players[i].Bet = (int)playerState.Bet; //this.gameState.Players[i].Winning = (int) playerState.Winning; this.gameState.Players[i].ReadyForNextRound = playerState.ReadyForNextRound; } this.StateChanged?.Invoke(); }