コード例 #1
0
    /**
     * value is a [] that first array in enum 0
     * second array is enum 1
     * thrid array is enum 2
     * */
    private BerrySize RandomSize(params int[] values)
    {
        int MaxValue = 0;

        foreach (int value in values)
        {
            MaxValue += value;
        }
        int       randomed = Random.Range(0, MaxValue - 1);
        BerrySize result   = BerrySize.Small;
        int       index    = 0;

        foreach (BerrySize s in System.Enum.GetValues(typeof(BerrySize)))
        {
            if (randomed <= 0)
            {
                continue;
            }
            randomed -= values[index];
            if (randomed <= 0)
            {
                result = s;
            }
        }

        return(result);
    }
コード例 #2
0
    public override void Restart()
    {
        base.Restart();
        // random the size
        BerrySize size = RandomSize(SmallBerry, MediumBerry, LargeBerry);

        this.size = size;
        // random the consume
        int addHP = RandomConsume(size);

        this.AddHp = addHP;
    }
コード例 #3
0
    private int RandomConsume(BerrySize size)
    {
        int randomed = 0;

        switch (size)
        {
        case BerrySize.Small: randomed = Random.Range(MinSmallBerry, MaxSmallBerry); break;

        case BerrySize.Medium: randomed = Random.Range(MinMediumBerry, MaxMediumBerry); break;

        case BerrySize.Large: randomed = Random.Range(MinLargeBerry, MaxLargeBerry); break;
        }
        return(randomed);
    }