示例#1
0
 private void Initialize(Board basis)
 {
     // Initialize each digit
     _digits = new Digit[Size, Size];
     for (var y = 0; y < Size; y++)
     {
         for (var x = 0; x < Size; x++)
         {
             _digits[x, y] = new Digit();
         }
     }
     if (null != basis)
     {
         // Copy the digits of the specified board
         for (var y = 0; y < Size; y++)
         {
             for (var x = 0; x < Size; x++)
             {
                 var digit = basis.GetDigit(x, y);
                 if (digit.ValueKnown)
                 {
                     SetValue(x, y, digit.KnownValue, digit.DigitKind);
                 }
             }
         }
     }
 }
示例#2
0
 private void UpdateDisplay(Board board)
 {
     // Update the value and candidate numbers according to the specified board
     for (var y = 0; y < Board.Size; y++)
     {
         for (var x = 0; x < Board.Size; x++)
         {
             var digit = board.GetDigit(x, y);
             _values[x, y].Text = (digit.ValueKnown ? digit.KnownValue.ToString() : " ");
             for (var z = 0; z < 9; z++)
             {
                 _candidates[x, y, z].Text = (digit.ValueKnown ? " " : (digit.CouldBe(z + 1) ? (z + 1).ToString() : " "));
             }
         }
     }
     // Incorporate the specified board and layout
     _board = board;
     Layout();
 }
示例#3
0
 private void Initialize(Board basis)
 {
     // Initialize each digit
     _digits = new Digit[Size, Size];
     for (var y = 0; y < Size; y++)
     {
         for (var x = 0; x < Size; x++)
         {
             _digits[x, y] = new Digit();
         }
     }
     if (null != basis)
     {
         // Copy the digits of the specified board
         for (var y = 0; y < Size; y++)
         {
             for (var x = 0; x < Size; x++)
             {
                 var digit = basis.GetDigit(x, y);
                 if (digit.ValueKnown)
                 {
                     SetValue(x, y, digit.KnownValue, digit.DigitKind);
                 }
             }
         }
     }
 }
示例#4
0
        public void Layout()
        {
            // Do nothing if Width is NaN
            if (Double.IsNaN(Width))
            {
                return;
            }

            // Resize the frame and lines to fill the control
            _frame.Width  = Width;
            _frame.Height = Height;
            for (var i = 0; i < _verticalLines.Length; i++)
            {
                var verticalLine = _verticalLines[i];
                verticalLine.X1 = Math.Round(Width * ((double)(i + 1) / (_verticalLines.Length + 1)));
                verticalLine.Y1 = _frame.StrokeThickness;
                verticalLine.X2 = verticalLine.X1;
                verticalLine.Y2 = Height - _frame.StrokeThickness;
                var horizontalLine = _horizontalLines[i];
                horizontalLine.X1 = _frame.StrokeThickness;
                horizontalLine.Y1 = Math.Round(Height * ((double)(i + 1) / (_horizontalLines.Length + 1)));
                horizontalLine.X2 = Width - _frame.StrokeThickness;
                horizontalLine.Y2 = horizontalLine.Y1;
            }
            // Experimentally compute the largest acceptable font size for value text
            var valueBoundingWidth  = Width / Board.Size;
            var valueBoundingHeight = (Height / Board.Size) * 0.85;
            var valueProbe          = _values[0, 0];

            valueProbe.FontSize = 50;
            while ((0 < valueProbe.FontSize) && ((valueBoundingWidth <= valueProbe.ActualHeight) || (valueBoundingHeight <= valueProbe.ActualHeight)))
            {
                valueProbe.FontSize--;
            }
            // Experimentally compute the largest acceptable font size for candidate text
            var candidateBoundingWidth  = valueBoundingWidth / 3;
            var candidateBoundingHeight = valueBoundingHeight / 3;
            var candidateProbe          = _candidates[0, 0, 0];

            candidateProbe.FontSize = 50;
            while ((0 < candidateProbe.FontSize) && ((candidateBoundingWidth <= candidateProbe.ActualHeight) || (candidateBoundingHeight <= candidateProbe.ActualHeight)))
            {
                candidateProbe.FontSize--;
            }
            for (var y = 0; y < Board.Size; y++)
            {
                for (var x = 0; x < Board.Size; x++)
                {
                    // Update the value's size, styling, and position
                    var value = _values[x, y];
                    value.FontSize = valueProbe.FontSize;
                    if (null != _board)
                    {
                        value.FontWeight = (Digit.Kind.Given == _board.GetDigit(x, y).DigitKind) ? FontWeights.Bold : FontWeights.Normal;
                        value.FontStyle  = (Digit.Kind.Guess == _board.GetDigit(x, y).DigitKind) ? FontStyles.Italic : FontStyles.Normal;
                    }
                    var cellRect = GetCellRect(x, y);
                    Utility.CenterTextBlock(value, cellRect.Left, cellRect.Top, cellRect.Width, cellRect.Height);
                    for (var z = 0; z < 9; z++)
                    {
                        // Update the candidate's visibility, size, and position
                        var candidate = _candidates[x, y, z];
                        if (_candidatesVisible)
                        {
                            candidate.Visibility = Visibility.Visible;
                            candidate.FontSize   = candidateProbe.FontSize;
                            var candidateWidth  = cellRect.Width / 3;
                            var candidateLeft   = cellRect.Left + ((z % 3) * candidateWidth);
                            var candidateHeight = cellRect.Height / 3;
                            var candidateTop    = cellRect.Top + ((z / 3) * candidateHeight);
                            Utility.CenterTextBlock(candidate, candidateLeft, candidateTop, candidateWidth, candidateHeight);
                        }
                        else
                        {
                            candidate.Visibility = Visibility.Collapsed;
                        }
                    }
                }
            }
            // Layout the markers
            LayoutMarker(_marker, _markerPosition);
            if (_conflictPosition.HasValue)
            {
                LayoutMarker(_conflict, _conflictPosition.Value);
            }
            else
            {
                _conflict.Visibility = Visibility.Collapsed;
            }
        }
示例#5
0
 private void UpdateDisplay(Board board)
 {
     // Update the value and candidate numbers according to the specified board
     for (var y = 0; y < Board.Size; y++)
     {
         for (var x = 0; x < Board.Size; x++)
         {
             var digit = board.GetDigit(x, y);
             _values[x, y].Text = (digit.ValueKnown ? digit.KnownValue.ToString() : " ");
             for (var z = 0; z < 9; z++)
             {
                 _candidates[x, y, z].Text = (digit.ValueKnown ? " " : (digit.CouldBe(z + 1) ? (z + 1).ToString() : " "));
             }
         }
     }
     // Incorporate the specified board and layout
     _board = board;
     Layout();
 }