Пример #1
0
        private bool IsValidMove(Command cmd, Point newPoint, TileType type)
        {
            var newSpot = _world.GetTile(newPoint);

            if (newSpot.IsWall())
            {
                return(false);
            }

            if (newSpot.IsPassable())
            {
                return(true);
            }

            if (newSpot.ContainsBarrel())
            {
                if (!type.ContainsPlayer())
                {
                    return(false);
                }

                var newBarrelPosition = GetNewPosition(cmd, newPoint);
                if (IsValidMove(cmd, newBarrelPosition, newSpot)) //can barrel move here?
                {
                    return(MoveObject(cmd, newPoint));
                }
            }

            return(false);
        }
Пример #2
0
        private bool IsValidMove(Command cmd, Point newPoint, TileType type)
        {
            var newSpot = _world.GetTile(newPoint);

            if (newSpot.IsWall())
                return false;

            if (newSpot.IsPassable())
                return true;

            if (newSpot.ContainsBarrel())
            {
                if (!type.ContainsPlayer())
                    return false;

                var newBarrelPosition = GetNewPosition(cmd, newPoint);
                if (IsValidMove(cmd, newBarrelPosition, newSpot)) //can barrel move here?
                {
                    return MoveObject(cmd, newPoint);
                }
            }

            return false;
        }