Ejemplo n.º 1
0
        /// <summary>
        /// Creates a randomized map.
        /// </summary>
        /// <param name="width">The width of the map.</param>
        /// <param name="height">The height of the map.</param>
        /// <param name="objects">The number of objects to be inserted.</param>
        /// <returns></returns>
        private Map CreateRandomMap(int width, int height, int objects)
        {
            Console.WriteLine("  - Creating randomized map: " + width.ToString() + "x" + height.ToString());
            Map           map = new Map(width, height);
            InternalField fld = new InternalField();
            Collision     col = new Collision();
            Random        rnd = new Random();

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    fld = new InternalField();
                    col = new Collision((rnd.Next(2) == 1), (rnd.Next(2) == 1), (rnd.Next(2) == 1), (rnd.Next(2) == 1));
                    fld.SetCollision(col);
                    fld.SetGraphicID((uint)(rnd.Next(int.MaxValue)));
                    map.SetField(x, y, fld);
                }
            }

            int        type;
            IMapObject obj;

            Console.Write("  - Creating objects");
            for (int i = 0; i < objects; i++)
            {
                if (i % 1000 == 0)
                {
                    Console.Write(".");
                }
                type = rnd.Next(17);
                switch (type)
                {
                case 0:
                    obj = new BreakableMapObject();
                    break;

                case 1:
                    obj = new ContainerMapObject();
                    break;

                case 2:
                    obj = new DamagerMapObject();
                    break;

                case 3:
                    obj = new DoorMapObject();
                    break;

                case 4:
                    obj = new EnemyMapObject();
                    break;

                case 5:
                    obj = new MovableMapObject();
                    break;

                case 6:
                    obj = new SoundMapObject();
                    break;

                case 7:
                    obj = new StaticMapObject();
                    break;

                case 8:
                    obj = new TriggerCommentMapObject();
                    break;

                case 9:
                    obj = new TriggerContainerMapObject();
                    break;

                case 10:
                    obj = new TriggerContainerSoundMapObject();
                    break;

                case 11:
                    obj = new TriggerDoorMapObject();
                    break;

                case 12:
                    obj = new TriggerDoorSoundMapObject();
                    break;

                case 13:
                    obj = new TriggerEnablerMapObject();
                    break;

                case 14:
                    obj = new TriggerExitMapObject();
                    break;

                case 15:
                    obj = new TriggerMapObject();
                    break;

                case 16:
                    obj = new TriggerTeleportMapObject();
                    break;

                default:
                    obj = new StaticMapObject();
                    break;
                }
                obj.PosX  = rnd.Next(width);
                obj.PosY  = rnd.Next(height);
                obj.SizeX = 1;
                obj.SizeY = 1;

                map.InsertObject(obj);

                obj = null;
            }
            Console.WriteLine();
            Console.WriteLine("  - Map created.");
            return(map);
        }
Ejemplo n.º 2
0
        private IMapObject RandomObject(Random rnd)
        {
            int        type = rnd.Next(17);
            IMapObject obj;

            switch (type)
            {
            case 0:
                obj = new BreakableMapObject();
                break;

            case 1:
                obj = new ContainerMapObject();
                break;

            case 2:
                obj = new DamagerMapObject();
                break;

            case 3:
                obj = new DoorMapObject();
                break;

            case 4:
                obj = new EnemyMapObject();
                break;

            case 5:
                obj = new MovableMapObject();
                break;

            case 6:
                obj = new SoundMapObject();
                break;

            case 7:
                obj = new StaticMapObject();
                break;

            case 8:
                obj = new TriggerCommentMapObject();
                break;

            case 9:
                obj = new TriggerContainerMapObject();
                break;

            case 10:
                obj = new TriggerContainerSoundMapObject();
                break;

            case 11:
                obj = new TriggerDoorMapObject();
                break;

            case 12:
                obj = new TriggerDoorSoundMapObject();
                break;

            case 13:
                obj = new TriggerEnablerMapObject();
                break;

            case 14:
                obj = new TriggerExitMapObject();
                break;

            case 15:
                obj = new TriggerMapObject();
                break;

            case 16:
                obj = new TriggerTeleportMapObject();
                break;

            default:
                obj = new StaticMapObject();
                break;
            }
            return(obj);
        }
Ejemplo n.º 3
0
        public IMapObject GenerateObject()
        {
            IMapObject obj = null;

            if (objectType.SelectedItem.ToString() == ObjectStatic)
            {
                obj = new StaticMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectTrigger)
            {
                obj = new TriggerMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectEnemy)
            {
                obj = new EnemyMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectDoor)
            {
                obj = new DoorMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectContainer)
            {
                obj = new ContainerMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectBreakable)
            {
                obj = new BreakableMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectMovable)
            {
                obj = new MovableMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectItem)
            {
                obj = new ItemMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectSound)
            {
                obj = new SoundMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectDamager)
            {
                obj = new DamagerMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectEnemy)
            {
                obj = new EnemyMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectTriggerDoor)
            {
                obj = new TriggerDoorMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectTriggerContainer)
            {
                obj = new TriggerContainerMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectTriggerDoorSound)
            {
                obj = new TriggerDoorSoundMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectTriggerContainerSound)
            {
                obj = new TriggerContainerSoundMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectTriggerExit)
            {
                obj = new TriggerExitMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectTriggerTeleport)
            {
                obj = new TriggerTeleportMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectTriggerEnabler)
            {
                obj = new TriggerEnablerMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectTriggerComment)
            {
                obj = new TriggerCommentMapObject();
            }
            if (objectType.SelectedItem.ToString() == ObjectMapStart)
            {
                obj = new MapStart();
            }
            obj.SizeX = 1;
            obj.SizeY = 1;
            return(obj);
        }