Exemple #1
0
    private void BuildRoutes()
    {
        float prob = 1f;
        Point newPoint;

        for (int j = 0; j < nextRoute; j++)
        {
            for (int i = 0; i < lvlCount; i++)
            {
                if (j == 0)
                {
                    prob = 1f;
                }
                float rand = Random.Range(0f, 1f);
                if (i < lvlCount - 1)
                {
                    if (rand < prob)
                    {
                        if (i == lvlCount - 2)
                        {
                            newPoint = new Point(pointType[1]);
                        }
                        else if (i == 0)
                        {
                            newPoint = new Point(pointType[0]);
                        }
                        else
                        {
                            newPoint = new Point(randAPointType());
                            //newPoint = new Point(pointType[2]);
                        }
                        levels[i].GetPoints()[levels[i].GetPoints().Count - 1].AddConnectionBetween(newPoint);
                        levels[i + 1].addPointToLevel(newPoint);
                        prob = newRouteProb;
                    }
                    else
                    {
                        Point point  = levels[i].GetPoints()[levels[i].GetPoints().Count - 1];
                        Point point2 = levels[i + 1].GetPoints()[levels[i + 1].GetPoints().Count - 1];
                        if (!point.IsConnectedTo(point2))
                        {
                            point.AddConnectionBetween(point2);
                        }
                        prob += probWhenFail;
                    }
                }
                else
                {
                    Point point  = levels[i].GetPoints()[levels[i].GetPoints().Count - 1];
                    Point point2 = levels[i + 1].GetPoints()[levels[i + 1].GetPoints().Count - 1];
                    if (!point.IsConnectedTo(point2))
                    {
                        point.AddConnectionBetween(point2);
                    }
                    prob = newRouteProb;
                }
            }
        }
    }