Android Open Source - dice-probabilities Current Dice Pile






From Project

Back to project page dice-probabilities.

License

The source code is released under:

MIT License

If you think the Android project dice-probabilities 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 org.kleemann.diceprobabilities;
/*from  w w w  .j av  a2s  .  c o m*/
import android.view.View;
import android.widget.Button;

/*
 * <p>Provides the behavior for a button that represents the current 
 * number of dice of a particular type (number of sides) that is 
 * to be rolled.  If number of sides==1 then the die is considerred a 
 * constant and rendered differently.
 * 
 * <p>When the Pile's count has changed, it calls the passed listener.
 */
public class CurrentDicePile implements View.OnClickListener {

  private int sides;
  protected int count;
  final protected Button button;
  final protected View.OnClickListener changed;

  protected CurrentDicePile(int sides, Button button,
      View.OnClickListener changed) {
    this.sides = sides;
    this.count = 0;
    this.button = button;
    button.setOnClickListener(this);
    this.changed = changed;
    updateButton();
  }

  public static CurrentDicePile create(int sides, Button button,
      View.OnClickListener changed) {
    if (sides == 1) {
      return new ConstantCurrentDicePile(button, changed);
    } else {
      return new CurrentDicePile(sides, button, changed);
    }
  }
  
  protected void updateButton() {
    button.setText(count + "d" + sides);
    button.setVisibility(count == 0 ? View.GONE
        : View.VISIBLE);
  }

  public int getSides() {
    return sides;
  }

  public int getCount() {
    return count;
  }

  public void setCount(int count) {
    if (count >= 0) {
      this.count = count;
      updateButton();
      changed.onClick(button);
    }
  }

  public void increment() {
    setCount(count + 1);
  }

  public void decrement() {
    setCount(count - 1);
  }

  public void clear() {
    setCount(0);
  }

  @Override
  public void onClick(View v) {
    decrement();
  }
}




Java Source Code List

com.asolutions.widget.RowLayout.java
org.kleemann.diceprobabilities.Check.java
org.kleemann.diceprobabilities.ConstantCurrentDicePile.java
org.kleemann.diceprobabilities.CurrentDicePile.java
org.kleemann.diceprobabilities.DiceSet.java
org.kleemann.diceprobabilities.MainActivity.java
org.kleemann.diceprobabilities.PoolDicePile.java
org.kleemann.diceprobabilities.TargetPool.java
org.kleemann.diceprobabilities.Target.java
org.kleemann.diceprobabilities.distribution.AbstractDistribution.java
org.kleemann.diceprobabilities.distribution.CachedCumulativeDistribution.java
org.kleemann.diceprobabilities.distribution.ConstantDistribution.java
org.kleemann.diceprobabilities.distribution.CritDistribution.java
org.kleemann.diceprobabilities.distribution.DeathZoneDieDistribution.java
org.kleemann.diceprobabilities.distribution.DieDistribution.java
org.kleemann.diceprobabilities.distribution.Distribution.java
org.kleemann.diceprobabilities.distribution.DogslicerDistribution.java
org.kleemann.diceprobabilities.distribution.ScaleCumulativeDistribution.java
org.kleemann.diceprobabilities.distribution.SumDistribution.java
org.kleemann.diceprobabilities.graph.GraphView.java
org.kleemann.diceprobabilities.graph.Interpolate.java
org.kleemann.diceprobabilities.graph.Point.java
org.kleemann.diceprobabilities.graph.Vector.java
org.kleemann.diceprobabilities.special.AbstractSpecial.java
org.kleemann.diceprobabilities.special.CritSpecial.java
org.kleemann.diceprobabilities.special.DeathZoneSpecial.java
org.kleemann.diceprobabilities.special.DogslicerSpecial.java
org.kleemann.diceprobabilities.special.FailureSpecial.java
org.kleemann.diceprobabilities.special.ForcedRerollSpecial.java
org.kleemann.diceprobabilities.special.ModifyEachDieSpecial.java
org.kleemann.diceprobabilities.special.NormalSpecial.java
org.kleemann.diceprobabilities.special.SecondChanceSpecial.java
org.kleemann.diceprobabilities.special.SpecialSpinner.java
org.kleemann.diceprobabilities.special.Special.java