Advertisement
Guest User

PetalsGame

a guest
Oct 8th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class PetalGame
  2. {
  3.     private int d1;
  4.     private int d2;
  5.     private int d3;
  6.     private int d4;
  7.     private int d5;
  8.  
  9.     public PetalGame(int inD1, int inD2, int inD3, int inD4, int inD5)
  10.     {
  11.         d1 = inD1;
  12.         d2 = inD2;
  13.         d3 = inD3;
  14.         d4 = inD4;
  15.         d5 = inD5;
  16.     }
  17.  
  18.     public int rollDice()
  19.     {
  20.         return (int) ((Math.random() * 6) + 1);
  21.     }
  22.  
  23.     public void calculateDice()
  24.     {
  25.         d1 = rollDice();
  26.         d2 = rollDice();
  27.         d3 = rollDice();
  28.         d4 = rollDice();
  29.         d5 = rollDice();
  30.     }
  31.  
  32.     public int calculateAllPetals()          
  33.     {
  34.         int totalPetals = 0;
  35.        
  36.         totalPetals += dicePoints(d1);
  37.         totalPetals += dicePoints(d2);
  38.         totalPetals += dicePoints(d3);
  39.         totalPetals += dicePoints(d4);
  40.         totalPetals += dicePoints(d5);
  41.        
  42.         return totalPetals;
  43.     }
  44.  
  45.     public int dicePoints(int diceRoll)
  46.     {
  47.         if(diceRoll==3||diceRoll==5)
  48.             return diceRoll-1;
  49.         else
  50.             return 0;
  51.     }
  52.  
  53.     public void printDiceRolles()
  54.     {
  55.         System.out.println("Dice 1: " + d1);
  56.         System.out.println("Dice 2: " + d2);
  57.         System.out.println("Dice 3: " + d3);
  58.         System.out.println("Dice 4: " + d4);
  59.         System.out.println("Dice 5: " + d5);
  60.     }
  61.  
  62.     public void printPetals()
  63.     {
  64.         System.out.println("Points: " + calculateAllPetals());
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement