Пример #1
0
        private void InitPuzzlePieces(int[,] puzzleValues)
        {
            int       vTicker      = 0;
            int       rTicker      = 0;
            bool      useBlue      = true;
            bool      startUseBlue = useBlue;
            const int boxSize      = 3;

            _currentValues = puzzleValues;

            for (int row = 0; row < _rows; ++row)
            {
                if (rTicker % 3 == 0 && rTicker != 0)
                {
                    startUseBlue = !startUseBlue;
                }
                useBlue = startUseBlue;
                vTicker = 0;
                for (int col = 0; col < _rows; ++col)
                {
                    int  pieceVal  = puzzleValues[row, col];
                    bool isDefined = false;

                    if (pieceVal != -1)
                    {
                        isDefined = true;
                    }
                    if (_sodukoPieces[row, col] != null)
                    {
                        // This means we are restoring so we can use the preset values.
                        isDefined = _sodukoPieces[row, col].IsPresetPiece;
                    }
                    var piece = new SodukoPiece(isDefined);
                    piece.OnTappedEvent += OnPieceTapped;
                    piece.SetScaling(_pieceLength);
                    piece.SetPosition(row, col);
                    if (vTicker % boxSize == 0 && vTicker != 0)
                    {
                        useBlue = !useBlue;
                    }
                    piece.SetBorderBrush(useBlue);

                    _sodukoPieces[row, col] = piece;

                    if (pieceVal != -1)
                    {
                        piece.NumberValue = pieceVal;
                    }

                    _canvas.Children.Add(piece);
                    ++vTicker;
                }
                ++rTicker;
            }
        }
Пример #2
0
        //BUG:
        // For some odd reason this function doesn't work it
        // makes all operations involving the UI just silently fail.
        // This all happens if this function is only called once on during startup.
        private void AddPuzzlePieces(int[,] puzzleValues)
        {
            int       vTicker      = 0;
            int       rTicker      = 0;
            bool      useBlue      = true;
            const int boxSize      = 3;
            bool      startUseBlue = useBlue;

            _canvas.Children.Clear();
            for (int row = 0; row < _rows; ++row)
            {
                if (rTicker % 3 == 0 && rTicker != 0)
                {
                    startUseBlue = !startUseBlue;
                }
                useBlue = startUseBlue;
                vTicker = 0;
                for (int col = 0; col < _rows; ++col)
                {
                    bool preDefined = false;
                    if (_startingState[row, col] != -1)
                    {
                        preDefined = true;
                    }
                    SodukoPiece p = new SodukoPiece(preDefined);

                    p.SetScaling(_pieceLength);
                    p.SetPosition(row, col);
                    if (vTicker % boxSize == 0 && vTicker != 0)
                    {
                        useBlue = !useBlue;
                    }
                    p.SetBorderBrush(useBlue);
                    p.OnTappedEvent += OnPieceTapped;
                    p.NumberValue    = puzzleValues[row, col];
                    _canvas.Children.Add(p);


                    ++vTicker;
                }
                ++rTicker;
            }
        }