Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.97 KB | None | 0 0
  1. /**
  2.  * Write a description of class Project_Three here.
  3.  *
  4.  * @author (your name)
  5.  * @version (a version number or a date)
  6.  */
  7. public class PokerDice
  8. {
  9.     private GVdie[] dice;
  10.  
  11.    public int rolls=0;
  12.      public int score=0;
  13.     public int rounds =0;
  14.     public int []tally;
  15.  
  16.     private final static  int FIVE_OF_A_KIND=50;
  17.     private final static  int FOUR_OF_A_KIND=40;
  18.     private final static  int THREE_OF_A_KIND=25;
  19.     private final static  int FULL_HOUSE=35;
  20.     private final static  int SMALL_STRAIGHT=30;
  21.     private final static  int LARGE_STRAIGHT=45;
  22.     public PokerDice() {
  23.         dice = new GVdie[5];
  24.         for (int i = 0; i < dice.length; i++) {
  25.             dice[i] = new GVdie();
  26.         }
  27.         tally= new int[7];
  28.         resetGame();    
  29.  
  30.     }
  31.  
  32.     public int getScore () {
  33.         return score;
  34.     }
  35.  
  36.     public int getNumRolls(){
  37.         return rolls;
  38.     }
  39.  
  40.     public int getNumRounds(){
  41.         return rounds;
  42.     }
  43.  
  44.     public boolean okToRoll (){
  45.        
  46.         if (rolls >= 3){
  47.             return false;
  48.         }
  49.         else{
  50.             return true;
  51.            
  52.         }
  53.        
  54.     }
  55.  
  56.     public boolean gameOver(){
  57.            
  58.         if (rounds > 7){
  59.             return true;
  60.         }
  61.         else{
  62.             return false;
  63.                     }
  64.  
  65.     }
  66.  
  67.     public GVdie [] getDice (){
  68.         return dice;
  69.  
  70.     }
  71.  
  72.     public void setDice(int [] values){
  73.         for (int i=0; i < values.length; i++){
  74.             if(values[i] < 1 || values[i] > 6){
  75.                 values[i]=1;
  76.             }
  77.             dice[i].roll();
  78.  
  79.             while(values[i]!=dice[i].getValue()){
  80.                 dice[i].roll();
  81.             }
  82.                     }
  83.     }
  84.  
  85.     public void resetGame(){
  86.         rounds= 0;
  87.         rolls=0;
  88.         score=0;
  89.         for (int i=0; i < dice.length; i++){
  90.             dice[i].setBlank();
  91.             dice[i].setHeld(false);
  92.         }
  93.     }
  94.     //need help with this
  95.     public String diceToString (){
  96.         String str="";
  97.         for (int i=0; i < dice.length ; i++){
  98.             str+= dice[i].getValue() +",";
  99.         }
  100.         return str;
  101.     }
  102.  
  103.     public void tallyDice ( ){
  104.         int count=0;
  105.         int val=0;
  106.         for(int i=0;i < tally.length;i++){
  107.             tally[i]=count;
  108.         }
  109.         for(int i=0; i <dice.length; i++){
  110.             val = dice[i].getValue();
  111.             tally[val]++;
  112.  
  113.         }
  114.     }
  115.  
  116.     private boolean hasStraight (int length) {
  117.         tallyDice();
  118.         int count=0;
  119.         for (int i=0; i < tally.length; i++){
  120.             if(tally[i]>=1){
  121.                 count++;
  122.                 if (count==length){
  123.                     return true;
  124.                 }
  125.             }
  126.             else{
  127.                 count=0;
  128.             }
  129.         }
  130.         return false;
  131.     }
  132.  
  133.     private boolean hasMultiples(int count) {
  134.         tallyDice();
  135.         for (int i=0; i < tally.length; i++){
  136.             if (tally[i]>=count){
  137.                 return true;
  138.             }
  139.         }
  140.         return false;
  141.     }
  142.  
  143.     private boolean hasStrictPair(){
  144.         tallyDice();
  145.         for (int i=0; i < tally.length; i++){
  146.             if (tally[i]==2){
  147.                 return true;
  148.             }
  149.         }
  150.         return false;
  151.     }
  152.  
  153.     private void nextround  (){
  154.                 for (int i=0; i < dice.length; i++){
  155.             dice[i].setBlank();
  156.             dice[i].setHeld(false);
  157.         }
  158.         rounds++;
  159.         rolls=0;
  160.     }
  161.  
  162.     public void rollDice (){
  163.         for(int i=0; i < dice.length; i++){  
  164.             if(!dice[i].isHeld()){
  165.                 dice[i].roll();
  166.             }
  167.         }
  168.         rolls++;
  169.     }
  170.  
  171.     public void checkThreeOfAKind(){
  172.        
  173.         if (hasMultiples(3)==true){
  174.             score=score+THREE_OF_A_KIND;
  175.         }
  176.  
  177.         nextround();
  178.     }
  179.  
  180.     public void checkFullHouse(){
  181.        
  182.        
  183.         if (hasMultiples(3) && hasStrictPair() ==true){
  184.             score=score+FULL_HOUSE;
  185.         }
  186.         if (hasMultiples(5) == true){
  187.          score=score+FULL_HOUSE;  
  188.         }
  189.         nextround();
  190.     }
  191.  
  192.     public void checkSmallStraight(){
  193.        
  194.         if (hasStraight(4)==true){
  195.             score=score+SMALL_STRAIGHT;
  196.         }
  197.  
  198.         nextround();
  199.  
  200.     }
  201.  
  202.     public void checkLargeStraight(){
  203.        
  204.         if (hasStraight(5)==true){
  205.             score=score+LARGE_STRAIGHT;
  206.         }
  207.         nextround();
  208.     }
  209.  
  210.     public void checkFiveOfAKind(){
  211.         hasMultiples(5);
  212.         if (hasMultiples(5)==true){
  213.             score=score+FIVE_OF_A_KIND;
  214.         }
  215.         nextround();
  216.     }
  217.  
  218.     public void checkFourOfAKind(){
  219.         hasMultiples(4);
  220.         if (hasMultiples(4)==true){
  221.             score=score+FOUR_OF_A_KIND;
  222.         }
  223.         nextround();
  224.     }
  225.  
  226.     public void checkChance (){
  227.         for(int i=0; i <dice.length; i++){
  228.             score=score+dice[i].getValue();
  229.         }
  230.     }
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement