Пример #1
0
    public int[,] GenerateGridLevel(int width, int height)
    {
        if (width <= 0 || height <= 0)
        {
            return(new int[0, 0]);
        }
        int[,] a = new int[width * 20, height * 20];


        CalculateLists();
        LevelTemplate last = rightList[Random.Range(0, rightList.Count)];
        LevelTemplate current;

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                if (y % 2 == 0)
                {
                    if (x == 0)
                    {
                        do
                        {
                            current = rightList[Random.Range(0, rightList.Count)];
                        } while (!current.HasDownWay());
                        last = current;
                        if (y == height - 1)
                        {
                            PlaceInto(a, last.levelPart, x * 20, y * 20, 12, true, false, false, true);
                        }
                        else if (y == 0)
                        {
                            PlaceInto(a, last.levelPart, x * 20, y * 20, 10, true, false, true, false);
                        }
                        else
                        {
                            PlaceInto(a, last.levelPart, x * 20, y * 20, 12, true, false, false, false);
                        }
                    }
                    else if (x == width - 1)
                    {
                        do
                        {
                            current = rightAndLeftList[Random.Range(0, rightAndLeftList.Count)];
                        } while (!last.CanCrossRightTo(current) || !current.HasUpWay());
                        last = current;
                        if (y == height - 1)
                        {
                            PlaceInto(a, last.levelPart, x * 20, y * 20, 12, false, true, false, true);
                        }
                        else if (y == 0)
                        {
                            PlaceInto(a, last.levelPart, x * 20, y * 20, 12, false, true, true, false);
                        }
                        else
                        {
                            PlaceInto(a, last.levelPart, x * 20, y * 20, 12, false, true, false, false);
                        }
                    }
                    else
                    {
                        do
                        {
                            current = rightAndLeftList[Random.Range(0, rightAndLeftList.Count)];
                        } while (!last.CanCrossRightTo(current));
                        last = current;
                        if (y == height - 1)
                        {
                            PlaceInto(a, last.levelPart, x * 20, y * 20, 12, false, false, false, true);
                        }
                        else if (y == 0)
                        {
                            PlaceInto(a, last.levelPart, x * 20, y * 20, 12, false, false, true, false);
                        }
                        else
                        {
                            PlaceInto(a, last.levelPart, x * 20, y * 20, 12, false, false, false, false);
                        }
                    }
                }
                else if (y % 2 == 1)
                {
                    if (x == 0)
                    {
                        do
                        {
                            current = rightList[Random.Range(0, rightAndLeftList.Count)];
                        } while (!current.HasUpWay());
                        last = current;
                        if (y == height - 1)
                        {
                            PlaceInto(a, last.levelPart, x * 20, y * 20, 12, true, false, false, true);
                        }
                        else
                        {
                            PlaceInto(a, last.levelPart, x * 20, y * 20, 12, true, false, false, false);
                        }
                    }
                    else if (x == width - 1)
                    {
                        do
                        {
                            current = leftList[Random.Range(0, leftList.Count)];
                        } while (!last.CanCrossRightTo(current) || !current.HasDownWay());
                        last = current;
                        if (y == height - 1)
                        {
                            PlaceInto(a, last.levelPart, x * 20, y * 20, 12, false, true, false, true);
                        }
                        else
                        {
                            PlaceInto(a, last.levelPart, x * 20, y * 20, 12, false, true, false, false);
                        }
                    }
                    else
                    {
                        do
                        {
                            current = rightAndLeftList[Random.Range(0, rightAndLeftList.Count)];
                        } while (!last.CanCrossRightTo(current));
                        last = current;
                        if (y == height - 1)
                        {
                            PlaceInto(a, last.levelPart, x * 20, y * 20, 12, false, false, false, true);
                        }
                        else
                        {
                            PlaceInto(a, last.levelPart, x * 20, y * 20, 12, false, false, false, false);
                        }
                    }
                }
                if (y == height - 1 && x == width - 1)
                {
                    PlaceInto(a, last.levelPart, x * 20, y * 20, 11, false, true, false, true);
                }
            }
        }



        return(a);
    }