/// <summary>
    /// Creates a string with the contents of the shapes array
    /// </summary>
    /// <param name="shapes"></param>
    /// <returns></returns>
    public static string GetArrayContents(ShapesArray shapes)
    {
        string x = string.Empty;
        for (int row = Constants.Rows - 1; row >= 0; row--)
        {

            for (int column = 0; column < Constants.Columns; column++)
            {
                if (shapes[row, column] == null)
                    x += "NULL  |";
                else
                {
                    var shape = shapes[row, column].GetComponent<Shape>();
                    x += shape.Row.ToString("D2")
                        + "-" + shape.Column.ToString("D2");

                    x += shape.Type.Substring(5, 2);

                    if (BonusTypeUtilities.ContainsDestroyWholeRowColumn(shape.Bonus))
                        x += "B";
                    else
                        x += " ";

                    x += " | ";
                }
            }
            x += Environment.NewLine;
        }
        return x;
    }
Beispiel #2
0
    /// <summary>
    /// Create a string with the content of the shapes array
    /// </summary>
    /// <param name="shapes">shapes array</param>
    /// <returns>returns the string with the shapes array content</returns>
    public static string GetArrayContents(ShapesArray shapes)
    {
        string x = string.Empty;

        for (int row = Constants.Rows - 1; row >= 0; row--)
        {
            for (int column = 0; column < Constants.Columns; column++)
            {
                if (shapes[row, column] == null)
                {
                    x += "NULL  |";
                }
                else
                {
                    var shape = shapes[row, column].GetComponent <Shape>();
                    x += shape.Row.ToString("D2") + "-" + shape.Column.ToString("D2");
                    x += shape.Type.Substring(5, 2);
                    x += " ";
                    x += " | ";
                }
            }

            x += Environment.NewLine;
        }

        return(x);
    }
Beispiel #3
0
    public static List <GameObject> CheckVertical3(int row, int column, ShapesArray shapes)
    {
        if (row <= ConstantsVariable.Rows - 4)
        {
            if (shapes[row, column].GetComponent <Shape>().
                IsSameType(shapes[row + 1, column].GetComponent <Shape>()) &&
                shapes[row, column].GetComponent <Shape>().
                IsSameType(shapes[row + 3, column].GetComponent <Shape>()))
            {
                return(new List <GameObject>()
                {
                    shapes[row, column],
                    shapes[row + 1, column],
                    shapes[row + 3, column]
                });
            }
        }

        if (row >= 2 && row <= ConstantsVariable.Rows - 2)
        {
            if (shapes[row, column].GetComponent <Shape>().
                IsSameType(shapes[row + 1, column].GetComponent <Shape>()) &&
                shapes[row, column].GetComponent <Shape>().
                IsSameType(shapes[row - 2, column].GetComponent <Shape>()))
            {
                return(new List <GameObject>()
                {
                    shapes[row, column],
                    shapes[row + 1, column],
                    shapes[row - 2, column]
                });
            }
        }
        return(null);
    }
    public void InitializeCandyAndSpawnPositionsFromPremadeLevel()
    {
        InitializeVariables();

        var premadeLevel = DebugUtilities.FillShapesArrayFromResourcesData();

        if (shapes != null)
            DestroyAllCandy();

        shapes = new ShapesArray();
        SpawnPositions = new Vector2[Constants.Columns];

        for (int row = 0; row < Constants.Rows; row++)
        {
            for (int column = 0; column < Constants.Columns; column++)
            {

                GameObject newCandy = null;

                newCandy = GetSpecificCandyOrBonusForPremadeLevel(premadeLevel[row, column]);

                InstantiateAndPlaceNewCandy(row, column, newCandy);

            }
        }

        SetupSpawnPositions();
    }
Beispiel #5
0
    public void InitializeCandyAndSpawnPositionsFromPremadeLevel()
    {
        InitializeVariables();

        var premadeLevel = DebugUtilities.FillShapesArrayFromResourcesData();

        if (shapes != null)
        {
            DestroyAllCandy();
        }

        shapes         = new ShapesArray();
        SpawnPositions = new Vector2[Constants.Columns];

        for (int row = 0; row < Constants.Rows; row++)
        {
            for (int column = 0; column < Constants.Columns; column++)
            {
                GameObject newCandy = null;

                newCandy = GetSpecificCandyOrBonusForPremadeLevel(premadeLevel[row, column]);

                InstantiateAndPlaceNewCandy(row, column, newCandy);
            }
        }

        SetupSpawnPositions();
    }
