Android Open Source - rpg-droid Die Roller






From Project

Back to project page rpg-droid.

License

The source code is released under:

Apache License

If you think the Android project rpg-droid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.thing.rpg_droid.Utils;
// w ww .  j  av a 2  s.c  o  m
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 * Created by jon on 12/08/14.
 */
public class DieRoller
{
    private static Random mRandom = new Random();

    public static int Roll(DieType lType)
    {
        return mRandom.nextInt(lType.getMax() - lType.getMin() + 1) + lType.getMin();
    }

    public static List<Integer> Roll(DieType lType, int lCount)
    {
        return Roll(lType, lCount, 0);
    }

    public static List<Integer> Roll(DieType lType, int lCount, int lDiscardLowest)
    {
        if (lDiscardLowest >= lCount)
            throw new IllegalArgumentException("Die roll must return at least 1 result");

        ArrayList<Integer> lResult = new ArrayList<Integer>();

        for (int i = 0; i < lCount; i++)
            lResult.add(Roll(lType));

        Collections.sort(lResult);

        for (int i = 0; i < lDiscardLowest; i++)
            lResult.remove(0);

        return lResult;
    }

    public static int RollAndTotal(DieType lType, int lCount)
    {
        return RollAndTotal(lType, lCount, 0);
    }

    public static int RollAndTotal(DieType lType, int lCount, int lDiscardLowest)
    {
        List<Integer> lRolls = Roll(lType, lCount, lDiscardLowest);

        int lResult = 0;

        for(Integer lRoll : lRolls)
            lResult += lRoll;

        return lResult;
    }
}




Java Source Code List

com.thing.rpg_droid.Utils.DieRoller.java
com.thing.rpg_droid.Utils.DieType.java
com.thing.rpg_droid.app.Activity_CharacterList.java
com.thing.rpg_droid.app.Activity_Charsheet.java
com.thing.rpg_droid.app.CharSheet_PageInfo.java
com.thing.rpg_droid.app.Fragment_CharacterList.java
com.thing.rpg_droid.app.ICharacter.java
com.thing.rpg_droid.app.PagerAdapter_Charsheet.java
com.thing.rpg_droid.app.ViewBinder.java
com.thing.rpg_droid.app.View_CharacterSheet_Field.java
com.thing.rpg_droid.app.dummy.DummyContent.java
com.thing.rpg_droid.pathfinder.Ability.java
com.thing.rpg_droid.pathfinder.Adapters.java
com.thing.rpg_droid.pathfinder.Appearance.java
com.thing.rpg_droid.pathfinder.ArmorClass.java
com.thing.rpg_droid.pathfinder.BodySlot.java
com.thing.rpg_droid.pathfinder.Character.java
com.thing.rpg_droid.pathfinder.Fragment_Basic.java
com.thing.rpg_droid.pathfinder.Fragment_Gear.java
com.thing.rpg_droid.pathfinder.Fragment_Skills.java
com.thing.rpg_droid.pathfinder.Fragment_Spells_Abilities.java
com.thing.rpg_droid.pathfinder.Fragment_Status.java
com.thing.rpg_droid.pathfinder.IInventoryLocation.java
com.thing.rpg_droid.pathfinder.Initiative.java
com.thing.rpg_droid.pathfinder.SavingThrow.java
com.thing.rpg_droid.pathfinder.SizeModifier.java
com.thing.rpg_droid.pathfinder.Skill.java
com.thing.rpg_droid.pathfinder.Spell.java
com.thing.rpg_droid.pathfinder.Status.java