Exemplo n.º 1
0
    private BallData[,] GetPlaneBoardData(BallData[,,] model, int[] sizes, bool inverseZ, Func <BallData[, , ], int[], BallData> getter)
    {
        Assert.AreEqual(sizes.Length, 3);
        BallData[,] result = new BallData[sizes[0], sizes[1]];
        for (int first = 0; first < sizes[0]; first++)
        {
            for (int second = 0; second < sizes[1]; second++)
            {
                int third = 0;
                while (third < sizes[2])
                {
                    int iThird = Functions.Inverse(third, sizes[2], inverseZ);

                    BallData ball = getter(model, new int[3] {
                        first, second, iThird
                    });
                    if (ball.BallType != BallType.EMPTY)
                    {
                        result[first, second] = ball;
                        break;
                    }
                    third++;
                }
                if (third >= sizes[2])
                {
                    result[first, second] = BallData.GetEmptyBall();
                }
            }
        }
        return(result);
    }
Exemplo n.º 2
0
    //Get the new ball positions from the slice and place the balls to their new positions
    // It relies on the fact that any balltype/objectiveType combiantion is only present once.
    //If a level has two balls exactly similar, this function may not work anymore
    public void SetNewBallPositions(SliceBoard slice)
    {
        Dictionary <BallData, IntVector3> currentPositions = new Dictionary <BallData, IntVector3>();

        for (int x = 0; x < X_SIZE; x++)
        {
            for (int y = 0; y < Y_SIZE; y++)
            {
                for (int z = 0; z < Z_SIZE; z++)
                {
                    if (balls[x, y, z].BallType == BallType.NORMAL)
                    {
                        currentPositions.Add(balls[x, y, z], new IntVector3(x, y, z));
                    }
                }
            }
        }

        FaceModel faceModel = FaceModel.ModelsDictionary[slice.face];

        var newPositions = slice.GetBallsPositions();
        var filledTiles  = slice.GetFilledTiles();

        foreach (var pair in currentPositions)
        {
            bool wasFilled = filledTiles.Contains(pair.Key.ObjectiveType);
            if (newPositions.ContainsKey(pair.Key) || wasFilled)
            {
                balls.Set(pair.Value, BallData.GetEmptyBall());
            }
        }
        foreach (var pair in currentPositions)
        {
            IntVector3 newPosition;
            if (newPositions.TryGetValue(pair.Key, out newPosition))
            {
                IntVector3 realPosition = new IntVector3();
                realPosition[faceModel.axes[0]] = newPosition.X;
                realPosition[faceModel.axes[1]] = newPosition.Y;
                realPosition[faceModel.axes[2]] = pair.Value[faceModel.axes[2]];

                balls.Set(realPosition, pair.Key);
            }
        }
        CheckLevelCompleted();
        HasChanged.Invoke(this);
    }
Exemplo n.º 3
0
    public Dictionary <BallData, IntVector3> GetBallsPositions()
    {
        BallData[,] realBalls = new BallData[Width, Height];
        for (int x = 0; x < Width; x++)
        {
            for (int y = 0; y < Height; y++)
            {
                if (!board[x, y].ball.IsEmpty() && !board[x, y].ball.IsWall())
                {
                    realBalls[x, y] = new BallData(BallType.NORMAL, board[x, y].ball.GetObjectiveType());
                }
                else
                {
                    realBalls[x, y] = BallData.GetEmptyBall();
                }
            }
        }
        FaceModel faceModel = FaceModel.ModelsDictionary[face];

        realBalls = realBalls.Rotate(360 - rotation);

        if (faceModel.mirrorAxis != -1)
        {
            realBalls = realBalls.Mirror(faceModel.mirrorAxis);
        }
        Dictionary <BallData, IntVector3> result = new Dictionary <BallData, IntVector3>();

        for (int x = 0; x < Width; x++)
        {
            for (int y = 0; y < Height; y++)
            {
                if (realBalls[x, y].BallType == BallType.NORMAL)
                {
                    IntVector3 point = new IntVector3(x, y);
                    result.Add(realBalls[x, y], point);
                }
            }
        }
        return(result);
    }
Exemplo n.º 4
0
 private BallData[,,] InitBalls(IntVector3 sizes)
 {
     BallData[,,] result = new BallData[sizes.X, sizes.Y, sizes.Z];
     for (int i = 0; i < sizes.X; i++)
     {
         for (int j = 0; j < sizes.Y; j++)
         {
             for (int k = 0; k < sizes.Z; k++)
             {
                 if (oldBalls.GetLength(0) > i && oldBalls.GetLength(1) > j && oldBalls.GetLength(2) > k)
                 {
                     result[i, j, k] = oldBalls[i, j, k];
                 }
                 else
                 {
                     result[i, j, k] = BallData.GetEmptyBall();
                 }
             }
         }
     }
     return(result);
 }
Exemplo n.º 5
0
 public void CreateBoard(int width, int height)
 {
     Assert.IsTrue(oldTiles.GetLength(0) == oldBalls.GetLength(0) && oldTiles.GetLength(1) == oldBalls.GetLength(1));
     tiles = new TileData[width, height];
     balls = new BallData[width, height];
     for (int i = 0; i < width; i++)
     {
         for (int j = 0; j < height; j++)
         {
             if (oldBalls.GetLength(0) > i && oldBalls.GetLength(1) > j)
             {
                 tiles[i, j] = oldTiles[i, j];
                 balls[i, j] = oldBalls[i, j];
             }
             else
             {
                 tiles[i, j] = TileData.GetNormalTile();
                 balls[i, j] = BallData.GetEmptyBall();
             }
         }
     }
     UpdateModel();
 }