Beispiel #6
0
        /// <summary>
        /// Creates a new geometric graph.
        /// </summary>
        public GeometricGraph(MemoryMap map, GeometricGraphProfile profile, int edgeDataSize, int size)
        {
            if (profile == null)
            {
                _graph       = new Graph(map, edgeDataSize, size);
                _coordinates = new Array <float>(map, size * 2);
                for (var i = 0; i < _coordinates.Length; i++)
                {
                    _coordinates[i] = NO_COORDINATE;
                }
                _shapes = new ShapesArray(map, size);
            }
            else
            {
                _graph       = new Graph(map, profile.GraphProfile, edgeDataSize, size);
                _coordinates = new Array <float>(map, size * 2, profile.CoordinatesProfile);
                for (var i = 0; i < _coordinates.Length; i++)
                {
                    _coordinates[i] = NO_COORDINATE;
                }
                _shapes = new ShapesArray(map, size);
            }

            _createElevation = (s) =>
            {
                return(new Array <short>(map, size));
            };
        }
        private Graph(int zoom, int edgeDataSize, int tileSizeInIndex, SparseMemoryArray <byte> tiles,
                      int coordinateSizeInBytes, MemoryArray <byte> vertices, uint vertexPointer, MemoryArray <uint> edgePointers,
                      uint edgePointer, MemoryArray <byte> edges, ShapesArray shapes)
        {
            _zoom         = zoom;
            _edgeDataSize = edgeDataSize;
            _edgeSize     = 8 * 2 +        // the vertices.
                            4 * 2 +        // the pointers to previous edges.
                            _edgeDataSize; // the edge data package.

            if (TileSizeInIndex != tileSizeInIndex)
            {
                throw new ArgumentOutOfRangeException($"{nameof(tileSizeInIndex)}");
            }
            _tiles = tiles;
            if (CoordinateSizeInBytes != coordinateSizeInBytes)
            {
                throw new ArgumentOutOfRangeException($"{nameof(coordinateSizeInBytes)}");
            }
            _vertices      = vertices;
            _vertexPointer = vertexPointer;
            _edgePointers  = edgePointers;
            _edgePointer   = edgePointer;
            _edges         = edges;
            _shapes        = shapes;
        }
Beispiel #8
0
    /// <summary>
    /// Check #4 for vertical potential matches
    /// </summary>
    /// <param name="row">Row of the object from which the check will be performed</param>
    /// <param name="column">Column of the object from which the check will be performed</param>
    /// <param name="shapes">Shapes array</param>
    /// <returns>List of objects for a potential match</returns>
    public static List <GameObject> CheckVertical4(int row, int column, ShapesArray shapes)
    {
        /* example
         * * * *     * * * *
         * * 2 *	 * 2 * *
         * 3 * *	 * * 3 *
         * * 1 *	 * 1 * *
         * * * *	 * * * *
         */
        List <GameObject> match = new List <GameObject>();

        if ((row <= Constants.Rows - 3) && shapes.IsSameType(row, column, 2, 0))
        {
            match.Add(shapes[row + 2, column]);

            if ((column >= 1) && shapes.IsSameType(row, column, 1, -1))
            {
                match.Add(shapes[row + 1, column - 1]);
            }

            else if ((column <= Constants.Columns - 2) && shapes.IsSameType(row, column, 1, 1))
            {
                match.Add(shapes[row + 1, column + 1]);
            }
        }

        return(match);
    }
Beispiel #9
0
        /// <summary>
        /// Deserializes from the given stream.
        /// </summary>
        public static ShapesDb Deserialize(Stream stream)
        {
            var version = stream.ReadByte();

            if (version != 1)
            {
                throw new Exception("Cannot deserialize stops db, version # doesn't match.");
            }

            // read size.
            var sizeBytes = new byte[8];

            stream.Read(sizeBytes, 0, 8);
            var size = BitConverter.ToInt64(sizeBytes, 0);

            // read index.
            var index = new MemoryArray <uint>(size);

            index.CopyFrom(stream);

            // read shapes.
            var shapes = ShapesArray.CreateFrom(stream, true);

            return(new ShapesDb(size, index, shapes));
        }
Beispiel #10
0
 /// <summary>
 /// Creates a new geometric graph.
 /// </summary>
 private GeometricGraph(Graph graph, ArrayBase <float> coordinates,
                        ShapesArray shapes)
 {
     _graph       = graph;
     _coordinates = coordinates;
     _shapes      = shapes;
 }
Beispiel #11
0
 public static List <GameObject> CheckHorizontal3(int row, int column, ShapesArray shapes)
 {
     if (column <= ConstantsVariable.Columns - 4)
     {
         if (shapes[row, column].GetComponent <Shape>().
             IsSameType(shapes[row, column + 1].GetComponent <Shape>()) &&
             shapes[row, column].GetComponent <Shape>().
             IsSameType(shapes[row, column + 3].GetComponent <Shape>()))
         {
             return(new List <GameObject>()
             {
                 shapes[row, column],
                 shapes[row, column + 1],
                 shapes[row, column + 3]
             });
         }
     }
     if (column >= 2 && column <= ConstantsVariable.Columns - 2)
     {
         if (shapes[row, column].GetComponent <Shape>().
             IsSameType(shapes[row, column + 1].GetComponent <Shape>()) &&
             shapes[row, column].GetComponent <Shape>().
             IsSameType(shapes[row, column - 2].GetComponent <Shape>()))
         {
             return(new List <GameObject>()
             {
                 shapes[row, column],
                 shapes[row, column + 1],
                 shapes[row, column - 2]
             });
         }
     }
     return(null);
 }
Beispiel #12
0
    /// <summary>
    /// Check #4 for horizontal potential matches
    /// </summary>
    /// <param name="row">Row of the object from which the check will be performed</param>
    /// <param name="column">Column of the object from which the check will be performed</param>
    /// <param name="shapes">Shapes array</param>
    /// <returns>List of objects for a potential match</returns>
    public static List <GameObject> CheckHorizontal4(int row, int column, ShapesArray shapes)
    {
        List <GameObject> match = new List <GameObject>();

        if ((column <= Constants.Columns - 3) && shapes.IsSameType(row, column, 0, 2))
        {
            match.Add(shapes[row, column + 2]);

            if ((row <= Constants.Rows - 2) && shapes.IsSameType(row, column, 1, 1))
            {
                match.Add(shapes[row + 1, column + 1]);

                /* * * * *
                * * 3 * *
                * 1 * 2 *
                * * * * */
            }

            else if ((row >= 1) && shapes.IsSameType(row, column, -1, 1))
            {
                match.Add(shapes[row - 1, column + 1]);

                /* * * * *
                * 1 * 2 *
                * * 3 * *
                * * * * */
            }
        }

        return(match);
    }
Beispiel #13
0
    public void InitializeCandyAndSpawnPositions()
    {
        if (shapes != null)
        {
            DestroyAllCandy();
        }

        shapes         = new ShapesArray();
        SpawnPositions = new Vector2[Constants.Columns];

        for (int row = 0; row < Constants.Rows; row++)
        {
            for (int column = 0; column < Constants.Columns; column++)
            {
                GameObject newCandy = GetRandomCandy();
                //check if two previous horizontal are of the same type
                while ((column >= 2 && shapes[row, column - 1].GetComponent <Shape>()
                        .IsSameType(newCandy.GetComponent <Shape>()) &&
                        shapes[row, column - 2].GetComponent <Shape>().IsSameType(newCandy.GetComponent <Shape>()))
                       ||
                       (row >= 2 && shapes[row - 1, column].GetComponent <Shape>()
                        .IsSameType(newCandy.GetComponent <Shape>()) &&
                        shapes[row - 2, column].GetComponent <Shape>().IsSameType(newCandy.GetComponent <Shape>()))
                       )
                {
                    newCandy = GetRandomCandy();
                }

                InstantiateAndPlaceNewCandy(row, column, newCandy);
            }
        }

        SetupSpawnPositions();
    }
Beispiel #14
0
    public static List <GameObject> CheckVertical2(int row, int column, ShapesArray shapes)
    {
        if (row <= Constants.Rows - 3)
        {
            if (shapes[row, column].GetComponent <Shape>().
                IsSameType(shapes[row + 1, column].GetComponent <Shape>()))
            {
                if (column >= 1)
                {
                    if (shapes[row, column].GetComponent <Shape>().
                        IsSameType(shapes[row + 2, column - 1].GetComponent <Shape>()))
                    {
                        return new List <GameObject>()
                               {
                                   shapes[row, column],
                                   shapes[row + 1, column],
                                   shapes[row + 2, column - 1],
                                   shapes[row + 2, column]
                               }
                    }
                }
                ;

                /* example *\
                 * * * * *
                 * & * * * *
                 * & * * *
                 * & * * *
                 * * * * *
                 \* example  */

                if (column <= Constants.Columns - 2)
                {
                    if (shapes[row, column].GetComponent <Shape>().
                        IsSameType(shapes[row + 2, column + 1].GetComponent <Shape>()))
                    {
                        return new List <GameObject>()
                               {
                                   shapes[row, column],
                                   shapes[row + 1, column],
                                   shapes[row + 2, column + 1],
                                   shapes[row + 2, column]
                               }
                    }
                }
                ;

                /* example *\
                 * * * * *
                 * * & * *
                 * & * * *
                 * & * * *
                 * * * * *
                 \* example  */
            }
        }
        return(null);
    }
Beispiel #15
0
    public static IEnumerable <GameObject> GetPotentialMatches(ShapesArray shapes)
    {
        // list to contain all found matches
        List <List <GameObject> > matches = new List <List <GameObject> >();

        for (int row = 0; row < Constants.Rows; row++)
        {
            for (int column = 0; column < Constants.Columns; column++)
            {
                var matches1 = CheckHorizontal1(row, column, shapes);
                var matches2 = CheckHorizontal2(row, column, shapes);
                var matches3 = CheckHorizontal3(row, column, shapes);
                var matches4 = CheckVertical1(row, column, shapes);
                var matches5 = CheckVertical2(row, column, shapes);
                var matches6 = CheckVertical3(row, column, shapes);

                if (matches1 != null)
                {
                    matches.Add(matches1);
                }
                if (matches2 != null)
                {
                    matches.Add(matches2);
                }
                if (matches3 != null)
                {
                    matches.Add(matches3);
                }
                if (matches4 != null)
                {
                    matches.Add(matches4);
                }
                if (matches5 != null)
                {
                    matches.Add(matches5);
                }
                if (matches6 != null)
                {
                    matches.Add(matches6);
                }

                // if more than 3 matches, return a random one.
                if (matches.Count >= 3)
                {
                    return(matches[UnityEngine.Random.Range(0, matches.Count - 1)]);
                }

                //if we are in the middle of the calculations/loops
                //and we have less than 3 matches, return a random one
                if (row >= Constants.Rows / 2 && matches.Count > 0 && matches.Count <= 2)
                {
                    return(matches[UnityEngine.Random.Range(0, matches.Count - 1)]);
                }
            }
        }
        return(null);
    }
