Пример #1
0
        public static MapUnit CheckOut(double x, double y, Level LevelModel, IStrategy strategy)       //Around the object
        {
            double x_right  = (Math.Ceiling(x / GeneralObject.cellSize.X) * GeneralObject.cellSize.X);
            double y_bottom = (Math.Ceiling(y / GeneralObject.cellSize.Y) * GeneralObject.cellSize.Y);
            double x_left   = (Math.Floor(x / GeneralObject.cellSize.X) * GeneralObject.cellSize.X);
            double y_top    = (Math.Floor(y / GeneralObject.cellSize.Y) * GeneralObject.cellSize.Y);
            //Using Iterator
            var iterator = new UnitIterator(LevelModel, 0);

            while (iterator.HasNext())
            {
                var unit = iterator.NextUnit();
                if (unit != null)
                {
                    //Real position on map
                    if (!(unit is Block) && unit.ImageController != null)
                    {
                        unit.Position = new PointF((float)Canvas.GetLeft(unit.ImageController), (float)Canvas.GetTop(unit.ImageController));
                    }
                    if (strategy is FallStrategy)
                    {
                        if (
                            ((unit.Position.X + GeneralObject.cellSize.X) > x &&
                             (unit.Position.X) <= x &&
                             ((unit.Position.Y) <= y) &&
                             ((unit.Position.Y + GeneralObject.cellSize.Y) > y)
                            )
                            )
                        {
                            return(unit);
                        }
                    }
                    else
                    if (strategy is MoveStrategy)
                    {
                        if (
                            ((unit.Position.Y + GeneralObject.cellSize.Y) > y &&
                             (unit.Position.Y) <= y &&
                             ((unit.Position.X) <= x) &&
                             ((unit.Position.X + GeneralObject.cellSize.X) > x)
                            )
                            )
                        {
                            return(unit);
                        }
                    }
                    else
                    {
                        return(CheckOut(x, y, LevelModel, new FallStrategy()) ?? (CheckOut(x, y, LevelModel, new MoveStrategy()) ?? null));
                    }
                }
            }
            return(null);
        }
Пример #2
0
        public static MapUnit CheckIn(double x, double y, Level LevelModel) //when x and y are equal unit.ImageController.X and Y
        {                                                                   //For MapEditor
            //Using Iterator
            var iterator = new UnitIterator(LevelModel, 0);

            while (iterator.HasNext())
            {
                var unit = iterator.NextUnit();
                if (unit != null)
                {
                    if ((unit.Position.X == x && unit.Position.Y == y))
                    {
                        return(unit);
                    }
                }
            }
            return(null);
        }