public void Handle(GameKeyEvent message)
        {
            if (!IsActive || IsPopupShowing)
            {
                return;
            }

            if (DebugSongHelper.HandleKeyPressed(this, message))
            {
                return;
            }

            if (message.PlayerAction == PlayerAction.Back)
            {
                PauseGame();
                IsPopupShowing = true;
                _eventAggregator.Publish(new ShowPopupEvent()
                {
                    PopupType     = PopupType.ButtonsPopup,
                    PopupSettings = (vm) =>
                    {
                        (vm as ButtonsPopupViewModel).Buttons.AddRange(new List <string>()
                        {
                            "Resume", "Play again", "Go back"
                        });
                        (vm as ButtonsPopupViewModel).Message = "Pause";
                    }
                });
            }
        }
        void PrepareUI()
        {
            //set points & life
            _view.p1PointsBar.Points = "0";
            _view.p1Health.SetLife(GameConstants.FullLife);
            _view.p2PointsBar.Points = "0";
            _view.p2Health.SetLife(GameConstants.FullLife);

            //load notes
            LoadNotes(Game.Song, Game.Player1);
            DebugSongHelper.ShowCurrentTimeInsteadPoints(_p1Animation, _game.MusicPlayerService, _view);

            //set background
            if (Game.Song.BackgroundPath != null && File.Exists(Game.Song.BackgroundPath))
            {
                _view.Background = new ImageBrush(new BitmapImage(new Uri(Game.Song.BackgroundPath)));
            }
            else
            {
                _view.Background = new ImageBrush(new BitmapImage(new Uri(GameUIConstants.DefaultGameBackground)));
            }

            //set view according to number of players
            _view.mainGrid.ColumnDefinitions.Clear();
            _view.mainGrid.ColumnDefinitions.Add(new ColumnDefinition());
            if (_game.IsMultiplayer)
            {
                LoadNotes(Game.Song, Game.Player2);
                _view.mainGrid.ColumnDefinitions.Add(new ColumnDefinition());

                _view.p2Playboard.Visibility = System.Windows.Visibility.Visible;
                _view.p2LifePanel.Visibility = System.Windows.Visibility.Visible;
                _view.p2PointsBar.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                _view.p2Playboard.Visibility = System.Windows.Visibility.Hidden;
                _view.p2LifePanel.Visibility = System.Windows.Visibility.Hidden;
                _view.p2PointsBar.Visibility = System.Windows.Visibility.Hidden;
            }
        }
        public void Handle(PlayerHitEvent message)
        {
            if (!IsActive)
            {
                return;
            }

            var notesPanel = message.PlayerID == PlayerID.Player1 ? _view.p1Notes     : _view.p2Notes;
            var pointsBar  = message.PlayerID == PlayerID.Player1 ? _view.p1PointsBar : _view.p2PointsBar;
            var healthBar  = message.PlayerID == PlayerID.Player1 ? _view.p1Health    : _view.p2Health;

            //set player status
            pointsBar.Points = message.Points.ToString();
            healthBar.SetLife(message.Life);
            DebugSongHelper.ShowHitTimeDifferenceInsteadPoints(_view, _p1Animation);

            //remove hit element
            var toRemove = notesPanel.Children.OfType <Image>().FirstOrDefault(img => img.Tag == message.SequenceElement);

            if (toRemove != null)
            {
                notesPanel.Children.Remove(toRemove);
            }
        }
        void LoadNotes(ISong song, IPlayer player)
        {
            var notes     = player.PlayerID == PlayerID.Player1 ? _view.p1Notes.Children : _view.p2Notes.Children;
            var animation = player.PlayerID == PlayerID.Player1 ? _p1Animation : _p2Animation;

            notes.Clear();

            //set animation
            animation.Children.First().Duration = song.Duration;
            (animation.Children.First() as DoubleAnimation).From = -GameUIConstants.ArrowWidthHeight;
            (animation.Children.First() as DoubleAnimation).To   = -(GameUIConstants.PixelsPerSecond * song.Duration.TotalSeconds + GameUIConstants.ArrowWidthHeight);

            //create arrows for each sequence element
            foreach (var seqElem in song.Sequences[player.Difficulty])
            {
                //load and prepare image
                string imagePath = player.PlayerID == PlayerID.Player1 ? GameUIConstants.P1ArrowImage : GameUIConstants.P2ArrowImage;
                if (seqElem.IsBomb)
                {
                    imagePath = GameUIConstants.BombImage;
                }
                var   bitmap = new BitmapImage(new Uri(imagePath));
                Image img    = new Image()
                {
                    Width = GameUIConstants.ArrowWidthHeight, Height = GameUIConstants.ArrowWidthHeight, Source = bitmap, Tag = seqElem
                };

                //set top position of arrow according to time
                double top = seqElem.Time.TotalSeconds * GameUIConstants.PixelsPerSecond;
                Canvas.SetTop(img, top);

                //rotate arrow and set in proper place
                switch (seqElem.Type)
                {
                case SeqElemType.LeftArrow:
                    if (!seqElem.IsBomb)
                    {
                        img.RenderTransform = new RotateTransform(90, GameUIConstants.ArrowWidthHeight / 2.0, GameUIConstants.ArrowWidthHeight / 2.0);
                    }
                    Canvas.SetLeft(img, GameUIConstants.LeftArrowX);
                    break;

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

                case SeqElemType.UpArrow:
                    if (!seqElem.IsBomb)
                    {
                        img.RenderTransform = new RotateTransform(180, GameUIConstants.ArrowWidthHeight / 2.0, GameUIConstants.ArrowWidthHeight / 2.0);
                    }
                    Canvas.SetLeft(img, GameUIConstants.UpArrowX);
                    break;

                case SeqElemType.RightArrow:
                    if (!seqElem.IsBomb)
                    {
                        img.RenderTransform = new RotateTransform(-90, GameUIConstants.ArrowWidthHeight / 2.0, GameUIConstants.ArrowWidthHeight / 2.0);
                    }
                    Canvas.SetLeft(img, GameUIConstants.RightArrowX);
                    break;
                }

                //add image to the canvas
                notes.Add(img);

                DebugSongHelper.AddTimeToNotes(notes, seqElem.Type, top);
            }
        }