Example #1
0
        private bool Ydirect(Grid start, Grid end, LinkedList path)
        {
            if (start.GetXpos() != end.GetXpos())
            {
                return false;
            }
            int direct = 1;
            if (start.GetYpos() > end.GetYpos())
            {
                direct = -1;
            }
            path.Clear();
            for (int y = start.GetYpos() + direct; y != end.GetYpos() && y < yBound
                    && y >= 0; y += direct)
            {
                if (grid[y][start.GetXpos()].IsVisible())
                {
                    return false;
                }
                path.Add(grid[y][start.GetXpos()]);
            }

            path.Add(end);
            return true;
        }
Example #2
0
        private void Shuffle(Grid[] array, int count)
        {
            if (wingame)
            {
                return;
            }
            int number = 0;
            do
            {
                GetSprites().SetVisible(false);
                for (int i = 0; i < count; i++)
                {
                    int j = (int)(MathUtils.Random() * (double)count);
                    int k = (int)(MathUtils.Random() * (double)count);
                    LTexture temp = array[k].GetBitmap();

                    array[k].SetImage(array[j].GetBitmap());
                    array[j].SetImage(temp);
                }

                GetSprites().SetVisible(true);
                number++;
                if (number > 5)
                {
                    wingame = true;
                    break;
                }
            } while (!FindPair());
        }
Example #3
0
        private bool Xdirect(Grid start, Grid end, LinkedList path)
        {
            if (start.GetYpos() != end.GetYpos())
                return false;
            int direct = 1;
            if (start.GetXpos() > end.GetXpos())
            {
                direct = -1;
            }
            path.Clear();
            for (int x = start.GetXpos() + direct; x != end.GetXpos() && x < xBound
                    && x >= 0; x += direct)
            {
                if (grid[start.GetYpos()][x].IsVisible())
                {
                    return false;
                }
                path.Add(grid[start.GetYpos()][x]);
            }

            path.Add(end);
            return true;
        }
Example #4
0
        private void InitUI()
        {
            xBound = levelInfo.GetXBound() + 2;
            yBound = levelInfo.GetYBound() + 2;

            grid = (Grid[][])CollectionUtils.XNA_CreateJaggedArray(typeof(Grid), yBound, xBound);
            int count = 0;

            Grid[] temp = new Grid[xBound * yBound];
            for (int y = 0; y < yBound; y++)
            {
                for (int x = 0; x < xBound; x++)
                {
                    grid[y][x] = new Grid(x, y);
                    if (x == 0 || x == xBound - 1 || y == 0 || y == yBound - 1)
                    {
                        LTexture img = GetImage(count % sub);
                        int nx = offsetX + x * img.GetWidth();
                        int ny = offsetY + y * img.GetHeight();

                        grid[y][x].SetLocation(nx, ny);
                        grid[y][x].SetImage(GetImage(9));
                        grid[y][x].SetVisible(false);
                    }
                    else
                    {
                        LTexture img = GetImage(count % sub);
                        grid[y][x].SetImage(img);
                        grid[y][x].SetBorder(3);
                        int nx = offsetX + x * img.GetWidth();
                        int ny = offsetY + y * img.GetHeight();

                        grid[y][x].SetLocation(nx, ny);
                        temp[count] = grid[y][x];
                        count++;
                    }
                    GetSprites().Add(grid[y][x]);
                }

            }

            Shuffle(temp, count);
            wingame = false;
            tipcount = tip_number;
            bombcount = bomb_number;
            refreshcount = refresh_number;
            InitRole();
        }
