Ejemplo n.º 1
0
        protected void OnMatchOver(DetectedThrow thrw)
        {
            ConvertAndSaveThrow(thrw, ThrowResult.MatchWon);
            Game.Winner = Game.PlayerOnThrow;

            OnMatchEnd?.Invoke();
        }
Ejemplo n.º 2
0
        protected override void OnThrowInternal(DetectedThrow thrw)
        {
            if (IsGameOver(thrw))
            {
                Game.PlayerOnThrow.GameData.SetsWon += 1;
                Game.PlayerOnThrow.GameData.LegsWon += 1;
                OnMatchOver(thrw);
                return;
            }

            if (IsSetOver(thrw))
            {
                OnSetOver(thrw);
                return;
            }

            if (IsLegOver(thrw))
            {
                OnLegOver(thrw);
                return;
            }

            if (IsFault(thrw))
            {
                OnFault(thrw);
                return;
            }

            Game.PlayerOnThrow.GameData.HandPoints += thrw.TotalPoints;
            Game.PlayerOnThrow.GameData.LegPoints  -= thrw.TotalPoints;
            scoreBoard.AddPointsTo(Game.PlayerOnThrow, thrw.TotalPoints * -1);

            OnHandOverDoublePlayersCheck(thrw);
        }
Ejemplo n.º 3
0
        public Image <Bgr, byte> ProjectionDrawThrow(DetectedThrow thrw)
        {
            var image = ProjectionBackgroundImage.Clone();

            DrawLine(image, thrw.FirstRay.RayPoint, thrw.FirstRay.CamPoint, projectionThrowRayColor, PoiThickness);
            DrawLine(image, thrw.SecondRay.RayPoint, thrw.SecondRay.CamPoint, projectionThrowRayColor, PoiThickness);
            DrawCircle(image, thrw.Poi, PoiRadius, poiColor, PoiThickness);
            return(image);
        }
Ejemplo n.º 4
0
 protected void OnFault(DetectedThrow thrw)
 {
     ConvertAndSaveThrow(thrw, ThrowResult.Fault);
     Game.PlayerOnThrow.GameData.LegPoints += Game.PlayerOnThrow.GameData.HandPoints;
     scoreBoard.SetPointsTo(Game.PlayerOnThrow, Game.PlayerOnThrow.GameData.LegPoints);
     ClearPlayerOnThrowHand();
     scoreBoard.CheckPointsHintFor(Game.PlayerOnThrow);
     TogglePlayerOnThrow();
 }
        protected override void OnThrowInternal(DetectedThrow thrw)
        {
            Game.PlayerOnThrow.GameData.HandPoints += thrw.TotalPoints;
            Game.PlayerOnThrow.GameData.LegPoints  += thrw.TotalPoints;

            scoreBoard.AddPointsTo(Game.PlayerOnThrow, thrw.TotalPoints);

            OnHandOverSinglePlayerCheck(thrw);
        }
Ejemplo n.º 6
0
        public override void OnThrow(DetectedThrow thrw)
        {
            if (IsOut(thrw))
            {
                ConvertAndSaveThrow(thrw, ThrowResult.LegWon);

                dbService.StatisticUpdateAddLegsPlayedForPlayers(Game.Id);
                dbService.StatisticUpdateAddLegsWonForPlayer(PlayerOnThrow, Game.Id);

                foreach (var player in Players)
                {
                    player.LegPoints = writeOffPoints;
                    scoreBoard.SetPointsToClassic(writeOffPoints, player);
                    scoreBoard.CheckPointsHintFor(player);
                }

                ClearThrows();

                TogglePlayerOnThrow();
                return;
            }

            if (IsFault(thrw))
            {
                PlayerOnThrow.LegPoints += PlayerOnThrow.HandPoints;
                scoreBoard.SetPointsToClassic(PlayerOnThrow.LegPoints, PlayerOnThrow);
                ConvertAndSaveThrow(thrw, ThrowResult.Fault);
                ClearThrows();
                scoreBoard.CheckPointsHintFor(PlayerOnThrow);

                TogglePlayerOnThrow();
                return;
            }

            PlayerOnThrow.HandPoints += thrw.TotalPoints;
            PlayerOnThrow.LegPoints  -= thrw.TotalPoints;
            scoreBoard.AddPointsToClassic(thrw.TotalPoints * -1, PlayerOnThrow);

            var dbThrow = ConvertAndSaveThrow(thrw, ThrowResult.Ordinary);

            PlayerOnThrow.HandThrows.Push(dbThrow);

            if (IsHandOver())
            {
                Check180();
                ClearThrows();
                scoreBoard.CheckPointsHintFor(PlayerOnThrow);
                TogglePlayerOnThrow();
            }
            else
            {
                PlayerOnThrow.ThrowNumber += 1;
                scoreBoard.SetThrowNumber(PlayerOnThrow.ThrowNumber);
                scoreBoard.CheckPointsHintFor(PlayerOnThrow);
            }
        }
Ejemplo n.º 7
0
        protected void ConvertAndSaveThrow(DetectedThrow detectedThrow,
                                           ThrowResult throwResult = ThrowResult.Ordinary)
        {
            var convertedThrow = new Throw(Game.PlayerOnThrow,
                                           detectedThrow.Sector,
                                           detectedThrow.Type,
                                           throwResult,
                                           (int)Game.PlayerOnThrow.GameData.ThrowNumber,
                                           detectedThrow.TotalPoints,
                                           detectedThrow.Poi,
                                           detectedThrow.ProjectionResolution);

            Game.Throws.Push(convertedThrow);
            Game.PlayerOnThrow.GameData.HandThrows.Add(convertedThrow);
        }
Ejemplo n.º 8
0
        protected void OnHandOverSinglePlayerCheck(DetectedThrow thrw)
        {
            ConvertAndSaveThrow(thrw);

            if (IsHandOver())
            {
                Check180();
                ClearPlayerOnThrowHand();
            }
            else
            {
                Game.PlayerOnThrow.GameData.ThrowNumber += 1;
                scoreBoard.SetThrowNumber(Game.PlayerOnThrow.GameData.ThrowNumber);
            }
        }
Ejemplo n.º 9
0
        protected Throw ConvertAndSaveThrow(DetectedThrow thrw, ThrowResult throwResult)
        {
            var dbThrow = new Throw(PlayerOnThrow,
                                    Game,
                                    thrw.Sector,
                                    thrw.Type,
                                    throwResult,
                                    PlayerOnThrow.ThrowNumber,
                                    thrw.TotalPoints,
                                    thrw.Poi,
                                    thrw.ProjectionResolution);

            dbService.ThrowSaveNew(dbThrow);
            return(dbThrow);
        }
Ejemplo n.º 10
0
        private void OnLegOver(DetectedThrow thrw)
        {
            ConvertAndSaveThrow(thrw, ThrowResult.LegWon);
            Game.PlayerOnThrow.GameData.LegsWon += 1;
            scoreBoard.AddLegsWonTo(Game.PlayerOnThrow);
            ClearPlayerOnThrowHand();

            foreach (var player in Game.Players)
            {
                player.GameData.LegPoints = Game.legPoints;
                scoreBoard.SetPointsTo(player, Game.legPoints);
                scoreBoard.CheckPointsHintFor(player);
            }

            TogglePlayerOnLegAndOnThrow();
        }
        public override void OnThrow(DetectedThrow thrw)
        {
            if (IsLegOver(thrw))
            {
                PlayerOnThrow.LegPoints = writeOffPoints;
                scoreBoard.SetPointsToSinglePlayer(writeOffPoints);

                ConvertAndSaveThrow(thrw, ThrowResult.LegWon);

                dbService.StatisticUpdateAddLegsPlayedForPlayers(Game.Id);
                dbService.StatisticUpdateAddLegsWonForPlayer(PlayerOnThrow, Game.Id);

                ClearPlayerOnThrowHand();
                scoreBoard.CheckPointsHintFor(PlayerOnThrow);
                return;
            }

            if (IsFault(thrw))
            {
                ConvertAndSaveThrow(thrw, ThrowResult.Fault);

                OnFault();
                return;
            }

            PlayerOnThrow.HandPoints += thrw.TotalPoints;
            PlayerOnThrow.LegPoints  -= thrw.TotalPoints;
            scoreBoard.AddPointsToSinglePlayer(thrw.TotalPoints * -1);

            var dbThrow = ConvertAndSaveThrow(thrw, ThrowResult.Ordinary);

            PlayerOnThrow.HandThrows.Push(dbThrow);
            if (IsHandOver())
            {
                Check180();
                ClearPlayerOnThrowHand();
            }
            else
            {
                PlayerOnThrow.ThrowNumber += 1;
                scoreBoard.SetThrowNumber(PlayerOnThrow.ThrowNumber);
            }

            scoreBoard.CheckPointsHintFor(PlayerOnThrow);
        }