Beispiel #16
0
        public void TestAddWithElevation()
        {
            using (var map = new MemoryMapStream())
            {
                var array = new ShapesArray(map, 1024);
                array.Set(0, new Coordinate(0, 0.1f, 10),
                          new Coordinate(1, 1.1f, 11));

                var shape = array[0];
                Assert.IsNotNull(shape);
                Assert.AreEqual(2, shape.Count);
                Assert.AreEqual(0, shape[0].Latitude, .00001);
                Assert.AreEqual(0.1, shape[0].Longitude, .00001);
                Assert.AreEqual(10, shape[0].Elevation);
                Assert.AreEqual(1, shape[1].Latitude, .00001);
                Assert.AreEqual(1.1, shape[1].Longitude, .00001);
                Assert.AreEqual(11, shape[1].Elevation);
            }

            using (var map = new MemoryMapStream())
            {
                var box = new Box(
                    new Coordinate(-90, -180),
                    new Coordinate(90, 180));
                var refArray = new ShapeBase[1024];
                var array    = new ShapesArray(map, 1024);

                var rand = new Randomizer(1587341311);
                for (var i = 0; i < 1024; i++)
                {
                    var count    = rand.Next(10);
                    var newShape = new List <Coordinate>(count);
                    for (var j = 0; j < count; j++)
                    {
                        newShape.Add(box.GenerateRandomIn());
                    }

                    var shape = new ShapeEnumerable(newShape);
                    refArray[i] = shape;
                    array[i]    = shape;
                }

                for (var i = 0; i < refArray.Length; i++)
                {
                    var refShape = refArray[i];
                    var shape    = array[i];
                    Assert.IsNotNull(shape);

                    for (var j = 0; j < shape.Count; j++)
                    {
                        Assert.AreEqual(refShape[j].Latitude, shape[j].Latitude);
                        Assert.AreEqual(refShape[j].Longitude, shape[j].Longitude);
                        Assert.AreEqual(refShape[j].Elevation, shape[j].Elevation);
                    }
                }
            }
        }
Beispiel #17
0
    public static List <GameObject> CheckHorizontal2(int row, int column, ShapesArray shapes)
    {
        if (column <= Variables.Columns - 3)
        {
            if (shapes[row, column].GetComponent <Shape>().
                IsSameType(shapes[row, column + 1].GetComponent <Shape>()))
            {
                if (row >= 1 && column <= Variables.Columns - 3)
                {
                    if (shapes[row, column].GetComponent <Shape>().
                        IsSameType(shapes[row - 1, column + 2].GetComponent <Shape>()))
                    {
                        return new List <GameObject>()
                               {
                                   shapes[row, column],
                                   shapes[row, column + 1],
                                   shapes[row - 1, column + 2]
                               }
                    }
                }
                ;

                /* example *\
                 * * * * *
                 * * * * *
                 * * * * *
                 * & & * *
                 * * * & *
                 \* example  */

                if (row <= Variables.Rows - 2 && column <= Variables.Columns - 3)
                {
                    if (shapes[row, column].GetComponent <Shape>().
                        IsSameType(shapes[row + 1, column + 2].GetComponent <Shape>()))
                    {
                        return new List <GameObject>()
                               {
                                   shapes[row, column],
                                   shapes[row, column + 1],
                                   shapes[row + 1, column + 2]
                               }
                    }
                }
                ;

                /* example *\
                 * * * * *
                 * * * * *
                 * * * & *
                 * & & * *
                 * * * * *
                 \* example  */
            }
        }
        return(null);
    }
Beispiel #18
0
 /// <summary>
 /// Creates a new geometric graph.
 /// </summary>
 public GeometricGraph(MemoryMap map, int edgeDataSize, int size)
 {
     _graph       = new Graph(map, edgeDataSize, size);
     _coordinates = new Array <float>(map, size * 2);
     for (var i = 0; i < _coordinates.Length; i++)
     {
         _coordinates[i] = NO_COORDINATE;
     }
     _shapes = new ShapesArray(map, size);
 }
Beispiel #19
0
 /// <summary>
 /// Creates a new geometric graph.
 /// </summary>
 public GeometricGraph(int edgeDataSize, int size)
 {
     _graph       = new Graph(edgeDataSize, size);
     _coordinates = Context.ArrayFactory.CreateMemoryBackedArray <float>(size * 2);
     for (var i = 0; i < _coordinates.Length; i++)
     {
         _coordinates[i] = NO_COORDINATE;
     }
     _shapes = new ShapesArray(size);
 }
Beispiel #20
0
 public GeometricGraph(MemoryMap map, int edgeDataSize, int size)
 {
     this._graph       = new Graph(map, edgeDataSize, (long)size);
     this._coordinates = (ArrayBase <float>) new Array <float>(map, (long)(size * 2));
     for (int index = 0; (long)index < this._coordinates.Length; ++index)
     {
         this._coordinates[(long)index] = float.MaxValue;
     }
     this._shapes = new ShapesArray(map, (long)size);
 }