Example #5
0
        private int FindPath(Grid start, Grid end)
        {
            if (Xdirect(start, end, path[0]))
            {
                return 1;
            }
            if (Ydirect(start, end, path[0]))
            {
                return 1;
            }
            Grid xy = grid[start.GetYpos()][end.GetXpos()];
            if (!xy.IsVisible() && Xdirect(start, xy, path[0])
                    && Ydirect(xy, end, path[1]))
            {
                return 2;
            }
            Grid yx = grid[end.GetYpos()][start.GetXpos()];
            if (!yx.IsVisible() && Ydirect(start, yx, path[0])
                    && Xdirect(yx, end, path[1]))
            {
                return 2;
            }
            path[0].Clear();
            for (int y = start.GetYpos() - 1; y >= 0; y--)
            {
                xy = grid[y][start.GetXpos()];
                yx = grid[y][end.GetXpos()];
                if (xy.IsVisible())
                {
                    break;
                }
                path[0].Add(xy);
                if (!yx.IsVisible() && Xdirect(xy, yx, path[1])
                        && Ydirect(yx, end, path[2]))
                {
                    return 3;
                }
            }

            path[0].Clear();
            for (int y = start.GetYpos() + 1; y < yBound; y++)
            {
                xy = grid[y][start.GetXpos()];
                yx = grid[y][end.GetXpos()];
                if (xy.IsVisible())
                {
                    break;
                }
                path[0].Add(xy);
                if (!yx.IsVisible() && Xdirect(xy, yx, path[1])
                        && Ydirect(yx, end, path[2]))
                {
                    return 3;
                }
            }

            path[0].Clear();
            for (int x = start.GetXpos() - 1; x >= 0; x--)
            {
                yx = grid[start.GetYpos()][x];
                xy = grid[end.GetYpos()][x];
                if (yx.IsVisible())
                {
                    break;
                }
                path[0].Add(yx);
                if (!xy.IsVisible() && Ydirect(yx, xy, path[1])
                        && Xdirect(xy, end, path[2]))
                {
                    return 3;
                }
            }

            path[0].Clear();
            for (int x = start.GetXpos() + 1; x < xBound; x++)
            {
                yx = grid[start.GetYpos()][x];
                xy = grid[end.GetYpos()][x];
                if (yx.IsVisible())
                {
                    break;
                }
                path[0].Add(yx);
                if (!xy.IsVisible() && Ydirect(yx, xy, path[1])
                        && Xdirect(xy, end, path[2]))
                {
                    return 3;
                }
            }

            return 0;
        }
Example #6
0
        private bool FindPair()
        {
            nexts = null;
            nexte = null;
            for (int sy = 1; sy < yBound - 1; sy++)
            {
                for (int sx = 1; sx < xBound - 1; sx++)
                    if (grid[sy][sx].IsVisible())
                    {
                        for (int ey = sy; ey < yBound - 1; ey++)
                        {
                            for (int ex = 1; ex < xBound - 1; ex++)
                                if (grid[ey][ex].IsVisible()
                                        && (ey != sy || ex != sx)
                                        && grid[sy][sx].Equals(grid[ey][ex]))
                                {
                                    pcount = FindPath(grid[sy][sx], grid[ey][ex]);
                                    if (pcount != 0)
                                    {
                                        nexts = grid[sy][sx];
                                        nexte = grid[ey][ex];
                                        return true;
                                    }
                                }

                        }

                    }

            }

            return false;
        }
Example #7
0
 private void DeletePair(Grid prev, Grid current)
 {
     LinkedList temp = new LinkedList();
     temp.Add(prev);
     for (int i = 0; i < pcount; i++)
     {
         temp.AddAll(path[i]);
         path[i].Clear();
     }
     AnimateThread thread = new AnimateThread(temp);
     thread.Tag = this;
     thread.Start();
 }
Example #8
0
        public void Refreshs()
        {
            if (wingame || progress.GetValue() == 0)
            {
                return;
            }
            if (progress != null)
            {
                progress.Set(progress_number);
            }
            wingame = false;
            overFlag = false;
            failgame = false;
            init = false;
            Grid[] temp = new Grid[xBound * yBound];
            int count = 0;
            for (int y = 1; y < yBound - 1; y++)
            {
                for (int x = 1; x < xBound - 1; x++)
                    if (grid[y][x].IsVisible())
                    {
                        int nx = offsetX + x * grid[y][x].GetWidth();
                        int ny = offsetY + y * grid[y][x].GetHeight();
                        grid[y][x].SetLocation(nx, ny);
                        grid[y][x].SetBorder(3);
                        temp[count] = grid[y][x];
                        count++;
                    }

            }
            if (count != 0)
            {
                refreshcount--;
                Shuffle(temp, count);
            }
            else
            {
                wingame = true;
            }
        }