コード例 #1
0
        private GameLobby GameToGameLobby(Game game)
        {
            GameLobby gameL = new GameLobby();

            gameL.Name = game.name;
            GameLobbyPlayer owner = new GameLobbyPlayer();

            owner.Name    = game.owner.name;
            gameL.Owner   = owner;
            gameL.Players = new ObservableCollection <GameLobbyPlayer>();
            foreach (Player player in game.users)
            {
                GameLobbyPlayer newPlayer = new GameLobbyPlayer();
                newPlayer.Name = player.name;
                gameL.Players.Add(newPlayer);
            }
            gameL.Capacity = game.users.Count + "/" + game.maxPLayers;
            return(gameL);
        }
コード例 #2
0
        public void UpdateGameLobby(Game game)
        {
            if (this.Dispatcher.Thread == System.Threading.Thread.CurrentThread)
            {
                if (game == null)
                {
                    quitLobbyPopup();
                    return;
                }
                try
                {
                    gameLobby.Name = game.name;
                    GameLobbyPlayer owner = new GameLobbyPlayer();
                    owner.Name      = game.owner.name;
                    gameLobby.Owner = owner;
                    gameLobby.Players.Clear();

                    foreach (Player player in game.users)
                    {
                        GameLobbyPlayer newPlayer = new GameLobbyPlayer();
                        newPlayer.Name    = player.name;
                        newPlayer.IsReady = player.isReady;
                        gameLobby.Players.Add(newPlayer);
                    }
                    int c = 0;
                    for (int i = 0; i < gameLobby.Players.Count; i++)
                    {
                        GameLobbyPlayer newPlayer = new GameLobbyPlayer();
                        newPlayer.Name     = gameLobby.Players[i].Name;
                        newPlayer.IsReady  = gameLobby.Players[i].IsReady;
                        newPlayer.Disabled = game.owner.name == user.Username ? false : true;
                        lobbyPlayers[i]    = newPlayer;
                        c++;
                    }
                    for (int i = c; i < 8; i++)
                    {
                        if (lobbyPlayers.Count <= i)
                        {
                            lobbyPlayers.Add(new GameLobbyPlayer());
                        }
                        else
                        {
                            lobbyPlayers[i] = new GameLobbyPlayer();
                        }
                    }

                    if (gameLobby.Owner.Name == user.Username)
                    {
                        startGameButton.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        startGameButton.Visibility = Visibility.Collapsed;
                    }

                    if (currentScreen == Screen.game)
                    {
                        for (int i = lobbyPlayers.Count - 1; i >= 0; i--)
                        {
                            if (lobbyPlayers[i].Name == null || lobbyPlayers[i].Name == "")
                            {
                                lobbyPlayers.RemoveAt(i);
                            }
                        }
                        gameLobby.DeckSize = game.deck.cards.Count;
                        int numBooks = 0;
                        selectablePlayers.Clear();
                        foreach (GameLobbyPlayer lobbyPlayer in lobbyPlayers)
                        {
                            Player tmpPlayer = game.users.Find(player => player.name == lobbyPlayer.Name);
                            lobbyPlayer.HandSize = tmpPlayer.hand.cards.Count;
                            lobbyPlayer.Books    = tmpPlayer.books;
                            numBooks            += lobbyPlayer.Books;
                            if (lobbyPlayer.Name != user.Username)
                            {
                                selectablePlayers.Add(lobbyPlayer);
                            }
                        }
                        DisplayDeckAmount.Content = "Cards in sea: " + game.deck.cards.Count;
                        DisplayBookAmount.Content = "Books created: " + numBooks;
                        foreach (Player player in game.users)
                        {
                            if (player.name == user.Username)
                            {
                                user.Hand.Clear();
                                ranksAvaliable.Clear();
                                player.hand.cards = player.hand.cards.OrderBy(card => card.rank).ThenBy(card => card.suit).ToList();
                                foreach (Card card in player.hand.cards)
                                {
                                    bool found = false;
                                    foreach (CardRank rank in ranksAvaliable)
                                    {
                                        if (rank.Rank == card.rank.ToString())
                                        {
                                            found = true;
                                            break;
                                        }
                                    }
                                    if (!found)
                                    {
                                        CardRank newRank = new CardRank();
                                        newRank.Rank = card.rank.ToString();
                                        ranksAvaliable.Add(newRank);
                                    }
                                    user.Hand.Add(new LobbyCard(card.suit, card.rank));
                                }
                                break;
                            }
                        }
                        if (game.users[game.currentPlayer].name == user.Username)
                        {
                            selectingPlayer();
                        }
                        else
                        {
                            waitingTurn(game.users[game.currentPlayer].name);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                this.Dispatcher.BeginInvoke(new GameUpdateDelegate(
                                                UpdateGameLobby), new object[] { game });
            }
        }