Exemplo n.º 1
0
        public bool CanProcess(ScoringStrategyAction Action)
        {
            switch (Action)
            {
            case ScoringStrategyAction.Player1Scored:
            case ScoringStrategyAction.Player2Scored:
                return(true);

            case ScoringStrategyAction.Player1Reduced:
                return(Player1.Point.Value > 0);

            case ScoringStrategyAction.Player2Reduced:
                return(Player2.Point.Value > 0);

            case ScoringStrategyAction.EnableTieBreak:
                if (_IsTieBreakEnabled)
                {
                    return(false);
                }
                if (_IsInTieBreak)
                {
                    return(false);
                }
                if (Player1.Point.Value != 0)
                {
                    return(false);
                }
                if (Player2.Point.Value != 0)
                {
                    return(false);
                }
                if (Player1.Game > 6 || Player2.Game > 6)
                {
                    return(false);
                }
                return(true);

            case ScoringStrategyAction.DisableTieBreak:
                if (!_IsTieBreakEnabled)
                {
                    return(false);
                }
                if (_IsInTieBreak)
                {
                    return(false);
                }
                if (Player1.Point.Value != 0)
                {
                    return(false);
                }
                if (Player2.Point.Value != 0)
                {
                    return(false);
                }
                return(true);

            default:
                throw new NopeException();
            }
        }
Exemplo n.º 2
0
 public bool CanProcess(ScoringStrategyAction Action)
 {
     return(States.Peek().CanProcess(Action));
 }
Exemplo n.º 3
0
 public void Process(ScoringStrategyAction Action)
 {
     States.Push(States.Peek().Process(Action));
     OnPropertyChanged("CanUndo", "CurrentState");
 }
Exemplo n.º 4
0
        public IScoringState Process(ScoringStrategyAction Action)
        {
            if (!CanProcess(Action))
            {
                throw new InvalidOperationException("Die Aktion kann nicht berechnet werden. Vorher mit CanProcess prüfen.");
            }

            switch (Action)
            {
            case ScoringStrategyAction.EnableTieBreak:
                return(new V1State(Player1, Player2, _IsInTieBreak, true));

            case ScoringStrategyAction.DisableTieBreak:
                return(new V1State(Player1, Player2, _IsInTieBreak, false));
            }

            PlayerState AffectedPlayer;
            PlayerState OtherPlayer;

            switch (Action)
            {
            case ScoringStrategyAction.Player1Scored:
            case ScoringStrategyAction.Player1Reduced:
                AffectedPlayer = Player1;
                OtherPlayer    = Player2;
                break;

            case ScoringStrategyAction.Player2Scored:
            case ScoringStrategyAction.Player2Reduced:
                AffectedPlayer = Player2;
                OtherPlayer    = Player1;
                break;

            default:
                throw new NopeException();
            }
            bool IsInTieBreak     = _IsInTieBreak;
            bool IsTieBreaEnabled = IsTieBreakEnabled;


            Action SetCompleted = delegate
            {
                AffectedPlayer.Game = 0;
                OtherPlayer.Game    = 0;
                AffectedPlayer.Set  = AffectedPlayer.Set + 1;
            };

            Action GameCompleted = delegate
            {
                IsInTieBreak         = false;
                AffectedPlayer.Point = new PointType(false, PointType.Zero);
                OtherPlayer.Point    = new PointType(false, PointType.Zero);

                if (_IsInTieBreak)
                {
                    SetCompleted();
                }
                else
                {
                    if (_IsTieBreakEnabled)
                    {
                        if (AffectedPlayer.Game == 6 && OtherPlayer.Game == 6)
                        {
                            SetCompleted();
                        }
                        else
                        {
                            AffectedPlayer.Game++;
                        }
                    }
                    else
                    {
                        if (AffectedPlayer.Game >= 5 && AffectedPlayer.Game >= OtherPlayer.Game + 1)
                        {
                            SetCompleted();
                        }
                        else
                        {
                            AffectedPlayer.Game++;
                        }
                    }
                }
            };

            switch (Action)
            {
            case ScoringStrategyAction.Player1Scored:
            case ScoringStrategyAction.Player2Scored:
                if (_IsInTieBreak)
                {
                    if (AffectedPlayer.Point.Value >= 6 && AffectedPlayer.Point.Value >= OtherPlayer.Point.Value + 1)
                    {
                        GameCompleted();
                    }
                    else
                    {
                        AffectedPlayer.Point = new PointType(true, AffectedPlayer.Point.Value + 1);
                    }
                }
                else
                {
                    switch (AffectedPlayer.Point.Value)
                    {
                    case PointType.Fourty:
                        switch (OtherPlayer.Point.Value)
                        {
                        case PointType.Advantage:
                            OtherPlayer.Point = new PointType(false, PointType.Fourty);
                            break;

                        case PointType.Fourty:
                            AffectedPlayer.Point = new PointType(false, PointType.Advantage);
                            break;

                        default:
                            GameCompleted();
                            break;
                        }
                        break;

                    case PointType.Advantage:
                        GameCompleted();
                        break;

                    default:
                        if (_IsTieBreakEnabled && AffectedPlayer.Game == 6 && OtherPlayer.Game == 6)
                        {
                            IsInTieBreak         = true;
                            AffectedPlayer.Point = new PointType(true, AffectedPlayer.Point.Value + 1);
                        }
                        else
                        {
                            AffectedPlayer.Point = new PointType(false, AffectedPlayer.Point.Value + 1);
                        }
                        break;
                    }
                }
                break;

            case ScoringStrategyAction.Player1Reduced:
            case ScoringStrategyAction.Player2Reduced:
                AffectedPlayer.Point = new PointType(false, Math.Max(AffectedPlayer.Point.Value - 1, 0));
                break;
            }

            switch (Action)
            {
            case ScoringStrategyAction.Player1Scored:
            case ScoringStrategyAction.Player1Reduced:
                return(new V1State(AffectedPlayer, OtherPlayer, IsInTieBreak, IsTieBreaEnabled));

            case ScoringStrategyAction.Player2Scored:
            case ScoringStrategyAction.Player2Reduced:
                return(new V1State(OtherPlayer, AffectedPlayer, IsInTieBreak, IsTieBreaEnabled));

            default:
                throw new NopeException();
            }
        }