示例#1
0
        public async Task PlayCard(Player player, Color cardColor, int cardNumber, SchafkopfHub hub)
        {
            if (GameState.CurrentGameState == State.HochzeitExchangeCards && player == GameState.HusbandWife)
            {
                bool success = GameState.ExchangeCardWithPlayer(player, cardColor, cardNumber, GameState.Leader, hub, this);

                if (success)
                {
                    foreach (String connectionId in GetPlayingPlayersConnectionIds())
                    {
                        await hub.Clients.Client(connectionId).SendAsync(
                            "ReceiveSystemMessage", $"{GameState.HusbandWife.Name} und {GameState.Leader.Name} haben eine Karte getauscht"
                        );
                    }
                    await StartGame(hub);
                }
                else
                {
                    foreach (String connectionId in player.GetConnectionIds())
                    {
                        await hub.Clients.Client(connectionId).SendAsync("ReceiveError", "Du kannst deinem Mitspieler kein Trumpf geben!");
                    }
                }
                return;
            }
            if (GameState.CurrentGameState != State.Playing || player != GameState.PlayingPlayers[GameState.ActionPlayer])
            {
                foreach (String connectionId in player.GetConnectionIds())
                {
                    await hub.Clients.Client(connectionId).SendAsync("ReceiveError", "Du bist gerade nicht dran!");
                }
                return;
            }
            if (GameState.Trick.Count == 4)
            {
                await hub.TakeTrick();
            }
            (Card playedCard, string message) = GameState.PlayCard(cardColor, cardNumber, hub, this, player);
            if (playedCard == null)
            {
                foreach (String connectionId in player.GetConnectionIds())
                {
                    await hub.Clients.Client(connectionId).SendAsync("ReceiveError", message);
                }
                return;
            }
            await player.SendHand(hub, GameState.AnnouncedGame, GameState.GetTrumpColor());
            GameState.AddCardToTrick(playedCard, player);
            await GameState.Trick.SendTrick(hub, this, GetPlayingPlayersConnectionIds());
            if (GameState.LastTrick != null)
            {
                await SendLastTrickButton(hub, GetPlayingPlayersConnectionIds(), LastTrickButtonState.show);
            }

            if (GameState.Trick.Count < 4)
            {
                GameState.IncrementActionPlayer();
                await SendPlayers(hub);
            }
            else
            {
                GameState.ActionPlayer = GameState.PlayingPlayers.IndexOf(GameState.Trick.Winner);
                await SendPlayers(hub);
                await SendTakeTrickButton(hub, GetPlayingPlayersConnectionIds());
            }
        }