Exemple #1
0
    public static List <Texture2D> GetSquareTextures(SquareBlocks sqBlock)
    {
        var listBlocks       = GetBlockPrefab(sqBlock.block);
        var listObstacles    = GetBlockPrefab(sqBlock.obstacle);
        var textureBlocks    = listBlocks.Select(i => i.GetComponent <SpriteRenderer>().sprite.texture).Take(sqBlock.blockLayer);
        var textureObstacles = listObstacles.Select(i => i.GetComponent <SpriteRenderer>().sprite.texture).Take(sqBlock.obstacleLayer);
        var resultList       = new List <Texture2D>();

        resultList.AddRange(textureBlocks);
        if (sqBlock.obstacle != SquareTypes.NONE)
        {
            resultList.AddRange(textureObstacles);
        }

        return(resultList);
    }
    public void openLeveltxt(string mapText)
    {
        string[] vs      = null;
        string[] lines   = mapText.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
        int      mapline = 0;

        foreach (string line in lines)
        {
            if (line.StartsWith("MODE"))
            {
                string modeSting = line.Replace("MODE", string.Empty).Trim();
                t       = int.Parse(modeSting);
                modeLvl = int.Parse(modeSting);
            }
            else if (line.StartsWith("SIZE"))
            {
                string   blockString = line.Replace("SIZE", string.Empty).Trim();
                string[] sizes       = blockString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                MaxX = int.Parse(sizes[0]);
                MaxY = int.Parse(sizes[1]);
                //GetMoveLayer.loadSize(MaxX, MaxY);//
                Arrays.THIS.SizeX = int.Parse(sizes[0]);
                Arrays.THIS.SizeY = int.Parse(sizes[1]);
                Blocksf           = new SquareBlocks[MaxY * MaxX];
                for (int i = 0; i < Blocksf.Length; i++)
                {
                    SquareBlocks sqBlocks = new SquareBlocks();
                    sqBlocks.Changeblck(1);//
                    sqBlocks.obstacle = 0;
                    Blocksf[i]        = sqBlocks;
                }
            }
            else if (line.StartsWith("LIMIT"))
            {
                string   blockString = line.Replace("LIMIT", string.Empty).Trim();
                string[] sizes       = blockString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                ltype = int.Parse(sizes[0]);
                Limit = int.Parse(sizes[1]);
            }
            else if (line.StartsWith("COLOR LIMIT "))
            {
                string blockString = line.Replace("COLOR LIMIT", string.Empty).Trim();
                colorLimit = int.Parse(blockString);
            }
            else if (line.StartsWith("STARS"))
            {
                string   starsline    = line.Replace("STARS", string.Empty).Trim();
                string[] starsNumbers = starsline.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                score1 = int.Parse(starsNumbers[0]);
                score2 = int.Parse(starsNumbers[1]);
                score3 = int.Parse(starsNumbers[2]);
                //if (ProgressBarScript.Instance != null) ProgressBarScript.Instance.InitBar();
            }
            else if (line.StartsWith("COLLECT COUNT"))
            {
                string   blocksString  = line.Replace("COLLECT COUNT", string.Empty).Trim();
                string[] blocksNumbers = blocksString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < blocksNumbers.Length; i++)
                {
                    ingCtar[i] = int.Parse(blocksNumbers[i]);
                }
            }
            else if (line.StartsWith("COLLECT ITEMS"))
            {
                string   blocksString  = line.Replace("COLLECT ITEMS", string.Empty).Trim();
                string[] blocksNumbers = blocksString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < blocksNumbers.Length; i++)
                {
                    if (t == 2)
                    {
                        ingTarget[i] = int.Parse(blocksNumbers[i]);
                    }
                    else if (t == 1)
                    {
                        collectItems[i] = int.Parse(blocksNumbers[i]);             //
                    }
                }//
            }
            else
            {
                string[] st = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < st.Length; i++)
                {
                    Blocksf[(mapline * MaxX) + i].blck     = int.Parse(st[i][0].ToString()); //
                    Blocksf[(mapline * MaxX) + i].obstacle = int.Parse(st[i][1].ToString()); //
                }
                mapline++;
            }
        }
    }