Beispiel #21
0
    public static List <GameObject> CheckHorizontal3(int row, int column, ShapesArray shapes)
    {
        if (column <= Constants.Columns - 4)
        {
            if (shapes[row, column].GetComponent <Shape>().
                IsSameType(shapes[row, column + 1].GetComponent <Shape>()) &&
                shapes[row, column].GetComponent <Shape>().
                IsSameType(shapes[row, column + 3].GetComponent <Shape>()))
            {
                return(new List <GameObject>()
                {
                    shapes[row, column],
                    shapes[row, column + 1],
                    shapes[row, column + 3],
                    shapes[row, column + 2]
                });
            }

            /* example *\
             * * * * *
             * * * * *
             * * * * *
             * & & * &
             * * * * *
             \* example  */
        }
        if (column >= 2 && column <= Constants.Columns - 2)
        {
            if (shapes[row, column].GetComponent <Shape>().
                IsSameType(shapes[row, column + 1].GetComponent <Shape>()) &&
                shapes[row, column].GetComponent <Shape>().
                IsSameType(shapes[row, column - 2].GetComponent <Shape>()))
            {
                return(new List <GameObject>()
                {
                    shapes[row, column],
                    shapes[row, column + 1],
                    shapes[row, column - 2],
                    shapes[row, column - 1]
                });
            }

            /* example *\
             * * * * *
             * * * * *
             * * * * *
             * & * & &
             * * * * *
             \* example  */
        }
        return(null);
    }
Beispiel #22
0
    /// <summary>
    /// Checks entire play area for potential matches and picks the best one (most matched objects)
    /// </summary>
    /// <param name="shapes">shapes array</param>
    /// <returns>List of best objects in the best potential match</returns>
    public static IEnumerable <GameObject> GetPotentialMatches(ShapesArray shapes)
    {
        // array of list that will contain all matches we find, sorted by amount of involved objects
        // index 0 = 8 objects, index 5 = 3 objects
        List <List <GameObject> >[] matches = new List <List <GameObject> > [6];

        for (int i = 0; i < matches.Length; i++)
        {
            matches[i] = new List <List <GameObject> >();
        }

        for (int row = 0; row < Constants.Rows; row++)
        {
            for (int column = 0; column < Constants.Columns; column++)
            {
                List <GameObject>[] foundmatches = new List <GameObject> [8];

                foundmatches[0] = CheckHorizontal1(row, column, shapes);
                foundmatches[1] = CheckHorizontal2(row, column, shapes);
                foundmatches[2] = CheckHorizontal3(row, column, shapes);
                foundmatches[3] = CheckHorizontal4(row, column, shapes);
                foundmatches[4] = CheckVertical1(row, column, shapes);
                foundmatches[5] = CheckVertical2(row, column, shapes);
                foundmatches[6] = CheckVertical3(row, column, shapes);
                foundmatches[7] = CheckVertical4(row, column, shapes);

                foreach (var match in foundmatches)
                {
                    match.Add(shapes[row, column]);

                    for (int i = 0; i < matches.Length; i++)
                    {
                        if ((match.Count > 2) && (match.Count == 8 - i))
                        {
                            matches[i].Add(match);
                        }
                    }
                }
            }
        }

        // return random found match
        for (int i = 0; i < matches.Length; i++)
        {
            if (matches[i].Count > 0)
            {
                return(matches[i][UnityEngine.Random.Range(0, matches[i].Count - 1)]);
            }
        }

        return(null);
    }
Beispiel #23
0
        public void TestCopyTo()
        {
            using (var map = new MemoryMapStream())
            {
                var array = new ShapesArray(map, 1);
                array.Set(0, new Coordinate(0, 0.1f), new Coordinate(1, 1.1f));

                using (var stream = new MemoryStream())
                {
                    Assert.AreEqual(16 + 8 + (4 * 4), array.CopyTo(stream));
                }
            }
        }
Beispiel #24
0
        /// <summary>
        /// Creates a new geometric graph.
        /// </summary>
        private GeometricGraph(Graph graph, ArrayBase <float> coordinates,
                               ShapesArray shapes, ArrayBase <short> elevation)
        {
            _graph       = graph;
            _coordinates = coordinates;
            _shapes      = shapes;
            _elevation   = elevation;

            _createElevation = (s) =>
            {
                return(Context.ArrayFactory.CreateMemoryBackedArray <short>(s));
            };
        }
Beispiel #25
0
    public void InitializeCandyAndSpawnPositions()
    {
        if (shapes != null)
        {
            DestroyAllCandy();
        }

        InitializeVariables();

        shapes         = new ShapesArray();
        SpawnPositions = new Vector2[Variables.Columns];

        if (Variables.GameMode == 1)
        {
            blocks = new ShapesArray();
        }

        for (int row = 0; row < Variables.Rows; row++)
        {
            for (int column = 0; column < Variables.Columns; column++)
            {
                GameObject newCandy = GetRandomCandy();

                //check if two previous horizontal are of the same type
                while (column >= 2 && shapes[row, column - 1].GetComponent <Shape>()
                       .IsSameType(newCandy.GetComponent <Shape>()) &&
                       shapes[row, column - 2].GetComponent <Shape>().IsSameType(newCandy.GetComponent <Shape>()))
                {
                    newCandy = GetRandomCandy();
                }

                //check if two previous vertical are of the same type
                while (row >= 2 && shapes[row - 1, column].GetComponent <Shape>()
                       .IsSameType(newCandy.GetComponent <Shape>()) &&
                       shapes[row - 2, column].GetComponent <Shape>().IsSameType(newCandy.GetComponent <Shape>()))
                {
                    newCandy = GetRandomCandy();
                }

                InstantiateAndPlaceNewCandy(row, column, newCandy);
                if (Variables.GameMode == 1)
                {
                    InstantiateAndPlaceNewBlock(row, column);
                }
            }
        }

        SetupSpawnPositions();

        StartCheckForPotentialMatches();
    }
