1. You want that $100.00 in your pocket or an Amazon Fire TV don't you? Well here's the deal. With our new updated look we are in desperate need of an updated logo. The 'old' one has certainly served us well, but it's time. Find all the details here: bit.ly/1q0k6Wa
  2. DroidForums.net is currently undergoing a major software upgrade. If you are experiencing any problems logging in please: Contact Us

Dice Roll App

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

  1. Aizen
    Offline

    Aizen New Member

    Joined:
    Dec 10, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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,

    Code:
    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 );
                }
    
            };
      
        
        @Override
        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 source code

,
android dice rolling apps source code
,
android roll dice source code
,
android tutorial for dice app
,
code 2 create a dice game in android
,
code for a game of dice in android
,
dice code android
,
dice game in android code
,
dice roller android app -google -play
,
sample code dice rolling android java
,
simple dice roller android app code
,
source code game dice android