Ejemplo n.º 12
0
        protected void OnHandOverDoublePlayersCheck(DetectedThrow thrw)
        {
            ConvertAndSaveThrow(thrw);

            if (IsHandOver())
            {
                Check180();
                ClearPlayerOnThrowHand();

                scoreBoard.CheckPointsHintFor(Game.PlayerOnThrow);
                TogglePlayerOnThrow();
            }
            else
            {
                Game.PlayerOnThrow.GameData.ThrowNumber += 1;
                scoreBoard.SetThrowNumber(Game.PlayerOnThrow.GameData.ThrowNumber);
                scoreBoard.CheckPointsHintFor(Game.PlayerOnThrow);
            }
        }
        protected override void OnThrowInternal(DetectedThrow thrw)
        {
            Game.PlayerOnThrow.GameData.HandPoints += thrw.TotalPoints;
            Game.PlayerOnThrow.GameData.LegPoints  += thrw.TotalPoints;

            scoreBoard.AddPointsTo(Game.PlayerOnThrow, thrw.TotalPoints);

            ConvertAndSaveThrow(thrw);

            if (IsHandOver())
            {
                Check180();
                ClearPlayerOnThrowHand();
                TogglePlayerOnThrow();
            }
            else
            {
                Game.PlayerOnThrow.GameData.ThrowNumber += 1;
                scoreBoard.SetThrowNumber(Game.PlayerOnThrow.GameData.ThrowNumber);
            }
        }
        public override void OnThrow(DetectedThrow thrw)
        {
            PlayerOnThrow.HandPoints += thrw.TotalPoints;

            scoreBoard.AddPointsTo(PlayerOnThrow, thrw.TotalPoints);

            var dbThrow = ConvertAndSaveThrow(thrw, ThrowResult.Ordinary);

            PlayerOnThrow.HandThrows.Push(dbThrow);

            if (IsHandOver())
            {
                Check180();

                ClearPlayerOnThrowHand();
            }
            else
            {
                PlayerOnThrow.ThrowNumber += 1;
                scoreBoard.SetThrowNumber(PlayerOnThrow.ThrowNumber);
            }
        }
Ejemplo n.º 15
0
 public abstract void OnThrow(DetectedThrow thrw);