Exemple #3
0
 /// <summary>
 /// change square type
 /// </summary>
 /// <param name="sqBlock"></param>
 public void SetType(SquareBlocks sqBlock)
 {
     SetType(sqBlock.block, sqBlock.blockLayer, sqBlock.obstacle, sqBlock.obstacleLayer);
 }
    /// <summary>
    /// длина,ширина мод, цели и т.д.
    /// </summary>
    /// <param name="mapText"></param>
    public void ProcessGameDataFromString(string mapText)
    {
        string[] vs      = null;
        string[] lines   = mapText.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
        int      mapline = 0;

        foreach (string line in lines)
        {
            if (line.StartsWith("MODE"))
            {
                string modeSting = line.Replace("MODE", string.Empty).Trim();
                target  = int.Parse(modeSting);
                modeLvl = int.Parse(modeSting);
            }
            else if (line.StartsWith("SIZE"))
            {
                string   blockString = line.Replace("SIZE", string.Empty).Trim();
                string[] sizes       = blockString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                maxCols         = int.Parse(sizes[0]); //9
                maxRows         = int.Parse(sizes[1]); //5
                GetArrays.SizeX = int.Parse(sizes[0]);
                GetArrays.SizeY = int.Parse(sizes[1]);
                squaresArray    = new Block[maxCols * maxRows];
                levelSquareFile = new SquareBlocks[maxRows * maxCols];
                for (int i = 0; i < levelSquareFile.Length; i++)
                {
                    SquareBlocks sqBlocks = new SquareBlocks();
                    //sqBlocks = 1;//
                    //sqBlocks.obstacle = SquareTypes.NONE;
                    levelSquareFile[i] = sqBlocks;
                }
            }
            else if (line.StartsWith("LIMIT"))
            {
                string   blockString = line.Replace("LIMIT", string.Empty).Trim();
                string[] sizes       = blockString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                limitType = int.Parse(sizes[0]);
                Limit     = int.Parse(sizes[1]);
            }
            else if (line.StartsWith("COLOR LIMIT "))
            {
                string blockString = line.Replace("COLOR LIMIT", string.Empty).Trim();
                colorLimit = int.Parse(blockString);
            }
            else if (line.StartsWith("STARS"))
            {
                string   blockString   = line.Replace("STARS", string.Empty).Trim();
                string[] blocksNumbers = blockString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                star1 = int.Parse(blocksNumbers[0]);
                star2 = int.Parse(blocksNumbers[1]);
                star3 = int.Parse(blocksNumbers[2]);
                //if (ProgressBarScript.Instance != null) ProgressBarScript.Instance.InitBar();
            }
            else if (line.StartsWith("COLLECT COUNT"))
            {
                string   blocksString  = line.Replace("COLLECT COUNT", string.Empty).Trim();
                string[] blocksNumbers = blocksString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < blocksNumbers.Length; i++)
                {
                    ingrCountTarget[i] = int.Parse(blocksNumbers[i]);
                }
            }
            else if (line.StartsWith("COLLECT ITEMS"))
            {
                string   blocksString  = line.Replace("COLLECT ITEMS", string.Empty).Trim();
                string[] blocksNumbers = blocksString.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < blocksNumbers.Length; i++)
                {
                    if (target == 0)
                    {
                        ingTarget[i] = int.Parse(blocksNumbers[i]);
                    }
                    else if (target == 1)
                    {
                        collectItems[i] = int.Parse(blocksNumbers[i]);
                    }
                }
            }
            else
            {
                /*string[] st = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                 * for (int i = 0; i < st.Length; i++)
                 * {
                 *  //levelSquareFile[mapline * maxCols + i].block = (SquareTypes)int.Parse(st[i][0].ToString());
                 *  //levelSquareFile[mapline * maxCols + i].obstacle = (SquareTypes)int.Parse(st[i][1].ToString());
                 * }*/
                mapline++;
            }
        }

        levelLoaded = true;
    }