Beispiel #1
0
        public void Page_Loaded(object o, EventArgs e)
        {
            // Initialize variables
            _defaultVolume = mediaElement.Volume;
            BrowserHost    = App.Current.Host.Content;

            // Initialize UI
            _primaryBoardDisplay = new BoardDisplay();
            Children.Add(_primaryBoardDisplay);
            _fadingBoardDisplay = new BoardDisplay();
            Children.Add(_fadingBoardDisplay);

            // Initialize handlers
            KeyUp += new KeyEventHandler(HandleKeyUp);
            MouseLeftButtonDown += new MouseButtonEventHandler(HandleMouseLeftButtonDown);
            BrowserHost.Resized += new EventHandler(HandleResize);

            // Create the starting board, play the "new" sound, and fade it in
            _primaryBoardDisplay.Board = Board.FromString(BoardWikipediaSample);
            PlaySoundEffect(SoundEffect.New);
            _fadingBoardDisplay.Fade(FadeSecondsLoading);
        }
Beispiel #2
0
        private void HandleKeyUp(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.Escape:     // Escape
                _primaryBoardDisplay.Solve();
                break;

            case Key.Left:   // Left arrow
            case Key.Up:     // Up arrow
            case Key.Right:  // Right arrow
            case Key.Down:   // Down arrow
                // Move the marker
                var markerPosition = _primaryBoardDisplay.MarkerPosition;
                switch (e.Key)
                {
                case Key.Left: markerPosition.X--; break;

                case Key.Up: markerPosition.Y--; break;

                case Key.Right: markerPosition.X++; break;

                case Key.Down: markerPosition.Y++; break;
                }
                _primaryBoardDisplay.MarkerPosition = markerPosition;
                _fadingBoardDisplay.MarkerPosition  = markerPosition;
                break;

            case Key.Delete:     // Delete
                // Clear the cell's value
                PrepareFade();
                if (_primaryBoardDisplay.ChangeSelectedValue(Digit.Unknown, Digit.Kind.Normal))
                {
                    // Play the appropriate sound and fade it
                    PlaySoundEffect(SoundEffect.Move);
                    _fadingBoardDisplay.Fade(FadeSecondsNormal);
                }
                break;

            case Key.D1:     // 1
            case Key.D2:     // 2
            case Key.D3:     // 3
            case Key.D4:     // 4
            case Key.D5:     // 5
            case Key.D6:     // 6
            case Key.D7:     // 7
            case Key.D8:     // 8
            case Key.D9:     // 9
                // Set the cell's value
                PrepareFade();
                if (_primaryBoardDisplay.ChangeSelectedValue(e.Key - Key.D0, ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift ? Digit.Kind.Given : ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control ? Digit.Kind.Guess : Digit.Kind.Normal))))
                {
                    // Normal move; play the appropriate sound and fade it
                    PlaySoundEffect(_primaryBoardDisplay.Board.Complete ? SoundEffect.Complete : SoundEffect.Move);
                    _fadingBoardDisplay.Fade(FadeSecondsNormal);
                }
                else
                {
                    // Invalid move, play the conflict sound
                    PlaySoundEffect(SoundEffect.Conflict);
                }
                break;

            case Key.B:     // B
            case Key.F:     // F
            case Key.S:     // S
            case Key.W:     // W
                // Switch to the specified board
                PrepareFade();
                var boardString = "";
                switch (e.Key)
                {
                case Key.B: boardString = BoardBlank; break;

                case Key.F: boardString = BoardAlmostFinished; break;

                case Key.S: boardString = BoardSudopediaSample; break;

                case Key.W: boardString = BoardWikipediaSample; break;
                }
                _primaryBoardDisplay.Board = Board.FromString(boardString);
                PlaySoundEffect(SoundEffect.New);
                _fadingBoardDisplay.Fade(FadeSecondsNormal);
                break;

            case Key.C:     // C
                // Toggle the candidate display
                PrepareFade();
                _primaryBoardDisplay.CandidatesVisible = !_primaryBoardDisplay.CandidatesVisible;
                _fadingBoardDisplay.Fade(FadeSecondsNormal);
                break;
            }
        }