Пример #1
0
    /// <summary>
    /// Spawns new candy in columns that have missing ones
    /// </summary>
    /// <param name="columnsWithMissingCandy"></param>
    /// <returns>Info about new candies created</returns>
    private AlteredCandyInfo CreateNewCandyInSpecificColumns(IEnumerable <int> columnsWithMissingCandy)
    {
        AlteredCandyInfo newCandyInfo = new AlteredCandyInfo();

        //find how many null values the column has
        foreach (int column in columnsWithMissingCandy)
        {
            var emptyItems = shapes.GetEmptyItemsOnColumn(column);
            foreach (var item in emptyItems)
            {
                var        go       = GetRandomCandy();
                GameObject newCandy = Instantiate(go, SpawnPositions[column], Quaternion.identity)
                                      as GameObject;

                newCandy.GetComponent <Shape>().Assign(go.GetComponent <Shape>().Type, item.Row, item.Column);

                if (Constants.Rows - item.Row > newCandyInfo.MaxDistance)
                {
                    newCandyInfo.MaxDistance = Constants.Rows - item.Row;
                }

                shapes[item.Row, item.Column] = newCandy;
                newCandyInfo.AddCandy(newCandy);
            }
        }
        return(newCandyInfo);
    }
Пример #2
0
    private AlteredCandyInfo CreateNewCandyInSpecificColumns(IEnumerable <int> columnsWithMissingCandy)
    {
        AlteredCandyInfo newCandyInfo = new AlteredCandyInfo();

        // find how many null values the column has
        foreach (int column in columnsWithMissingCandy)
        {
            var emptyItems = shapes.GetEmptyItemsOnColumn(column);
            int offset     = 0;
            foreach (var item in emptyItems)
            {
                var        go       = GetRandomCandy();
                GameObject newCandy = Instantiate(go,
                                                  spawnPositions[column] + new Vector2(0.0f, offset * CandySize.y),
                                                  Quaternion.identity,
                                                  shapesContainer) as GameObject;

                newCandy.GetComponent <Shape>().Assign(go.GetComponent <Shape>().Type, item.Row, item.Column);

                shapes[item.Row, item.Column] = newCandy;
                newCandyInfo.AddCandy(newCandy);

                offset++;
            }
        }

        return(newCandyInfo);
    }
Пример #3
0
    /// <summary>
    /// Spawns new food in columns that have missing ones
    /// </summary>
    /// <param name="columnsWithMissingFood"></param>
    /// <returns>Info about new foods created</returns>
    private AlteredFoodInfo CreateNewFoodInSpecificColumns(IEnumerable <int> columnsWithMissingFood)
    {
        AlteredFoodInfo newFoodInfo = new AlteredFoodInfo();

        //find how many null values the column has
        foreach (int column in columnsWithMissingFood)
        {
            var emptyItems = shapes.GetEmptyItemsOnColumn(column);
            foreach (var item in emptyItems)
            {
                var        go      = GetRandomFood();
                GameObject newFood = Instantiate(go, SpawnPositions[column], Quaternion.identity)
                                     as GameObject;

                newFood.GetComponent <Shape>().Assign(go.GetComponent <Shape>().Type, item.Row, item.Column);
                newFood.transform.localScale = new Vector3(FoodSize.x, FoodSize.y, 1.0f);

                if (Constants.Rows - item.Row > newFoodInfo.MaxDistance)
                {
                    newFoodInfo.MaxDistance = Constants.Rows - item.Row;
                }

                shapes[item.Row, item.Column] = newFood;
                newFoodInfo.AddFood(newFood);
            }
        }
        return(newFoodInfo);
    }