예제 #1
0
        public static void InsertSorted(this List <BrickActor> subject, BrickActor brick)
        {
            int index = subject.BinarySearch(brick, new BrickPositionComparer());

            subject.Insert((index >= 0) ? index : ~index, brick);
        }
예제 #2
0
파일: Scene.cs 프로젝트: rozniak/Junkbot
        public Scene(JunkbotLevelData levelData, AnimationStore store)
        {
            _MobileActors   = new List <IActor>();
            _ImmobileBricks = new List <BrickActor>();
            AnimationStore  = store;
            PlayField       = new IActor[levelData.Size.Width, levelData.Size.Height];
            CellSize        = levelData.Spacing;
            Size            = levelData.Size;

            foreach (JunkbotPartData part in levelData.Parts)
            {
                IActor actor    = null;
                Color  color    = Color.FromName(levelData.Colors[part.ColorIndex]);
                Point  location = part.Location; // Subtract one to get zero-indexed location

                switch (levelData.Types[part.TypeIndex])
                {
                case "brick_01":
                    actor = new BrickActor(store, location, color, BrickSize.One);
                    break;

                case "brick_02":
                    actor = new BrickActor(store, location, color, BrickSize.Two);
                    break;

                case "brick_03":
                    actor = new BrickActor(store, location, color, BrickSize.Three);
                    break;

                case "brick_04":
                    actor = new BrickActor(store, location, color, BrickSize.Four);
                    break;

                case "brick_06":
                    actor = new BrickActor(store, location, color, BrickSize.Six);
                    break;

                case "brick_08":
                    actor = new BrickActor(store, location, color, BrickSize.Eight);
                    break;

                case "minifig":
                    actor = new JunkbotActor(store, this, location, (part.AnimationName == "WALK_L" ? FacingDirection.Left : FacingDirection.Right));
                    break;

                default:
                    Console.WriteLine("Unknown actor: " + levelData.Types[part.TypeIndex]);
                    continue;
                }

                actor.Location = location.Subtract(new Point(1, actor.GridSize.Height));
                UpdateActorGridPosition(actor, actor.Location);

                actor.LocationChanged += Actor_LocationChanged;

                if (actor is BrickActor)
                {
                    var brick = (BrickActor)actor;

                    _ImmobileBricks.InsertSorted((BrickActor)actor);
                }
                else
                {
                    _MobileActors.Add(actor);
                }
            }
        }