Ejemplo n.º 1
0
        public static void AddTimeToNotes(UIElementCollection notes, SeqElemType elemType, double top)
        {
            #if DEBUG_TIMING
            TextBlock tb = new TextBlock()
            {
                FontSize = 20, Text = String.Format("{0:N2}", top / GameUIConstants.PixelsPerSecond)
            };
            Canvas.SetTop(tb, top);
            switch (elemType)
            {
            case SeqElemType.LeftArrow:
                Canvas.SetLeft(tb, GameUIConstants.LeftArrowX);
                break;

            case SeqElemType.DownArrow:
                Canvas.SetLeft(tb, GameUIConstants.DownArrowX);
                break;

            case SeqElemType.UpArrow:
                Canvas.SetLeft(tb, GameUIConstants.UpArrowX);
                break;

            case SeqElemType.RightArrow:
                Canvas.SetLeft(tb, GameUIConstants.RightArrowX);
                break;
            }
            notes.Add(tb);
            #endif
        }
Ejemplo n.º 2
0
        public static void GenerateSequence(Random randomGenerator, ISong song, Difficulty difficulty)
        {
            var      r        = randomGenerator;
            Sequence sequence = new Sequence();

            if (song.Sequences.ContainsKey(difficulty))
            {
                song.Sequences.Remove(difficulty);
            }
            song.Sequences.Add(difficulty, sequence);

            int notesCount = 3;

            switch (difficulty)
            {
            case Difficulty.Easy:
                notesCount = 2;
                break;

            case Difficulty.Medium:
                notesCount = 2;
                break;

            case Difficulty.Hard:
                notesCount = 3;
                break;
            }

            for (int i = 2; i < song.Duration.TotalSeconds - 2; i++)
            {
                if (difficulty == Difficulty.Medium)
                {
                    notesCount = r.Next(2, 4);
                }

                for (int j = 0; j < notesCount; j++)
                {
                    SeqElemType elemType = (SeqElemType)r.Next(0, 4);
                    sequence.AddElement(new SequenceElement()
                    {
                        Type = elemType, IsBomb = r.Next(0, 100) < 10, Time = new TimeSpan(0, 0, 0, i, r.Next(200, 1000))
                    });
                }
            }
        }
Ejemplo n.º 3
0
        public ISequenceElement GetClosestTo(TimeSpan time, SeqElemType elementType, IList <ISequenceElement> alreadyHit)
        {
            var notHitElements = SequenceElements.Except(alreadyHit).ToList(); //need to make a copy, because alreadyHit can be modified

            if (notHitElements.Count == 0)
            {
                return(null);
            }

            var inRangeElements = notHitElements.Where(e => e.Type == elementType && Math.Abs(e.Time.TotalSeconds - time.TotalSeconds) <= GameConstants.WorstHitTime);

            if (inRangeElements.Count() == 0)
            {
                return(null);
            }

            return(inRangeElements.OrderBy(e => e.Time.TotalSeconds).First());
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
 public ISequenceElement GetClosestTo(Difficulty difficulty, TimeSpan time, SeqElemType elementType, IList <ISequenceElement> alreadyHit)
 {
     return(Sequences[difficulty].GetClosestTo(time, elementType, alreadyHit));
 }