Ejemplo n.º 1
0
        public override ShotResult ValidateShot(IShot shot)
        {
            // 1. He can hit a red. (Both player)
            // Scenarios
            //  a. Fresh Hit (New Player)
            //  b. Color Followup (Old Player)
            // 2. He can hit a color (Both Players)
            // Scenarios
            //  a. Red followup (Old Player)
            //  b. Free Ball (New Player) **** // TODO
            //  c. ColorRundown (Both Players)
            var shotResult = ShotResult.Undetermined;

            if (ShouldHitColor(shot))
            {
                shotResult = ValidateColorHit(shot);
            }
            else if (shot.FirstTouchedBall.Is(BallTypes.Red))
            {
                shotResult = ShotResult.ValidShot;

                if (shot.BallsPotted.Length > 0 && shot.BallsPotted.All(ball => ball.Is(BallTypes.Red)))
                {
                    shotResult |= ShotResult.PlayerContinues;
                }
                else if (shot.BallsPotted.Length > 0 && shot.BallsPotted.Any(ball => !ball.Is(BallTypes.Red)))
                {
                    shotResult |= ShotResult.OpenentContinues;
                    shotResult |= ShotResult.InvalidShot;
                }
                else if (shot.BallsPotted.Length == 0)
                {
                    shotResult |= ShotResult.OpenentContinues;
                }
            }
            else if (shot.FirstTouchedBall.Is(BallTypes.None))
            {
                shotResult = ShotResult.InvalidShot | ShotResult.OpenentCan | ShotResult.AskToPlayAgain |
                             ShotResult.AcceptTable;
            }
            else if (!shot.FirstTouchedBall.Is(BallTypes.Red))
            {
                shotResult = ShotResult.InvalidShot | ShotResult.OpenentCan | ShotResult.AskToPlayAgain |
                             ShotResult.CanReRack;
            }

            ShotHistoryProvider.PushShotDetails(CreateShotHistory(shot, new GameResult()
            {
                IsSuccessful = true,
                Result       = shotResult
            }));
            return(shotResult);
        }
Ejemplo n.º 2
0
        public override IGameResult IsValidBreak(IShot shot)
        {
            var breakResult = base.IsValidBreak(shot);

            if (breakResult.IsSuccessful)
            {
                breakResult.Result = ValidateShot(shot);

                ShotHistoryProvider.PushShotDetails(CreateShotHistory(shot, breakResult));
            }

            return(breakResult);
        }