Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
            public IUnitIterator getIterator(string list)
            {
                switch (list.ToLower())
                {
                case "clean":
                    IUnitIterator clean = new UnitIterator(nodesClean);
                    //Console.WriteLine("clean iterator count in setup class: " + clean.getUnits().Count);
                    return(clean);

                case "anchor":
                case "anchors":
                    IUnitIterator itAnchors = new UnitIterator(anchors);
                    //Console.WriteLine("anchors iterator count in setup class: " + itAnchors.getUnits().Count);
                    return(itAnchors);

                case "raw":
                default:
                    IUnitIterator raw = new UnitIterator(nodesRaw);
                    Console.WriteLine("raw iterator count in setup class: " + raw.getUnits().Count);
                    return(raw);
                }
            }