예제 #1
0
파일: Utils.cs 프로젝트: huiliu/Sokoban
        private static Cell CreateCellOrBlock(LevelMap map, char data, int r, int c)
        {
            var cell = null as Cell;

            if (data == Floor ||
                data == Wall ||
                data == Box ||
                data == Pusher)
            {
                cell = new Cell(map, CellType.Floor, new Point(r, c));
            }

            if (data == Goal ||
                data == BoxOnGoal ||
                data == PusherOnGoal)
            {
                cell = new Cell(map, CellType.Goal, new Point(r, c));
            }

            var block = null as Entity;

            if (data == Wall)
            {
                block = new Wall(cell);
            }

            if (data == Box ||
                data == BoxOnGoal)
            {
                block = new Box(cell);
            }

            if (data == Pusher ||
                data == PusherOnGoal)
            {
                block = new Pusher(cell);
            }


            if (block != null)
            {
                cell.SetEntity(block);
            }

            return(cell);
        }
예제 #2
0
파일: Utils.cs 프로젝트: huiliu/Sokoban
        public static LevelMap ParseLevelData(List <string> data)
        {
            var map     = new LevelMap();
            var mapData = new List <List <Cell> >();

            for (var r = 0; r < data.Count; ++r)
            {
                var count = data[r].Length;
                var row   = new List <Cell>();
                for (var c = 0; c < count; ++c)
                {
                    row.Add(CreateCellOrBlock(map, data[r][c], r, c));
                }

                mapData.Add(row);
            }
            map.SetData(mapData);

            return(map);
        }