Пример #1
0
        private Tuple <int, int> ConvertKKSquareToCoord(KenKenSquare square)
        {
            int row = Grid.GetRow(square);
            int col = Grid.GetColumn(square);

            return(Tuple.Create(row, col));
        }
Пример #2
0
        private void KenKenSquare_Click(object sender, RoutedEventArgs e)
        {
            KenKenSquare square = (KenKenSquare)sender;

            if (!square.IsDefined)
            {
                square.IsDefined = true;
                square.ColorIn   = Brushes.Orange.Color;
                EvolvingKKShape.Add(square);
                UpdateEvolvingKKShape();
            }
        }
Пример #3
0
        private IEnumerable <KenKenSquare> KKNeighbours(KenKenSquare square)
        {
            int row = Grid.GetRow(square);
            int col = Grid.GetColumn(square);

            return(KKSquares().Where(kkSquare => {
                int r = Grid.GetRow(kkSquare);
                int c = Grid.GetColumn(kkSquare);

                int rowDiff = Math.Abs(r - row);
                int colDiff = Math.Abs(c - col);

                return (rowDiff == 1 && colDiff == 0) || (rowDiff == 0 && colDiff == 1);
            }));
        }
Пример #4
0
        private void btnDefineRegion_Click(object sender, RoutedEventArgs e)
        {
            if (EvolvingKKShape.Count == 1)
            {
                SingleSquare singleSquare = new SingleSquare();
                if ((bool)singleSquare.ShowDialog())
                {
                    KenKenSquare onlySquare = EvolvingKKShape.Single();
                    onlySquare.TopLeftValue = singleSquare.Target.ToString();
                    onlySquare.ColorIn      = myPalate.NextColor();
                    cellColletionList.Add(new CellCollection {
                        KenKenSquares = EvolvingKKShape, TargetSum = singleSquare.Target
                    });
                    EvolvingKKShape = new List <KenKenSquare>();
                }
            }
            else
            {
                NewRegion nr = new NewRegion(EvolvingKKShape.Count);
                if ((bool)nr.ShowDialog())
                {
                    KenKenSquare topLeft = TopLeftKKSquare(EvolvingKKShape);
                    topLeft.TopLeftValue = String.Format("{0} {1}", nr.Target, nr.Operation.StringFormat());
                    Color currentColor = myPalate.NextColor();
                    foreach (KenKenSquare square in EvolvingKKShape)
                    {
                        square.ColorIn = currentColor;
                    }
                    cellColletionList.Add(new CellCollection {
                        KenKenSquares = EvolvingKKShape, MathematicalOp = nr.Operation, TargetSum = nr.Target
                    });
                    EvolvingKKShape = new List <KenKenSquare>();
                }
            }

            foreach (KenKenSquare square in KKSquares().Except(DefinedKKSquares()))
            {
                square.IsEnabled = true;
                square.Reset();
            }

            if (DefinedKKSquares().Count() == 36)
            {
                this.btnSolve.IsEnabled = true;
            }
        }
Пример #5
0
 private void KenKenSquare_MouseEnterLeave(KenKenSquare aSquare, bool IsEntering)
 {
     if (aSquare.IsDefined)
     {
         var kksList = cellColletionList.Find(cellCollection => cellCollection.KenKenSquares.Contains(aSquare));
         if (kksList != null)
         {
             foreach (KenKenSquare square in kksList.KenKenSquares)
             {
                 if (IsEntering)
                 {
                     square.button_MouseEnter(square, null);
                 }
                 else
                 {
                     square.button_MouseLeave(square, null);
                 }
             }
         }
     }
 }
        private static void ColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            KenKenSquare square = (KenKenSquare)d;

            square.Background = new SolidColorBrush((Color)e.NewValue);
        }
        private static void TopLeftValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            KenKenSquare square = (KenKenSquare)d;

            square.txtTopLeft.Text = e.NewValue.ToString();
        }