Ejemplo n.º 16
0
        public override void OnThrow(DetectedThrow thrw)
        {
            if (IsGameOver(thrw))
            {
                ConvertAndSaveThrow(thrw, ThrowResult.MatchWon);

                dbService.StatisticUpdateAddLegsPlayedForPlayers(Game.Id);
                dbService.StatisticUpdateAddLegsWonForPlayer(PlayerOnThrow, Game.Id);

                dbService.StatisticUpdateAddSetsPlayedForPlayers(Game.Id);
                dbService.StatisticUpdateAddSetsWonForPlayer(PlayerOnThrow, Game.Id);

                InvokeEndMatch();
                return;
            }

            if (IsSetOver(thrw))
            {
                ConvertAndSaveThrow(thrw, ThrowResult.SetWon);

                OnSetOver();
                return;
            }

            if (IsLegOver(thrw))
            {
                ConvertAndSaveThrow(thrw, ThrowResult.LegWon);

                OnLegOver();
                return;
            }

            if (IsFault(thrw))
            {
                ConvertAndSaveThrow(thrw, ThrowResult.Fault);

                OnFault();
                return;
            }

            PlayerOnThrow.HandPoints += thrw.TotalPoints;
            PlayerOnThrow.LegPoints  -= thrw.TotalPoints;
            scoreBoard.AddPointsToClassic(thrw.TotalPoints * -1, PlayerOnThrow);

            var dbThrow = ConvertAndSaveThrow(thrw, ThrowResult.Ordinary);

            PlayerOnThrow.HandThrows.Push(dbThrow);

            if (IsHandOver())
            {
                Check180();
                ClearPlayerOnThrowHand();
                scoreBoard.CheckPointsHintFor(PlayerOnThrow);
                TogglePlayerOnThrow();
            }
            else
            {
                PlayerOnThrow.ThrowNumber += 1;
                scoreBoard.SetThrowNumber(PlayerOnThrow.ThrowNumber);
                scoreBoard.CheckPointsHintFor(PlayerOnThrow);
            }
        }
Ejemplo n.º 17
0
 protected bool IsSetOver(DetectedThrow thrw)
 {
     return(IsLegOver(thrw) && Game.PlayerOnThrow.GameData.LegsWon + 1 == Game.legs);
 }
Ejemplo n.º 18
0
 protected bool IsGameOver(DetectedThrow thrw)
 {
     return(IsSetOver(thrw) && Game.PlayerOnThrow.GameData.SetsWon + 1 == Game.sets);
 }
Ejemplo n.º 19
0
 protected abstract void OnThrowInternal(DetectedThrow thrw);
Ejemplo n.º 20
0
 protected bool IsLegOver(DetectedThrow thrw)
 {
     return(PlayerOnThrow.LegPoints - thrw.TotalPoints == 0 &&
            (thrw.Type == ThrowType.Double || thrw.Type == ThrowType.Bulleye));
 }
Ejemplo n.º 21
0
 private void OnAnotherThrow(DetectedThrow thrw)
 {
     GameProcessor.OnThrow(thrw);
 }
Ejemplo n.º 22
0
 protected bool IsGameOver(DetectedThrow thrw)
 {
     return(IsSetOver(thrw) && PlayerOnThrow.SetsWon + 1 == sets);
 }
Ejemplo n.º 23
0
 public virtual void OnThrow(DetectedThrow thrw)
 {
 }
Ejemplo n.º 24
0
 protected bool IsSetOver(DetectedThrow thrw)
 {
     return(IsLegOver(thrw) && PlayerOnThrow.LegsWon + 1 == legs);
 }
Ejemplo n.º 25
0
 protected bool IsFault(DetectedThrow thrw)
 {
     return(Game.PlayerOnThrow.GameData.LegPoints - thrw.TotalPoints == 1 ||
            Game.PlayerOnThrow.GameData.LegPoints - thrw.TotalPoints < 0 ||
            Game.PlayerOnThrow.GameData.LegPoints - thrw.TotalPoints == 0);
 }
Ejemplo n.º 26
0
 protected bool IsFault(DetectedThrow thrw)
 {
     return(PlayerOnThrow.LegPoints - thrw.TotalPoints == 1 ||
            PlayerOnThrow.LegPoints - thrw.TotalPoints < 0 ||
            PlayerOnThrow.LegPoints - thrw.TotalPoints == 0);
 }
Ejemplo n.º 27
0
 public void OnThrow(DetectedThrow thrw)
 {
     TakeSnapshot();
     OnThrowInternal(thrw);
 }