Ejemplo n.º 1
0
 public static bool IsTrue(MatrixBox matrix_box, int rows, int cols)
 {
     for (int i = 0; i < rows; ++i)
     {
         for (int j = 0; j < cols; ++j)
         {
             if (i == rows - 1 && j == cols - 1)
             {
                 break;
             }
             //if (matrix_box.matrix[i, j].curr_row != matrix_box.matrix[i, j].corr_row)
             //    return false;
             //if (matrix_box.matrix[i, j].curr_col != matrix_box.matrix[i, j].corr_col)
             //    return false;
             if (matrix_box.matrix[i, j].curr_row != i)
             {
                 return(false);
             }
             if (matrix_box.matrix[i, j].curr_col != j)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Ejemplo n.º 2
0
        public static void Move(MatrixBox matrix_box, int _x, int _y)
        {
            int rows = matrix_box.rows;
            int cols = matrix_box.cols;
            int r = rows - 1, c = cols - 1;

            for (int i = 0; i < rows; ++i)
            {
                for (int j = 0; j < cols; ++j)
                {
                    if (i == rows - 1 && j == cols - 1)
                    {
                        break;
                    }
                    if ((matrix_box.matrix[i, j].curr_row == Empty.X + _x) && (matrix_box.matrix[i, j].curr_col == Empty.Y + _y))
                    {
                        r = i; c = j;
                    }
                }
            }
            if (r == rows - 1 && c == cols - 1)
            {
                return;
            }
            Grid.SetRow(matrix_box.matrix[r, c].box, Empty.X);
            Grid.SetColumn(matrix_box.matrix[r, c].box, Empty.Y);
            int temp = matrix_box.matrix[r, c].curr_row;

            matrix_box.matrix[r, c].curr_row = Empty.X;
            Empty.X = temp;
            temp    = matrix_box.matrix[r, c].curr_col;
            matrix_box.matrix[r, c].curr_col = Empty.Y;
            Empty.Y = temp;
        }
Ejemplo n.º 3
0
 public void Level(int rows, int cols)
 {
     this.rows  = rows;
     this.cols  = cols;
     matrix_box = new MatrixBox(image, rows, cols);
     matrix_box.Shuffle();
     matrix_box.Fill(gridPlay);
 }
Ejemplo n.º 4
0
        public async void Play(MatrixBox matrix_box, Grid gridPlay)
        {
            long[,] matrix = new long[3, 3];
            for (long i = 0; i < 3; ++i)
            {
                for (long j = 0; j < 3; ++j)
                {
                    matrix[i, j] = -1;
                }
            }
            for (long i = 0; i < 3; ++i)
            {
                for (long j = 0; j < 3; ++j)
                {
                    if (i == 2 && j == 2)
                    {
                        break;
                    }
                    matrix[matrix_box.matrix[i, j].curr_row, matrix_box.matrix[i, j].curr_col] = i * 3 + j;
                }
            }
            for (long i = 0; i < 3; ++i)
            {
                for (long j = 0; j < 3; ++j)
                {
                    if (matrix[i, j] == -1)
                    {
                        matrix[i, j] = 8;
                    }
                }
            }

            long _curr = tree[ToInt(matrix)];

            while (_curr != 0)
            {
                long _x = (_curr - 1) % 4;
                MoveEvent.Move(matrix_box, (-1) * X[_x], (-1) * Y[_x]);
                await Task.Delay(500);

                _curr = (_curr - 1) / 4;
            }
            SetGrid.SetDefault(gridPlay);
            SetGrid.SetImage(gridPlay, matrix_box.image);
        }
Ejemplo n.º 5
0
 public static void Right(MatrixBox matrix_box)
 {
     Move(matrix_box, 0, -1);
 }
Ejemplo n.º 6
0
 public static void Left(MatrixBox matrix_box)
 {
     Move(matrix_box, 0, 1);
 }
Ejemplo n.º 7
0
 public static void Down(MatrixBox matrix_box)
 {
     Move(matrix_box, -1, 0);
 }
Ejemplo n.º 8
0
 public static void Up(MatrixBox matrix_box)
 {
     Move(matrix_box, 1, 0);
 }