Пример #1
0
        public static GameWorld LoadWorld(List <string> lines, WorldType type)
        {
            var world = new GameWorld(type);

            for (var i = 0; i < lines.Count; i++)
            {
                for (int s = 0; s < lines[i].Length; s++)
                {
                    char c         = lines[i][s];
                    var  newObject = GetGameObject(s, i, c);
                    if (newObject == null)
                    {
                        continue;
                    }
                    if (newObject is Player)
                    {
                        world.AddGamePlayer(newObject as Player);
                    }
                    else if (newObject.IsStatic || newObject is Teleport)
                    {
                        world.AddGameObject(newObject, 1);
                    }
                    else
                    {
                        world.AddGameObject(newObject);
                    }
                }
            }
            return(world);
        }
Пример #2
0
        public void HandleTeleports()
        {
            var teleportedObj = new List <GameObject>();

            foreach (var obj in Shapes)
            {
                if (obj is Teleport)
                {
                    var teleport = obj as Teleport;
                    if (teleport.Activated)
                    {
                        var teleported = teleport.teleported;
                        teleportedObj.Add(teleported);
                        teleport.Disable();
                    }
                }
            }
            bool teleportPlayer = false;

            foreach (var teleported in teleportedObj)
            {
                if (teleported is Player)
                {
                    teleportPlayer = true;
                    break;
                }
                RemoveGameObject(teleported);
                anotherWorld.AddGameObject(teleported);
            }
            if (teleportPlayer)
            {
                game.SwitchWorlds();
            }
        }