Exemple #1
0
    public static void ConnectPathFromPreviousNodeColors(World model, int width, int height)
    {
        for (int y = 1; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                Point fromPoint = PointService.GetPointInGrid(model, x, y - 1);

                for (int i = fromPoint.colors.Count - 1; i >= 0; i--)
                {
                    ColorType color = fromPoint.colors[i];
                    fromPoint.colors.Remove(color);

                    Point toPoint = PointService.GetPointInGrid(
                        model,
                        MathService.RandomRange(
                            MathService.Clamp(x - 1, 0, width),
                            MathService.Clamp(x + 2, 0, width)),
                        y
                        );

                    ConnectionService.CreateConnection(model, fromPoint.id, toPoint.id, color);

                    if (MathService.Random() < 0.75f)
                    {
                        PointService.AddColorToPointWithId(model, toPoint.id, color);
                    }
                    else
                    {
                        ColorService.ReleaseColor(model, color);
                        for (int j = 0; j < MathService.RandomRange(1, 1); j++)
                        {
                            PointService.AddColorToPointWithId(model, toPoint.id, ColorService.GetFreeColor(model));
                        }
                    }
                }
            }
        }
    }