Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class Project_Three here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class PokerDice
- {
- private GVdie[] dice;
- public int rolls=0;
- public int score=0;
- public int rounds =0;
- public int []tally;
- private final static int FIVE_OF_A_KIND=50;
- private final static int FOUR_OF_A_KIND=40;
- private final static int THREE_OF_A_KIND=25;
- private final static int FULL_HOUSE=35;
- private final static int SMALL_STRAIGHT=30;
- private final static int LARGE_STRAIGHT=45;
- public PokerDice() {
- dice = new GVdie[5];
- for (int i = 0; i < dice.length; i++) {
- dice[i] = new GVdie();
- }
- tally= new int[7];
- resetGame();
- }
- public int getScore () {
- return score;
- }
- public int getNumRolls(){
- return rolls;
- }
- public int getNumRounds(){
- return rounds;
- }
- public boolean okToRoll (){
- if (rolls >= 3){
- return false;
- }
- else{
- return true;
- }
- }
- public boolean gameOver(){
- if (rounds > 7){
- return true;
- }
- else{
- return false;
- }
- }
- public GVdie [] getDice (){
- return dice;
- }
- public void setDice(int [] values){
- for (int i=0; i < values.length; i++){
- if(values[i] < 1 || values[i] > 6){
- values[i]=1;
- }
- dice[i].roll();
- while(values[i]!=dice[i].getValue()){
- dice[i].roll();
- }
- }
- }
- public void resetGame(){
- rounds= 0;
- rolls=0;
- score=0;
- for (int i=0; i < dice.length; i++){
- dice[i].setBlank();
- dice[i].setHeld(false);
- }
- }
- //need help with this
- public String diceToString (){
- String str="";
- for (int i=0; i < dice.length ; i++){
- str+= dice[i].getValue() +",";
- }
- return str;
- }
- public void tallyDice ( ){
- int count=0;
- int val=0;
- for(int i=0;i < tally.length;i++){
- tally[i]=count;
- }
- for(int i=0; i <dice.length; i++){
- val = dice[i].getValue();
- tally[val]++;
- }
- }
- private boolean hasStraight (int length) {
- tallyDice();
- int count=0;
- for (int i=0; i < tally.length; i++){
- if(tally[i]>=1){
- count++;
- if (count==length){
- return true;
- }
- }
- else{
- count=0;
- }
- }
- return false;
- }
- private boolean hasMultiples(int count) {
- tallyDice();
- for (int i=0; i < tally.length; i++){
- if (tally[i]>=count){
- return true;
- }
- }
- return false;
- }
- private boolean hasStrictPair(){
- tallyDice();
- for (int i=0; i < tally.length; i++){
- if (tally[i]==2){
- return true;
- }
- }
- return false;
- }
- private void nextround (){
- for (int i=0; i < dice.length; i++){
- dice[i].setBlank();
- dice[i].setHeld(false);
- }
- rounds++;
- rolls=0;
- }
- public void rollDice (){
- for(int i=0; i < dice.length; i++){
- if(!dice[i].isHeld()){
- dice[i].roll();
- }
- }
- rolls++;
- }
- public void checkThreeOfAKind(){
- if (hasMultiples(3)==true){
- score=score+THREE_OF_A_KIND;
- }
- nextround();
- }
- public void checkFullHouse(){
- if (hasMultiples(3) && hasStrictPair() ==true){
- score=score+FULL_HOUSE;
- }
- if (hasMultiples(5) == true){
- score=score+FULL_HOUSE;
- }
- nextround();
- }
- public void checkSmallStraight(){
- if (hasStraight(4)==true){
- score=score+SMALL_STRAIGHT;
- }
- nextround();
- }
- public void checkLargeStraight(){
- if (hasStraight(5)==true){
- score=score+LARGE_STRAIGHT;
- }
- nextround();
- }
- public void checkFiveOfAKind(){
- hasMultiples(5);
- if (hasMultiples(5)==true){
- score=score+FIVE_OF_A_KIND;
- }
- nextround();
- }
- public void checkFourOfAKind(){
- hasMultiples(4);
- if (hasMultiples(4)==true){
- score=score+FOUR_OF_A_KIND;
- }
- nextround();
- }
- public void checkChance (){
- for(int i=0; i <dice.length; i++){
- score=score+dice[i].getValue();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement