Dice Roll App

Discussion in 'Android Hacks and Help' started by Aizen, Dec 10, 2010.

  1. Aizen

    Aizen New Member

    Dec 10, 2010
    Likes Received:
    Trophy Points:
    Hi, I'm trying to make a simple dice roller app.
    This is what I want to be able to do.

    The game allows player throwing an arbitrary number of dice (1-6). Each die can show the number from 1 to 6 if thrown. On each throw you are to calculate the sum of all dice thrown
    If your single iteration yielded 7, 11, 21 the player won the game
    If your single iteration yielded 13 or 26 the player lost the game
    The player can go for maximum of 6 iterations. They can change the number of dice in each iteration.
    You must keep the running sum of all iterations. If the sum is exactly 120 the player won the game.

    Can anyone tell me how this can be done? I've tried searching for dice roll apps to get some understanding of how it can be done, but didn't find any source code. I'm new to programming, so not exactly sure how this can be done. Any help will be greatly appreciated, thanks. :blackdroid:

    This is what I have sofar,

    package diceroller.sample;
    import java.util.Random;
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.TextView;
    public class dicroller extends Activity
        private TextView firstRollResult;
        private TextView secondRollResult;
        private TextView thirdRollResult;
        private TextView finalResult;
        private Button rollerButton;
        private Random rand = new Random();
        private String[] fRoll = new String[] { "1", "2", "3", "4", "5", "6" };
        private String[] sRoll = new String[] { "1", "2", "3", "4", "5", "6" };
        private String[] tRoll = new String[] { "1", "2", "3", "4", "5", "6" };
        private int total = 0;
        private int numOfRolls = 6;
        int firstResult;
        int secondResult;
        int thirdResult;
        private OnClickListener buttonClickListener = new OnClickListener() {
            public void onClick( View v )
                int num = rand.nextInt( fRoll.length );
                String fresult = fRoll[num];
                firstResult = Integer.parseInt(fresult);
                firstRollResult.setText( fresult );
                int numTwo = rand.nextInt( sRoll.length );
                String sresult = sRoll[numTwo];
                secondResult = Integer.parseInt(sresult);
                secondRollResult.setText( sresult );
                int numThree = rand.nextInt( sRoll.length );
                String tresult = tRoll[numThree];
                thirdResult = Integer.parseInt(tresult);
                thirdRollResult.setText( tresult );
                //total = firstResult + secondResult + thirdResult;
                //finalResult.setText( total );
        public void onCreate( Bundle savedInstanceState )
            super.onCreate( savedInstanceState );
            setContentView( R.layout.main );
            firstRollResult = (TextView)findViewById( R.id.firstRollResult );
            secondRollResult = (TextView)findViewById( R.id.secondRollResult );
            thirdRollResult = (TextView)findViewById( R.id.thirdRollResult);
            finalResult = (TextView)findViewById( R.id.total);
            rollerButton = (Button)findViewById( R.id.rollerButton );
            rollerButton.setOnClickListener( buttonClickListener );
    When I add the total code to calculate the total of all the dice rolls the application just crashes.
    Last edited: Dec 10, 2010
Search tags for this page
android code dice game
android dice example#gsc.tab
android dice game sample code
android dice roller example

android dice roller source code

android roll dice source code
android tutorial for dice app

java dice roller samples android

java die roller samples app android
simple dice roller android app code