Exemplo n.º 1
0
    public static List<GameObject> CheckHorizontal1(int row, int column, ActionsArray actions)
    {
        if (column <= Constants.Columns - 2)
        {
            if (actions[row, column].GetComponent<Action>().
                CheckIfMatchingAction(actions[row, column + 1].GetComponent<Action>()))
            {
                if (row >= 1 && column >= 1)
                    if (actions[row, column].GetComponent<Action>().
                    CheckIfMatchingAction(actions[row - 1, column - 1].GetComponent<Action>()))
                        return new List<GameObject>()
                                {
                                    actions[row, column],
                                    actions[row, column + 1],
                                    actions[row - 1, column - 1]
                                };

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

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

                /* example *\
                 * * * * *
                 * * * * *
                 & * * * *
                 * & & * *
                 * * * * *
                \* example  */
            }
        }
        return null;
    }
Exemplo n.º 2
0
    public void InitializeActionsAndSpawnPositions()
    {
        InitializeVariables();

        if (Actions != null)
        {
            DestroyAllActions();
        }

        Actions = new ActionsArray();
        _spawnPositions = new Vector2[Constants.Columns];

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

                while (column >= 2 &&
                       Actions[row, column - 1].GetComponent<Action>()
                           .CheckIfMatchingAction(newAction.GetComponent<Action>()) &&
                       Actions[row, column - 2].GetComponent<Action>()
                           .CheckIfMatchingAction(newAction.GetComponent<Action>()))
                {
                    newAction = GetRandomAction();
                }

                while (row >= 2 &&
                       Actions[row - 1, column].GetComponent<Action>()
                           .CheckIfMatchingAction(newAction.GetComponent<Action>()) &&
                       Actions[row - 2, column].GetComponent<Action>()
                           .CheckIfMatchingAction(newAction.GetComponent<Action>()))
                {
                    newAction = GetRandomAction();
                }

                InstantiateAndPlaceNewAction(row, column, newAction);
            }
        }

        SetupSpawnPositions();
    }
Exemplo n.º 3
0
    public static IEnumerable<GameObject> GetPotentialMatches(ActionsArray actions)
    {
        // List the contains potential matches that we can use for hints.
        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, actions);
                var matches2 = CheckHorizontal2(row, column, actions);
                var matches3 = CheckHorizontal3(row, column, actions);
                var matches4 = CheckVertical1(row, column, actions);
                var matches5 = CheckVertical2(row, column, actions);
                var matches6 = CheckVertical3(row, column, actions);

                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 (matches.Count >= 3)
                {
                    return matches[Random.Range(0, matches.Count - 1)];
                }

                if (row >= Constants.Rows/2 && matches.Count > 0 && matches.Count <= 2)
                {
                    return matches[Random.Range(0, matches.Count - 1)];
                }
            }
        }
        return null;
    }
Exemplo n.º 4
0
    public static List<GameObject> CheckVertical3(int row, int column, ActionsArray shapes)
    {
        if (row <= Constants.Rows - 4)
        {
            if (shapes[row, column].GetComponent<Action>().
               CheckIfMatchingAction(shapes[row + 1, column].GetComponent<Action>()) &&
               shapes[row, column].GetComponent<Action>().
               CheckIfMatchingAction(shapes[row + 3, column].GetComponent<Action>()))
            {
                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<Action>().
               CheckIfMatchingAction(shapes[row + 1, column].GetComponent<Action>()) &&
               shapes[row, column].GetComponent<Action>().
               CheckIfMatchingAction(shapes[row - 2, column].GetComponent<Action>()))
            {
                return new List<GameObject>()
                                {
                                    shapes[row, column],
                                    shapes[row + 1, column],
                                    shapes[row - 2, column]
                                };
            }
        }

        /* example *\
          * * * * *
          * & * * *
          * & * * *
          * * * * *
          * & * * *
        \* example  */
        return null;
    }
Exemplo n.º 5
0
    public static List<GameObject> CheckVertical2(int row, int column, ActionsArray shapes)
    {
        if (row <= Constants.Rows - 3)
        {
            if (shapes[row, column].GetComponent<Action>().
                CheckIfMatchingAction(shapes[row + 1, column].GetComponent<Action>()))
            {
                if (column >= 1)
                    if (shapes[row, column].GetComponent<Action>().
                    CheckIfMatchingAction(shapes[row + 2, column - 1].GetComponent<Action>()))
                        return new List<GameObject>()
                                {
                                    shapes[row, column],
                                    shapes[row + 1, column],
                                    shapes[row + 2, column -1]
                                };

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

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

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

            }
        }
        return null;
    }
Exemplo n.º 6
0
    public static List<GameObject> CheckHorizontal3(int row, int column, ActionsArray shapes)
    {
        if (column <= Constants.Columns - 4)
        {
            if (shapes[row, column].GetComponent<Action>().
               CheckIfMatchingAction(shapes[row, column + 1].GetComponent<Action>()) &&
               shapes[row, column].GetComponent<Action>().
               CheckIfMatchingAction(shapes[row, column + 3].GetComponent<Action>()))
            {
                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<Action>().
               CheckIfMatchingAction(shapes[row, column + 1].GetComponent<Action>()) &&
               shapes[row, column].GetComponent<Action>().
               CheckIfMatchingAction(shapes[row, column - 2].GetComponent<Action>()))
            {
                return new List<GameObject>()
                                {
                                    shapes[row, column],
                                    shapes[row, column + 1],
                                    shapes[row, column -2]
                                };
            }

            /* example *\
              * * * * *
              * * * * *
              * * * * *
              * & * & &
              * * * * *
            \* example  */
        }
        return null;
    }