Android Open Source - aSimpleDiceRoller A Simple Dice Roller Activity






From Project

Back to project page aSimpleDiceRoller.

License

The source code is released under:

GNU General Public License

If you think the Android project aSimpleDiceRoller 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

/*
 *  aSimpleDiceRoller - Simple dice roller application for Android.
 *  Copyright  2012 Elad Alfassa <elad@fedoraproject.org>
 * /* w  w  w .j  a va  2 s .  c  o  m*/
 *  This file is part of aSimpleDiceRoller.
 *
 *   aSimpleDiceRoller is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   aSimpleDiceRoller is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with aSimpleDiceRoller.  If not, see <http://www.gnu.org/licenses/>.

 */

package com.elad.diceroller;

import java.util.Random;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.content.Intent;
import com.elad.diceroller.DiceRollerShared;

public class ASimpleDiceRollerActivity extends Activity {
  public static String selected_die="d6";
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView label = (TextView) findViewById(R.id.selected);
        label.setText(selected_die);
  }
  public void nerdmode(View view) {
      Intent intent = new Intent(this, NerdmodeActivity.class);
        startActivity(intent);

  }
  public void diceList(View view) {
    Intent intent = new Intent(this, DiceListActivity.class);
    startActivity(intent);
  }
    public void roll(View view) {
      rollDie(selected_die);
    }
  private void rollDie(String Die) {    
    int max=0;
    //We can't do switch case on strings. That's so stupid.
    if (Die=="d4")
      max=4;
    else if (Die=="d6")
      max=6;
    else if (Die=="d8")
        max=8;
    else if (Die=="d10")
      max=10;
    else if (Die=="d12")
      max=12;
    else if (Die=="d20")
      max=20;
    else if (Die=="d100")
      max=100;
    String str;
    int randomNum=DiceRollerShared.rollDice(max);
    str="d"+max+": "+String.valueOf(randomNum);

    TextView label = (TextView) findViewById(R.id.textView1);
    label.setText(str);
    }
}




Java Source Code List

com.elad.diceroller.ASimpleDiceRollerActivity.java
com.elad.diceroller.DiceListActivity.java
com.elad.diceroller.DiceRollerShared.java
com.elad.diceroller.NerdmodeActivity.java
com.elad.diceroller.StringUtils.java