Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Dice Roller

Code
public class DiceRoller2
{
   public static void main(String[] args)
   {
   int num1;
   int num2;
   int total;
   num1 = (int)(Math.random() * (6+1)-1) + 1;
   num2 = (int)(Math.random() * (6+1)-1) + 1;
  
   total =  num1 + num2;
   System.out.println("The two six sided dice rolled equal: " + total);
   //This gets the random number for the dice everything under this point draws the die according to the number rolled.
   if(total == 2)
   {
   StdDraw.square(.25,.5,.15);
   StdDraw.square(.75,.5,.15);
   StdDraw.circle(.25,.5,.015);
   StdDraw.circle(.75,.5,.015);
   }
   else if(total == 3)
   {
   StdDraw.square(.25,.5,.15);
   StdDraw.square(.75,.5,.15);
   StdDraw.circle(.30,.5,.015);
   StdDraw.circle(.75,.5,.015);
   }
   else if(total == 4)
   {
   StdDraw.square(.25,.5,.15);
   StdDraw.square(.75,.5,.15);
   StdDraw.circle(.20,.5,.015);
   StdDraw.circle(.30,.5,.015);
   StdDraw.circle(.70,.5,.015);
   StdDraw.circle(.80,.5,.015);
   }
   else if(total == 5)
   {
   StdDraw.square(.25,.5,.15);
   StdDraw.square(.75,.5,.15);
   StdDraw.circle(.25,.6,.015);
   StdDraw.circle(.25,.4,.015);
   StdDraw.circle(.25,.5,.015);
   StdDraw.circle(.75,.5,.015);
  
   }
   else if(total == 6)
   {
   StdDraw.square(.25,.5,.15);
   StdDraw.square(.75,.5,.15);
   StdDraw.circle(.75,.6,.015);
   StdDraw.circle(.75,.4,.015);
   StdDraw.circle(.75,.5,.015);
   StdDraw.circle(.25,.6,.015);
   StdDraw.circle(.25,.4,.015);
   StdDraw.circle(.25,.5,.015);
   }
   else if(total == 7)
   {
   StdDraw.square(.25,.5,.15);
   StdDraw.square(.75,.5,.15);
   StdDraw.circle(.20,.55,.015);
   StdDraw.circle(.30,.55,.015);
   StdDraw.circle(.20,.45,.015);
   StdDraw.circle(.30,.45,.015);
  StdDraw.circle(.75,.6,.015);
  StdDraw.circle(.75,.4,.015);
  StdDraw.circle(.75,.5,.015);
  
   }
   else if(total == 8)
   {
   StdDraw.square(.25,.5,.15);
   StdDraw.square(.75,.5,.15);
   StdDraw.circle(.20,.55,.015);
   StdDraw.circle(.30,.55,.015);
   StdDraw.circle(.20,.45,.015);
   StdDraw.circle(.30,.45,.015);
   StdDraw.circle(.80,.55,.015);
   StdDraw.circle(.70,.55,.015);
   StdDraw.circle(.80,.45,.015);
   StdDraw.circle(.70,.45,.015);

   }
   else if(total == 9)
   {
   StdDraw.square(.25,.5,.15);
   StdDraw.square(.75,.5,.15);
   StdDraw.circle(.80,.55,.015);
   StdDraw.circle(.70,.55,.015);
   StdDraw.circle(.80,.45,.015);
   StdDraw.circle(.70,.45,.015);
   StdDraw.circle(.20,.55,.015);
   StdDraw.circle(.30,.55,.015);
   StdDraw.circle(.20,.45,.015);
   StdDraw.circle(.30,.45,.015);
   StdDraw.circle(.25,.5,.015);
   }
   else if(total == 10)
   {
   StdDraw.square(.25,.5,.15);
   StdDraw.square(.75,.5,.15);
   StdDraw.circle(.20,.55,.015);
   StdDraw.circle(.30,.55,.015);
   StdDraw.circle(.20,.45,.015);
   StdDraw.circle(.30,.45,.015);
   StdDraw.circle(.25,.5,.015);
   StdDraw.circle(.80,.55,.015);
   StdDraw.circle(.70,.55,.015);
   StdDraw.circle(.70,.45,.015);
   StdDraw.circle(.80,.45,.015);
   StdDraw.circle(.75,.5,.015);
   }
   else if(total == 11)
   {
   StdDraw.square(.25,.5,.15);
   StdDraw.square(.75,.5,.15);
   StdDraw.circle(.80,.55,.015);
   StdDraw.circle(.70,.55,.015);
   StdDraw.circle(.70,.45,.015);
   StdDraw.circle(.80,.45,.015);
   StdDraw.circle(.75,.5,.015);
   StdDraw.circle(.20,.6,.015);
   StdDraw.circle(.20,.4,.015);
   StdDraw.circle(.20,.5,.015);
   StdDraw.circle(.30,.6,.015);
   StdDraw.circle(.30,.4,.015);
   StdDraw.circle(.30,.5,.015);
   }
   else if(total == 12)
   {
   StdDraw.square(.25,.5,.15);
   StdDraw.square(.75,.5,.15);
   StdDraw.circle(.20,.6,.015);
   StdDraw.circle(.20,.4,.015);
   StdDraw.circle(.20,.5,.015);
   StdDraw.circle(.30,.6,.015);
   StdDraw.circle(.30,.4,.015);
   StdDraw.circle(.30,.5,.015);
   StdDraw.square(.25,.5,.15);
   StdDraw.square(.75,.5,.15);
   StdDraw.circle(.70,.6,.015);
   StdDraw.circle(.70,.4,.015);
   StdDraw.circle(.70,.5,.015);
   StdDraw.circle(.80,.6,.015);
   StdDraw.circle(.80,.4,.015);
   StdDraw.circle(.80,.5,.015);
   }


  
   }

}
You need to do it something like this:
PHP Code

<?php 
public static void paintDice(int num) {
   if (
num == 1) {
      
// code to paint the "1" dice here
   
} else if (num == 2) {
      
// code to paint the "2" dice here
   
} // etc.
} 

And then in your main method you would do paintDice(num1) and paintDice(num2).
Thank you null byte That makes sense will post again if I run into any problems I appreciate it.


Updated the op with source for others who look for something like this.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by ICUPApr 3, 2020 08:21 AM 3 186 Apr 3, 2020 08:21 AM
Last Post: lockhead
[Python] by Mr.RichieApr 25, 2018 09:56 PM 5 155 Apr 25, 2018 09:56 PM
Last Post: cleptom
[Python] by Will PattersonOct 6, 2017 11:02 AM 9 290 Oct 6, 2017 11:02 AM
Last Post: koolkid