Beispiel #26
0
    public static List <GameObject> CheckVertical3(int row, int column, ShapesArray shapes)
    {
        if (row <= Constants.Rows - 4)
        {
            if (shapes[row, column].GetComponent <Shape>().Type == shapes[row + 1, column].GetComponent <Shape>().Type&&
                shapes[row, column].GetComponent <Shape>().Type == shapes[row + 3, column].GetComponent <Shape>().Type)
            {
                return(new List <GameObject>()
                {
                    shapes[row, column],
                    shapes[row + 1, column],
                    shapes[row + 3, column]
                });
            }
        }

        /* example *\
         * & * * *
         * * * * *
         * & * * *
         * & * * *
         * * * * *
         \* example  */

        if (row >= 2 && row <= Constants.Rows - 2)
        {
            if (shapes[row, column].GetComponent <Shape>().
                IsSameType(shapes[row + 1, column].GetComponent <Shape>()) &&
                shapes[row, column].GetComponent <Shape>().
                IsSameType(shapes[row - 2, column].GetComponent <Shape>()))
            {
                return(new List <GameObject>()
                {
                    shapes[row, column],
                    shapes[row + 1, column],
                    shapes[row - 2, column]
                });
            }
        }

        /* example *\
         * * * * *
         * & * * *
         * & * * *
         * * * * *
         * & * * *
         \* example  */
        return(null);
    }
Beispiel #27
0
        public void TestCreate()
        {
            var array = new ShapesArray(1024);

            Assert.IsNull(array[0]);
            Assert.IsNull(array[1000]);

            using (var map = new MemoryMapStream())
            {
                array = new ShapesArray(map, 1024);

                Assert.IsNull(array[0]);
                Assert.IsNull(array[1000]);
            }
        }
Beispiel #28
0
        public void TestSettingNull()
        {
            using (var map = new MemoryMapStream())
            {
                var array = new ShapesArray(map, 10);
                array.Set(0, new Coordinate(0.0f, 0.1f), new Coordinate(1.0f, 1.1f));

                array[0] = null;

                Assert.IsNull(array[0]);
                Assert.IsNull(array[4]);
                Assert.IsNull(array[7]);
                Assert.IsNull(array[2]);
                Assert.IsNull(array[8]);
            }
        }
Beispiel #29
0
    public static List<GameObject> CheckHorizontal1(int row, int column, ShapesArray shapes)
    {
        if (column <= Constants.Columns - 2)
        {
            if (shapes[row, column].GetComponent<Shape>().
                IsSameType(shapes[row, column + 1].GetComponent<Shape>()))
            {
                if (row >= 1 && column >= 1)
                    if (shapes[row, column].GetComponent<Shape>().
                    IsSameType(shapes[row - 1, column - 1].GetComponent<Shape>()))
                        return new List<GameObject>()
                                {
                                    shapes[row, column],
                                    shapes[row, column + 1],
                                    shapes[row - 1, column - 1]
                                };

                /* example *\
                 * * * * *
                 * * * * *
                 * * * * *
                 * & & * *
                 & * * * *
                \* example  */

                if (row <= Constants.Rows - 2 && column >= 1)
                    if (shapes[row, column].GetComponent<Shape>().
                    IsSameType(shapes[row + 1, column - 1].GetComponent<Shape>()))
                        return new List<GameObject>()
                                {
                                    shapes[row, column],
                                    shapes[row, column + 1],
                                    shapes[row + 1, column - 1]
                                };

                /* example *\
                 * * * * *
                 * * * * *
                 & * * * *
                 * & & * *
                 * * * * *
                \* example  */
            }
        }
        return null;
    }
Beispiel #30
0
    private void InitializeVariables()
    {
        // stop all coroutines. needed for Restart and Premade Level button
        StopAllCoroutines();

        score     = 0;
        nextCandy = 0;
        ShowScore();
        state = GameState.None;
        Graphy.SetActive(false);
        ShuffleText.SetActive(false);

        if (shapes != null)
        {
            DestroyAllCandy();
        }

        shapes         = new ShapesArray();
        spawnPositions = new Vector2[Constants.Columns];
    }
Beispiel #31
0
        /// <summary>
        /// Deserializes a graph from the stream.
        /// </summary>
        public static GeometricGraph Deserialize(System.IO.Stream stream, GeometricGraphProfile profile)
        {
            var version = stream.ReadByte();

            if (version != 1)
            {
                throw new Exception(string.Format("Cannot deserialize geometric graph: Invalid version #: {0}.", version));
            }
            var graph           = Graph.Deserialize(stream, profile == null ? null : profile.GraphProfile);
            var initialPosition = stream.Position;
            var size            = 0L;

            ArrayBase <float> coordinates;
            ShapesArray       shapes;

            if (profile == null)
            { // don't use the stream, the read from it.
                coordinates = Context.ArrayFactory.CreateMemoryBackedArray <float>(graph.VertexCount * 2);
                coordinates.CopyFrom(stream);
                size += graph.VertexCount * 2 * 4;
                long shapeSize;
                shapes = ShapesArray.CreateFrom(stream, true, out shapeSize);
                size  += shapeSize;
            }
            else
            { // use the stream as a map.
                var position = stream.Position;
                var map      = new MemoryMapStream(new CappedStream(stream, position, graph.VertexCount * 4 * 2));
                coordinates = new Array <float>(map.CreateSingle(graph.VertexCount * 2), profile.CoordinatesProfile);
                size       += graph.VertexCount * 2 * 4;
                stream.Seek(position + graph.VertexCount * 4 * 2, System.IO.SeekOrigin.Begin);
                long shapeSize;
                shapes = ShapesArray.CreateFrom(stream, false, out shapeSize);
                size  += shapeSize;
            }

            // make stream is positioned correctly.
            stream.Seek(initialPosition + size, System.IO.SeekOrigin.Begin);

            return(new GeometricGraph(graph, coordinates, shapes));
        }
Beispiel #32
0
    public static List <GameObject> CheckVertical1(int row, int column, ShapesArray shapes)
    {
        if (row <= ConstantsVariable.Rows - 2)
        {
            if (shapes[row, column].GetComponent <Shape>().
                IsSameType(shapes[row + 1, column].GetComponent <Shape>()))
            {
                if (column >= 1 && row >= 1)
                {
                    if (shapes[row, column].GetComponent <Shape>().
                        IsSameType(shapes[row - 1, column - 1].GetComponent <Shape>()))
                    {
                        return new List <GameObject>()
                               {
                                   shapes[row, column],
                                   shapes[row + 1, column],
                                   shapes[row - 1, column - 1]
                               }
                    }
                }
                ;

                if (column <= ConstantsVariable.Columns - 2 && row >= 1)
                {
                    if (shapes[row, column].GetComponent <Shape>().
                        IsSameType(shapes[row - 1, column + 1].GetComponent <Shape>()))
                    {
                        return new List <GameObject>()
                               {
                                   shapes[row, column],
                                   shapes[row + 1, column],
                                   shapes[row - 1, column + 1]
                               }
                    }
                }
                ;
            }
        }
        return(null);
    }
        internal static Graph ReadFrom(Stream stream)
        {
            // read & verify header.
            var header  = stream.ReadWithSizeString();
            var version = stream.ReadByte();

            if (header != nameof(Graph))
            {
                throw new InvalidDataException($"Cannot read {nameof(Graph)}: Header invalid.");
            }
            if (version != 1)
            {
                throw new InvalidDataException($"Cannot read {nameof(Graph)}: Version # invalid.");
            }

            // read zoom and edge data size.
            var zoom         = stream.ReadByte();
            var edgeDataSize = stream.ReadByte();

            // read tile index.
            var tileSizeIndex = stream.ReadByte();
            var tiles         = SparseMemoryArray <byte> .CopyFromWithHeader(stream);

            // read vertices.
            var coordinateSizeInBytes = stream.ReadByte();
            var vertexPointer         = stream.ReadInt64();
            var vertices = MemoryArray <byte> .CopyFromWithSize(stream);

            var edgePointers = MemoryArray <uint> .CopyFromWithSize(stream);

            // read edges.
            var edgePointer = stream.ReadInt64();
            var edges       = MemoryArray <byte> .CopyFromWithSize(stream);

            // read shapes.
            var shapes = ShapesArray.CreateFrom(stream, true, false);

            return(new Graph(zoom, edgeDataSize, tileSizeIndex, tiles, coordinateSizeInBytes, vertices, (uint)vertexPointer, edgePointers,
                             (uint)edgePointer, edges, shapes));
        }
    public void InitializeCandyAndSpawnPositions()
    {
        InitializeVariables();

        if (shapes != null)
            DestroyAllCandy();

        shapes = new ShapesArray();
        SpawnPositions = new Vector2[Constants.Columns];

        for (int row = 0; row < Constants.Rows; row++)
        {
            for (int column = 0; column < Constants.Columns; column++)
            {

                GameObject newCandy = GetRandomCandy();

                //check if two previous horizontal are of the same type
                while (column >= 2 && shapes[row, column - 1].GetComponent<Shape>()
                    .IsSameType(newCandy.GetComponent<Shape>())
                    && shapes[row, column - 2].GetComponent<Shape>().IsSameType(newCandy.GetComponent<Shape>()))
                {
                    newCandy = GetRandomCandy();
                }

                //check if two previous vertical are of the same type
                while (row >= 2 && shapes[row - 1, column].GetComponent<Shape>()
                    .IsSameType(newCandy.GetComponent<Shape>())
                    && shapes[row - 2, column].GetComponent<Shape>().IsSameType(newCandy.GetComponent<Shape>()))
                {
                    newCandy = GetRandomCandy();
                }

                InstantiateAndPlaceNewCandy(row, column, newCandy);

            }
        }

        SetupSpawnPositions();
    }
Beispiel #35
0
    /// <summary>
    /// Will check for potential matches vertically and horizontally
    /// </summary>
    /// <returns></returns>
    public static IEnumerable<GameObject> GetPotentialMatches(ShapesArray shapes)
    {
        //list that will contain all the matches we find
        List<List<GameObject>> matches = new List<List<GameObject>>();

        for (int row = 0; row < Constants.Rows; row++)
        {
            for (int column = 0; column < Constants.Columns; column++)
            {

                var matches1 = CheckHorizontal1(row, column, shapes);
                var matches2 = CheckHorizontal2(row, column, shapes);
                var matches3 = CheckHorizontal3(row, column, shapes);
                var matches4 = CheckVertical1(row, column, shapes);
                var matches5 = CheckVertical2(row, column, shapes);
                var matches6 = CheckVertical3(row, column, shapes);

                if (matches1 != null) matches.Add(matches1);
                if (matches2 != null) matches.Add(matches2);
                if (matches3 != null) matches.Add(matches3);
                if (matches4 != null) matches.Add(matches4);
                if (matches5 != null) matches.Add(matches5);
                if (matches6 != null) matches.Add(matches6);

                //if we have >= 3 matches, return a random one
                if (matches.Count >= 3)
                    return matches[UnityEngine.Random.Range(0, matches.Count - 1)];

                //if we are in the middle of the calculations/loops
                //and we have less than 3 matches, return a random one
                if (row >= Constants.Rows / 2 && matches.Count > 0 && matches.Count <= 2)
                    return matches[UnityEngine.Random.Range(0, matches.Count - 1)];
            }
        }
        return null;
    }
