示例#1
0
        static public bool Move(this iBoard b, MoveType moveType)
        {
            int dx = 0, dy = 0;

            moveType.Move(ref dx, ref dy);

            int bx = b.BuddyX, by = b.BuddyY;
            int nx = bx + dx, ny = by + dy;

            // on border check
            if (dx < 0 && nx <= 0 || dx > 0 && nx >= b.Width - 1)
            {
                return(false);
            }
            if (dy < 0 && ny <= 0 || dy > 0 && ny >= b.Height - 1)
            {
                return(false);
            }

            if (IsEmpty(b[nx, ny]))
            {
                string boardInfo = b.GetBoardInfo(true);
                b[bx, by] &= ~CellType.Buddy;
                b[nx, ny] |= CellType.Buddy;
                b.BuddyX   = nx;
                b.BuddyY   = ny;
                b.PushStep(new UndoStep(moveType, false, boardInfo));
                return(true);
            }
            if (Is(b[nx, ny], CellType.Box))
            {
                int nbx = nx + dx, nby = ny + dy;
                // on border check
                if (dx < 0 && nbx <= 0 || dx > 0 && nbx >= b.Width - 1)
                {
                    return(false);
                }
                if (dy < 0 && nby <= 0 || dy > 0 && nby >= b.Height - 1)
                {
                    return(false);
                }
                if (IsEmpty(b[nbx, nby]))
                {
                    string boardInfo = b.GetBoardInfo(true);
                    b[nx, ny]   &= ~CellType.Box;
                    b[nbx, nby] |= CellType.Box;
                    b[bx, by]   &= ~CellType.Buddy;
                    b[nx, ny]   |= CellType.Buddy;
                    b.BuddyX     = nx;
                    b.BuddyY     = ny;
                    b.PushStep(new UndoStep(moveType, true, boardInfo));
                    return(true);
                }
            }
            return(false);
        }
示例#2
0
        static bool CanNotBeMoved(this iBoard b, int x, int y, MoveType mt)
        {
            mt.Move(ref x, ref y);
            CellType t = b[x, y];

            if (t == CellType.Wall)
            {
                return(true);
            }

            if (Is(t, CellType.Box))
            {
                bool u = mt == MoveType.Down || b.CanNotBeMoved(x, y, MoveType.Up);
                bool d = mt == MoveType.Up || b.CanNotBeMoved(x, y, MoveType.Down);
                bool l = mt == MoveType.Right || b.CanNotBeMoved(x, y, MoveType.Left);
                bool r = mt == MoveType.Left || b.CanNotBeMoved(x, y, MoveType.Right);
                if ((u || d) && (l || r))
                {
                    return(true);
                }
            }

            return(false);
        }
示例#3
0
        static bool CanNotBeMoved(this iBoard b, int x, int y, MoveType mt)
        {
            mt.Move(ref x, ref y);
            CellType t = b[x, y];

            if (t == CellType.Wall)
                return true;

            if (Is(t, CellType.Box))
            {
                bool u = mt == MoveType.Down || b.CanNotBeMoved(x, y, MoveType.Up);
                bool d = mt == MoveType.Up || b.CanNotBeMoved(x, y, MoveType.Down);
                bool l = mt == MoveType.Right || b.CanNotBeMoved(x, y, MoveType.Left);
                bool r = mt == MoveType.Left || b.CanNotBeMoved(x, y, MoveType.Right);
                if ((u || d) && (l || r))
                {
                    return true;
                }
            }

            return false;
        }
示例#4
0
        public static bool Move(this iBoard b, MoveType moveType)
        {
            int dx = 0, dy = 0;
            moveType.Move(ref dx, ref dy);

            int bx = b.BuddyX, by = b.BuddyY;
            int nx = bx+ dx, ny = by + dy;
            // on border check
            if (dx < 0 && nx <= 0 || dx > 0 && nx >= b.Width - 1)
                return false;
            if (dy < 0 && ny <= 0 || dy > 0 && ny >= b.Height - 1)
                return false;

            if (IsEmpty(b[nx, ny]))
            {
                string boardInfo = b.GetBoardInfo(true);
                b[bx,by] &= ~CellType.Buddy;
                b[nx, ny] |= CellType.Buddy;
                b.BuddyX = nx;
                b.BuddyY = ny;
                b.PushStep(new UndoStep(moveType, false, boardInfo));
                return true;
            }
            if (Is(b[nx, ny], CellType.Box))
            {
                int nbx = nx + dx, nby = ny + dy;
                // on border check
                if (dx < 0 && nbx <= 0 || dx > 0 && nbx >= b.Width - 1)
                    return false;
                if (dy < 0 && nby <= 0 || dy > 0 && nby >= b.Height - 1)
                    return false;
                if (IsEmpty(b[nbx, nby]))
                {
                    string boardInfo = b.GetBoardInfo(true);
                    b[nx, ny] &= ~CellType.Box;
                    b[nbx, nby] |= CellType.Box;
                    b[bx, by] &= ~CellType.Buddy;
                    b[nx, ny] |= CellType.Buddy;
                    b.BuddyX = nx;
                    b.BuddyY = ny;
                    b.PushStep(new UndoStep(moveType, true, boardInfo));
                    return true;
                }
            }
            return false;
        }