예제 #1
0
        public bool AvoidToLeavePath()
        {
            if (_isLoading == true || _isUnloading == true)
            {
                return(false);
            }

            Point LeftTile;
            Point RightTile;
            Point BackTile;
            Point FrontTile;

            switch (_direction)
            {
            case Direction.Up:
                LeftTile  = new Point(_location.X - 1, _location.Y);
                RightTile = new Point(_location.X + 1, _location.Y);
                BackTile  = new Point(_location.X, _location.Y + 1);
                FrontTile = new Point(_location.X, _location.Y - 1);
                break;

            case Direction.Down:
                LeftTile  = new Point(_location.X + 1, _location.Y);
                RightTile = new Point(_location.X - 1, _location.Y);
                BackTile  = new Point(_location.X, _location.Y - 1);
                FrontTile = new Point(_location.X, _location.Y + 1);
                break;

            case Direction.Left:
                LeftTile  = new Point(_location.X, _location.Y + 1);
                RightTile = new Point(_location.X, _location.Y - 1);
                BackTile  = new Point(_location.X + 1, _location.Y);
                FrontTile = new Point(_location.X - 1, _location.Y);
                break;

            case Direction.Right:
                LeftTile  = new Point(_location.X, _location.Y - 1);
                RightTile = new Point(_location.X, _location.Y + 1);
                BackTile  = new Point(_location.X - 1, _location.Y);
                FrontTile = new Point(_location.X + 1, _location.Y);
                break;

            default:
                return(false);
            }

            if (Warehouse.ValueAt(LeftTile) == 0)
            {
                _path.Push(_location);
                _path.Push(LeftTile);
                Program.PrintLine(_id + "Move to left side" + _location + LeftTile);
                return(true);
            }
            else if (Warehouse.ValueAt(RightTile) == 0)
            {
                _path.Push(_location);
                _path.Push(RightTile);
                Program.PrintLine(_id + "Move to right side" + _location + RightTile);
                return(true);
            }
            else if (Warehouse.ValueAt(BackTile) == 0)
            {
                _path.Push(_location);
                _path.Push(BackTile);
                Program.PrintLine(_id + "Move to back side" + _location + BackTile);
                return(true);
            }
            else if (Warehouse.ValueAt(FrontTile) == 0)
            {
                _path.Push(_location);
                _path.Push(FrontTile);
                Program.PrintLine(_id + "Move to front side" + _location + FrontTile);
                return(true);
            }
            Program.PrintLine(_id + "can not move");
            return(false);
        }