コード例 #1
0
        void rec_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            CheckGame();

            if (clickedPeg != null)
            {
                TableControl rec = sender as TableControl;

                if (pegs[rec.XK, rec.YK] == null)
                {
                    if ((clickedPeg.XK == rec.XK && Math.Abs(clickedPeg.YK - rec.YK) == 2) ||
                        (clickedPeg.YK == rec.YK && Math.Abs(clickedPeg.XK - rec.XK) == 2))
                    {
                        int kx = (clickedPeg.XK + rec.XK) / 2;
                        int ky = (clickedPeg.YK + rec.YK) / 2;

                        if (pegs[kx, ky] != null)
                        {
                            pegs[clickedPeg.XK, clickedPeg.YK] = null;

                            pegs[kx, ky].Visibility = Visibility.Collapsed;
                            pegs[kx, ky]            = null;

                            clickedPeg.XK = rec.XK;
                            clickedPeg.YK = rec.YK;

                            pegs[rec.XK, rec.YK] = clickedPeg;

                            clickedPeg.SetValue(Grid.RowProperty, rec.XK);
                            clickedPeg.SetValue(Grid.ColumnProperty, rec.YK);

                            clickedPeg.ChangeColor(false);

                            clickedPeg = null;
                        }
                    }
                }
            }

            CheckGame();
        }
コード例 #2
0
        private void CreateTable()
        {
            for (int i = 0; i < 7; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    if (level[i, j] == 1)
                    {
                        TableControl rec = new TableControl();

                        rec.XK = i;
                        rec.YK = j;

                        rec.MouseLeftButtonDown += new MouseButtonEventHandler(rec_MouseLeftButtonDown);

                        rec.SetValue(Grid.RowProperty, i);
                        rec.SetValue(Grid.ColumnProperty, j);

                        GridBoard.Children.Add(rec);
                    }
                }
            }
        }