示例#1
0
        //returns null if nothing hit
        //synchronized with UI (if animation time attached to GetSongCurrentTime)
        private ISequenceElement SetPoints(IPlayer player, TimeSpan hitTime, PlayerAction playerAction)
        {
            var alreadyHit = player.PlayerID == PlayerID.Player1 ? _p1AlreadyHit : _p2AlreadyHit;

            SeqElemType      type       = GameHelper.PlayerActionToSeqElemType(playerAction);
            ISequenceElement hitElement = Song.GetClosestTo(player.Difficulty, hitTime, type, alreadyHit);

            if (hitElement == null)
            {
                SetLifePoints(player, -GameConstants.WrongMomentOrActionLifePoints);
                return(null);
            }

            if (!hitElement.IsBomb)
            {
                double diff = Math.Abs(hitElement.Time.TotalSeconds - hitTime.TotalSeconds);

                if (diff <= GameConstants.BestHitTime)
                {
                    player.Points += GameConstants.BestHitPoints;
                }
                else if (diff <= GameConstants.MediumHitTime)
                {
                    player.Points += GameConstants.MediumHitPoints;
                }
                else if (diff <= GameConstants.WorstHitTime)
                {
                    player.Points += GameConstants.WorstHitPoints;
                }

                SetLifePoints(player, GameConstants.HitLifePoints);
            }
            else
            {
                SetLifePoints(player, -GameConstants.BombLifePoints);
            }

            alreadyHit.Add(hitElement);
            return(hitElement);
        }