Пример #1
0
        private void LoadSolution()
        {
            var lines           = Level.SolutionFile.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
            var boardParameters = lines.First().Split(',').Select(int.Parse).ToList();
            var width           = boardParameters[0];
            var height          = boardParameters[1];
            var board           = new Board(width, height);

            for (var y = 0; y < height; y++)
            {
                var line = lines[y + 1].Split(WidthSeparator.ToCharArray());
                for (var x = 0; x < width; x++)
                {
                    var cell = line[x].Split(DepthSeparator.ToCharArray());

                    var piecePrefabName = cell[0];
                    var botPrefabName   = cell[1];

                    Piece piece = null;
                    Bot   bot   = null;

                    if (piecePrefabName != string.Empty)
                    {
                        var isRandom    = piecePrefabName == "piece";
                        var pieceNumber = isRandom ? -1 : int.Parse(piecePrefabName.Substring(5));
                        piece = new Piece(new Vector2Int(x, y), pieceNumber, null, isRandom);
                    }

                    if (botPrefabName != string.Empty)
                    {
                        bot = new Bot(new Vector2Int(x, y), null);
                    }

                    board[x, y] = new Field(TileType.Normal, bot, piece);
                }
            }

            _solution = board;
        }
Пример #2
0
        public void LoadLevel()
        {
            var lines           = Level.File.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
            var boardParameters = lines.First().Split(',').Select(int.Parse).ToList();
            var width           = boardParameters[0];
            var height          = boardParameters[1];
            var board           = new Board(width, height);

            for (var y = 0; y < height; y++)
            {
                var line = lines[y + 1].Split(WidthSeparator.ToCharArray());
                for (var x = 0; x < width; x++)
                {
                    var cell = line[x].Split(DepthSeparator.ToCharArray());

                    var piecePrefabName = cell[0];
                    var botPrefabName   = cell[1];
                    var tilePrefabName  = cell[2];

                    Piece piece    = null;
                    Bot   bot      = null;
                    var   tileType = TileType.Hole;

                    if (piecePrefabName != string.Empty)
                    {
                        var isRandom    = piecePrefabName == "piece";
                        var pieceNumber = isRandom
                            ? Random.Next(100)
                            : int.Parse(piecePrefabName.Substring(5));
                        var pieceTransform = CreateGameObject("piece", x, y, 1);
                        piece = new Piece(new Vector2Int(x, y), pieceNumber, pieceTransform, isRandom);
                    }

                    if (botPrefabName != string.Empty)
                    {
                        var botTransform = CreateGameObject(botPrefabName, x, y, 1);
                        var botAnimator  = botTransform.GetComponent <BotAnimator>();
                        bot             = new Bot(new Vector2Int(x, y), botAnimator);
                        botAnimator.Bot = bot;
                    }

                    if (tilePrefabName != string.Empty)
                    {
                        var rotation = Quaternion.identity;
                        if (y == 0 || y == height - 1)
                        {
                            rotation = Quaternion.AngleAxis(90, Vector3.forward);
                            if (x == 0 && y == 0)
                            {
                                rotation = Quaternion.AngleAxis(90, Vector3.back);
                            }
                            if (x == 0 && y == height - 1)
                            {
                                rotation = Quaternion.AngleAxis(180, Vector3.forward);
                            }
                            if (x == width - 1 && y == 0)
                            {
                                rotation = Quaternion.AngleAxis(0, Vector3.forward);
                            }
                        }

                        var tile = CreateGameObject(tilePrefabName, x, y, 2, rotation).GetComponent <Tile>();
                        tileType = tile.TileType;
                    }

                    var field = new Field(tileType, bot, piece);
                    board[x, y] = field;
                }
            }

            _board = board;
            ClipLevel();
            GameObject.Find("ExecutionIndicatorManager").GetComponent <ExecutionIndicatorManager>()
            .AssignColorsToBots(_board.Bots);
        }