Beispiel #36
0
    // Initializes the score variables
    // Destroys all elements in the array
    // Reinitializes the array and the spawn positions for the new glyphs
    // Loops through all the array elements and creates new glyphs while not creating matches
    public void InitializeGlyphAndSpawnPositions()
    {
        InitializeVariables();

        soundManager.PlayStart();

        if (!empty)
        {
            DestroyAllGlyphs();
        }
        shapes = new ShapesArray();
        empty = false;
        SpawnPositions = new Vector2[Constants.Columns];

        for (int row = 0; row < Constants.Rows; row++)
        {
            for (int column = 0; column < Constants.Columns; column++)
            {
                GameObject newGlyph = GetRandomGlyph();

                // Check if two previous horizontal glyphs are of the same type
                while (column >= 2 && shapes[row, column - 1].GetComponent<Shape>()
                    .IsSameType(newGlyph.GetComponent<Shape>())
                    && shapes[row, column - 2].GetComponent<Shape>().IsSameType(newGlyph.GetComponent<Shape>()))
                {
                    newGlyph = GetRandomGlyph();
                }

                // Check if two previous vertical glyphs are of the same type
                while (row >= 2 && shapes[row - 1, column].GetComponent<Shape>()
                    .IsSameType(newGlyph.GetComponent<Shape>())
                    && shapes[row - 2, column].GetComponent<Shape>().IsSameType(newGlyph.GetComponent<Shape>()))
                {
                    newGlyph = GetRandomGlyph();
                }

                InstantiateAndPlaceNewGlyph(row, column, newGlyph);
            }
        }

        SetupSpawnPositions();
    }
Beispiel #37
0
    public static List<GameObject> CheckVertical3(int row, int column, ShapesArray shapes)
    {
        if (row <= Constants.Rows - 4)
        {
            if (shapes[row, column].GetComponent<Shape>().
               IsSameType(shapes[row + 1, column].GetComponent<Shape>()) &&
               shapes[row, column].GetComponent<Shape>().
               IsSameType(shapes[row + 3, column].GetComponent<Shape>()))
            {
                return new List<GameObject>()
                                {
                                    shapes[row, column],
                                    shapes[row + 1, column],
                                    shapes[row + 3, column]
                                };
            }
        }

        /* example *\
          * & * * *
          * * * * *
          * & * * *
          * & * * *
          * * * * *
        \* example  */

        if (row >= 2 && row <= Constants.Rows - 2)
        {
            if (shapes[row, column].GetComponent<Shape>().
               IsSameType(shapes[row + 1, column].GetComponent<Shape>()) &&
               shapes[row, column].GetComponent<Shape>().
               IsSameType(shapes[row - 2, column].GetComponent<Shape>()))
            {
                return new List<GameObject>()
                                {
                                    shapes[row, column],
                                    shapes[row + 1, column],
                                    shapes[row - 2, column]
                                };
            }
        }

        /* example *\
          * * * * *
          * & * * *
          * & * * *
          * * * * *
          * & * * *
        \* example  */
        return null;
    }
Beispiel #38
0
    public static List<GameObject> CheckHorizontal3(int row, int column, ShapesArray shapes)
    {
        if (column <= Constants.Columns - 4)
        {
            if (shapes[row, column].GetComponent<Shape>().
               IsSameType(shapes[row, column + 1].GetComponent<Shape>()) &&
               shapes[row, column].GetComponent<Shape>().
               IsSameType(shapes[row, column + 3].GetComponent<Shape>()))
            {
                return new List<GameObject>()
                                {
                                    shapes[row, column],
                                    shapes[row, column + 1],
                                    shapes[row, column + 3]
                                };
            }

            /* example *\
              * * * * *
              * * * * *
              * * * * *
              * & & * &
              * * * * *
            \* example  */
        }
        if (column >= 2 && column <= Constants.Columns - 2)
        {
            if (shapes[row, column].GetComponent<Shape>().
               IsSameType(shapes[row, column + 1].GetComponent<Shape>()) &&
               shapes[row, column].GetComponent<Shape>().
               IsSameType(shapes[row, column - 2].GetComponent<Shape>()))
            {
                return new List<GameObject>()
                                {
                                    shapes[row, column],
                                    shapes[row, column + 1],
                                    shapes[row, column -2]
                                };
            }

            /* example *\
              * * * * *
              * * * * *
              * * * * *
              * & * & &
              * * * * *
            \* example  */
        }
        return null;
    }
    public static void ShowArray(ShapesArray shapes)
    {

        Debug.Log(GetArrayContents(shapes));
    }