Ejemplo n.º 1
0
    public static bool MoveTrainForward(World model)
    {
        Logger.Log("Current: " + model.train.color + ", " + "Next: " + model.train.nextColor);

        Point             trainPoint = PointService.GetPointInGrid(model, model.train.toGridPos);
        List <Connection> cons       = ConnectionService.GetConnectionsForPointId(model, trainPoint.id);

        Connection matchingConnection = cons.Find(x => x.color == model.train.nextColor);

        if (matchingConnection == null)
        {
            matchingConnection = cons.Find(x => x.color == model.train.color);
        }
        else
        {
            model.train.color = model.train.nextColor;
        }

        if (matchingConnection == null)
        {
            Logger.Log("Game Over!");
            return(false);
        }
        else
        {
            Point forwardPoint = PointService.GetPointWithId(model, matchingConnection.toPointId);
            model.train.fromGridPos = model.train.toGridPos;
            model.train.toGridPos   = forwardPoint.gridPos;
            return(true);
        }
    }
Ejemplo n.º 2
0
    public static void GeneratePath(World model, int width, int height)
    {
        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                Point p = PointService.CreatePoint(model);
                p.pos       = new Vector(x, y);
                p.gridPos.x = x;
                p.gridPos.y = y;
            }
        }

        for (int i = 0; i < 3; i++)
        {
            ColorType randomFreeColor = ColorService.GetFreeColor(model);
            Point     randomPoint     = PointService.GetPointInGrid(model, MathService.RandomRange(0, width), 0);
            PointService.AddColorToPointWithId(model, randomPoint.id, randomFreeColor);
        }
    }
Ejemplo n.º 3
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));
                        }
                    }
                }
            }
        }
    }