private async Task CheckPlayerSetup(ClientMessage route, WebSocket websocket) { command = "UpdatePlayerSetup"; bool playerSetupOK = true; if (!game.IsUserNameAvailable(route.Name)) { playerSetupOK = false; } else { game.AssignUserName(route.Name, route.From); game.AssignIcon(route.Icon, route.From); // the icon on pos route.Icon is not available availableIcons[route.Icon] = false; game.GetPlayer(route.From).waitingRoomState = WaitingRoomState.Ready; } // send setup result to the user's websocket await SendJSON(websocket, new { command, playerSetupOK }); // update other players' availableIcons list command = "UpdateAvailableIcons"; int readyPlayers = game.GetNumberOfReadyPlayers(); await DistributeJSONToWebSockets(new { command, availableIcons, readyPlayers }); }
public GameView(Durak game, int id) { this.game = game; variation = game.variation; List <Player> players = game.GetPlayers(); playerID = id; hand = players[id].GetPlayersHand(); if (prevDiscardedHeapValue != discardHeapSize) { discardHeapChanged = true; } prevDiscardedHeapValue = discardHeapSize; PlayerView playerView; List <PlayerView> pViews = new List <PlayerView>(); for (int i = 0; i < game.GetSizeOfPlayers(); i++) { playerView = new PlayerView(); playerView.numberOfCards = players[i].GetNumberOfCards(); playerView.isAttacking = (attackingPlayer == i); playerView.playerState = players[i].playerState; playerView.passport = players[i].passport; if (players[i].playerState == PlayerState.Winner) { passportGameOver = true; } if (variation == Variation.Passport && players[i].CheckIfAllCardsPassport()) { playerView.allCardsPassport = true; } pViews.Add(playerView); } playersView = pViews; trumpCard = deckSize == 0 ? new Card(game.GetTrumpCard().suit, (Rank)5) : game.GetTrumpCard(); attackingCards = game.GetBoutInformation().GetAttackingCards(); defendingCards = game.GetBoutInformation().GetDefendingCards(); takingCards = game.GetPlayer(defendingPlayer).IsPlayerTaking(); playerTurn = game.GetPlayersTurn(); gameStatus = game.gameStatus; }