Dice Roll App

This is a discussion on Dice Roll App within the Droid Development forums, part of the Droid Hacking category; 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 ...

+ Reply to Thread
Results 1 to 1 of 1

Thread: Dice Roll App

  1. Droid Newbie
    Aizen's Avatar
    Member #
    147007
    Join Date
    Dec 2010
    Posts
    1
    Phone
    Enter Current Phone Model Here
    #1

    Dice Roll App

    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.

    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 by Aizen; 12-10-2010 at 10:23 PM.
  2. Sponsor
    DF Advertising
    Join Date
    Nov 2008
    Location
    DroidForums.net
     
     
     
     

Sponsors

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Similar Threads

  1. Roll back from 2.2 to 2.1?
    By sniper6 in forum Rescue Squad Help
    Replies: 6
    Last Post: 08-24-2010, 08:53 PM
  2. Have you grown up in a rock n roll rut?
    By Johnly in forum Off Topic Forum
    Replies: 0
    Last Post: 08-17-2010, 03:01 AM
  3. Notification bar won't roll back up
    By luckmylife in forum Tech Issues, Bug Reports & Suggestions
    Replies: 1
    Last Post: 01-10-2010, 09:11 PM
  4. Roll Tide Roll
    By CatsTide in forum Off Topic Forum
    Replies: 5
    Last Post: 01-09-2010, 10:35 AM
  5. Roll back to 2.0 (not .0.1)?
    By jkayner in forum Droid General Discussions
    Replies: 5
    Last Post: 12-21-2009, 09:40 AM

Search tags for this page

android dice example

,

android dice game source

,

android dice roller example

,

android dice roller source

,

android dice roller source code

,

android dice sample code

,

android dice source code

,

android dice tutorial

,
android game source
,

dice roller app java

,
diceroll in android tutorial
,

droid dice app

,
java android dice rolling app how to program
,

java dice roller source code

,

make dice roller for android

Click on a term to search our site for related topics.