Ejemplo n.º 1
0
        public void PerformPlayerAction(Player player, ActionType actionType)
        {
            switch (actionType)
            {
            case ActionType.TakeSkat:
                SkatTaken = true;
                break;

            case ActionType.PlayHand:
                SetGameOption(player, player.Game.Option | GameOption.Hand);
                break;

            case ActionType.StartGame:
                StartGame(player);
                break;

            case ActionType.DoNotPlayHand:
                var gameOption = player.Game.Option & ~GameOption.Hand;
                if (player.Game.Type != GameType.Null)
                {
                    gameOption &= ~GameOption.Ouvert;
                }
                SetGameOption(player, gameOption);
                break;

            case ActionType.Bid:
                BidSaid = true;
                MoveNextBidValue();
                break;

            case ActionType.PassBid:
                player.BidStatus = BidStatus.Pass;
                foreach (var p in Players)
                {
                    if (p.Position == PlayerPosition.Rearhand && p.BidStatus != BidStatus.Pass)
                    {
                        p.BidStatus = BidStatus.Bid;
                        break;
                    }
                }
                BidSaid = false;
                break;

            case ActionType.HoldBid:
                BidSaid = false;
                break;

            case ActionType.PassHold:
                BidSaid          = false;
                player.BidStatus = BidStatus.Pass;
                foreach (var p in Players)
                {
                    if (p.Position == PlayerPosition.Rearhand && p.BidStatus != BidStatus.Pass)     // weitersagen
                    {
                        p.BidStatus = BidStatus.Bid;
                    }
                    else if (p.Position == PlayerPosition.Middlehand && p.BidStatus != BidStatus.Pass)     // hoeren
                    {
                        p.BidStatus = BidStatus.Accept;
                    }
                }
                break;

            default:
                break;
            }
            if (actionType == ActionType.PassBid ||
                actionType == ActionType.PassHold ||
                actionType == ActionType.Bid)
            {
                // find if all player have given up
                Player gamePlayer = null;
                var    cntPassen  = 0;
                foreach (var p in Players)
                {
                    if (p.BidStatus != BidStatus.Pass)
                    {
                        gamePlayer = p;
                        continue;
                    }
                    cntPassen++;
                }
                // all gave up
                if (cntPassen == 3)
                {
                    GamePlayer = Players[0];
                    GameValue  = new GameValue {
                        Score = 0
                    };
                    GameStarted = true;
                    foreach (var p in Players)
                    {
                        p.Cards.Clear();
                        p.Stitches.Clear();
                    }
                    Skat.Clear();
                    Stitch.Clear();
                    CurrentHistory.GamePlayerScore = 0;
                    CurrentHistory.GameValue       = 0;
                    SkatResult.History.Add(CurrentHistory);
                    SkatResult.EndedUtc = DateTime.UtcNow;
                }
                // two player gave up, remaing playing is the game player
                else if (gamePlayer != null && cntPassen == 2)
                {
                    if (gamePlayer.Position == PlayerPosition.Forehand && CurrentBidValue == 0)
                    {
                        gamePlayer.BidStatus = BidStatus.Bid;
                    }
                    else
                    {
                        GamePlayer  = gamePlayer;
                        GameStarted = false;
                        SkatTaken   = false;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public GameValue GetGameValue(MatadorsJackStraight spitzen, List <Card> stitches, List <Card> skat, int bidValue, bool giveUp)
        {
            bool schneider           = false;
            bool schwarz             = false;
            bool gamePlayerSchneider = false;
            bool gamePlayerSchwarz   = false;

            if (Type != GameType.Null)
            {
                var score = Card.GetScore(stitches, skat);
                schneider = score >= 90;
                schwarz   = stitches.Count == 30;
                if (!giveUp)
                {
                    if (stitches.Count == 0)
                    {
                        gamePlayerSchwarz = true;
                    }
                    gamePlayerSchneider = score <= 30;
                }
            }
            var gameValue = new GameValue();
            // check if bid value is exceeded considering schneider and schwarz
            var gameBidValue = GetBidValue(spitzen, schneider, schwarz);

            if (gameBidValue < bidValue)
            {
                int baseValue;
                if (Type == GameType.Null)
                {
                    baseValue = GetNullBaseValue();
                }
                else
                {
                    baseValue = GetGrandOrColorBaseValue();
                }
                gameValue.Score = baseValue;
                int factor = 1;
                while (gameValue.Score < bidValue)
                {
                    gameValue.Score += baseValue;
                    factor++;
                }
                var calc = factor == 1 ? $"{baseValue}" : $"{factor} x {baseValue}";
                gameValue.BidExceeded = true;
                gameValue.IsWinner    = false;
                gameValue.Score      *= -2;
                gameValue.DescriptionLabels.Add($"INFO_GAME_OVER_BID_1:{bidValue}");
                gameValue.DescriptionLabels.AddRange(GetGameAndOptionTextLabels());
                gameValue.DescriptionLabels.Add($"INFO_GAME_LOST_CALC_1_2:{calc}:{gameValue.Score}");
            }
            else
            {
                var isWinner = IsWinner(stitches, skat);
                if (!isWinner)
                {
                    schneider = false;
                    schwarz   = false;
                }
                string calc;
                var    gameLabels = new List <string>();
                int    baseValue;
                int    factor = 1;
                if (Type == GameType.Null)
                {
                    baseValue       = GetNullBaseValue();
                    gameValue.Score = baseValue;
                    gameLabels.AddRange(GetGameAndOptionTextLabels());
                }
                else
                {
                    gameLabels.Add(spitzen.With ? "TEXT_WITH" : "TEXT_WITHOUT");
                    gameLabels.Add($"INFO_PLAY_1_2:{spitzen.Count}:{spitzen.Play}");
                    factor = spitzen.Play;
                    if (Option.HasFlag(GameOption.Hand))
                    {
                        factor++;
                        gameLabels.Add($"INFO_HAND_FACTOR_1:{factor}");
                    }
                    if (Option.HasFlag(GameOption.Ouvert))
                    {
                        factor++;
                        gameLabels.Add($"INFO_OUVERT_FACTOR_1:{factor}");
                    }
                    if (schneider || gamePlayerSchneider)
                    {
                        factor++;
                        gameLabels.Add($"INFO_SCHNEIDER_FACTOR_1:{factor}");
                    }
                    if (Option.HasFlag(GameOption.Schneider))
                    {
                        factor++;
                        if (!schneider && !gamePlayerSchneider)
                        {
                            gameLabels.Add($"TEXT_SCHNEIDER");
                        }
                        gameLabels.Add($"INFO_SAID_FACTOR_1:{factor}");
                    }
                    if (schwarz || gamePlayerSchwarz)
                    {
                        factor++;
                        gameLabels.Add($"INFO_SCHWARZ_FACTOR_1:{factor}");
                    }
                    if (Option.HasFlag(GameOption.Schwarz))
                    {
                        factor++;
                        if (!schwarz && !gamePlayerSchwarz)
                        {
                            gameLabels.Add("TEXT_SCHWARZ");
                        }
                        gameLabels.Add($"INFO_SAID_FACTOR_1:{factor}");
                    }
                    gameLabels.Add(GetGameTextLabel());
                    baseValue = GetGrandOrColorBaseValue();
                }
                gameValue.Score = factor * baseValue;
                calc            = $"{factor} x {baseValue}";
                if (!isWinner)
                {
                    gameValue.Score   *= -2;
                    gameValue.IsWinner = false;
                    gameValue.DescriptionLabels.AddRange(gameLabels);
                    gameValue.DescriptionLabels.Add($"INFO_GAME_LOST_CALC_1_2:{calc}:{gameValue.Score}");
                }
                else
                {
                    gameValue.DescriptionLabels.AddRange(gameLabels);
                    gameValue.DescriptionLabels.Add($"INFO_GAME_WON_CALC_1_2:{calc}:{gameValue.Score}");
                }
            }
            return(gameValue);
        }