示例#1
0
        public static LevelGrid Copy(this ILevelGrid level)
        {
            var copy = new LevelGrid(level.Width, level.Height);

            for (int x = 0; x < level.Width; ++x)
            {
                for (int y = 0; y < level.Height; ++y)
                {
                    copy.SetElement(x, y, level.GetElement(x, y));
                }
            }
            return(copy);
        }
示例#2
0
        public static LevelGrid FromString(string levelString)
        {
            if (string.IsNullOrWhiteSpace(levelString))
            {
                return(null);
            }
            var lines         = levelString.Split(new string[] { Environment.NewLine, "\n" }, StringSplitOptions.RemoveEmptyEntries);
            int longestLength = lines.Max(s => s.Length);
            //use the longest line and line count as level dimensions
            LevelGrid level = new LevelGrid(longestLength, lines.Length);
            int       y     = level.Height - 1;

            foreach (string sLine in lines)
            {
                int x = 0;
                //each character is a grid element
                foreach (char symbol in sLine)
                {
                    ElementType type = ElementType.Floor;
                    switch (symbol)
                    {
                    case '#': type = ElementType.Wall; break;

                    case '-': type = ElementType.Floor; break;

                    case '@': type = ElementType.Man; break;

                    case '$': type = ElementType.Box; break;

                    case '.': type = ElementType.Goal; break;

                    case '*': type = ElementType.BoxOnGoal; break;

                    case '+': type = ElementType.ManOnGoal; break;
                    }
                    ;
                    level.SetElement(x, y, type);
                    ++x;
                }
                --y;
            }
            return(level);
        }
示例#3
0
        public static void MovePlayer(this LevelGrid level, Point oldPos, Point newPos)
        {
            ElementType type = level.GetElement(oldPos);

            switch (type)
            {
            case ElementType.Man: level.SetElement(oldPos, ElementType.Floor); break;

            case ElementType.ManOnGoal: level.SetElement(oldPos, ElementType.Goal); break;

            default: return;
            }
            ElementType type2 = level.GetElement(newPos);

            switch (type2)
            {
            case ElementType.Floor: level.SetElement(newPos, ElementType.Man); break;

            case ElementType.Goal: level.SetElement(newPos, ElementType.ManOnGoal); break;

            default: return;
            }
        }
示例#4
0
        public static void MoveBox(this LevelGrid level, Point oldPos, Point newPos)
        {
            var type = level.GetElement(oldPos);

            switch (type)
            {
            case ElementType.Box: level.SetElement(oldPos, ElementType.Floor); break;

            case ElementType.BoxOnGoal: level.SetElement(oldPos, ElementType.Goal); break;

            default: return;
            }
            var type2 = level.GetElement(newPos);

            switch (type2)
            {
            case ElementType.Floor: level.SetElement(newPos, ElementType.Box); break;

            case ElementType.Goal: level.SetElement(newPos, ElementType.BoxOnGoal); break;

            default: return;
            }
        }
示例#5
0
 public LevelLogic(LevelGrid level)
 {
     levelStates.Add(level);
     SetPlayerPos();
 }
示例#6
0
 public static void SetElement(this LevelGrid level, Point position, ElementType type)
 {
     level.SetElement(position.X, position.Y, type);
 }