Guest User

Untitled

a guest
Jun 14th, 2023
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.43 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class MyProgram {
  4.     public static void main(String[] args) {
  5.         Scanner input = new Scanner(System.in);
  6.        
  7.         int[] diceRollsArray = new int[6];
  8.         int[] diceCounts = {0, 0, 0, 0, 0, 0};
  9.         int userTotalScore = 0; //stores total.
  10.         boolean continueGame = true;
  11.        
  12.         //int userScore = countScore(diceCounts);
  13.         //System.out.println("Score is: " + userScore);
  14.        
  15.        
  16.         while (continueGame == true && userTotalScore < 2000){
  17.             //start game by starting dice roll
  18.             diceRollsArray = randomArray(6);
  19.             //Printing the dice rolls
  20.             System.out.println("Dice Roll: "  + Arrays.toString(diceRollsArray));
  21.             //resets the diceCounts so after the first round it resets
  22.             //Arrays.fill(diceCounts, 0);
  23.             for (int i = 0; i < diceCounts.length; i++){
  24.                 diceCounts[i] = 0;
  25.             }
  26.             // asks user which dices ones to keep
  27.             askUserToBank(diceCounts,diceRollsArray);
  28.             //validates users responce
  29.             //***********validate(int toCheckValue,int[] array)
  30.             //stores total score of user
  31.             userTotalScore += countScore(diceCounts);
  32.             //prints users total score
  33.             System.out.println("Round Score: " + userTotalScore);
  34.            
  35.             //if the score is == 0 than quit because user has farkeled.
  36.            
  37.             if (userTotalScore == 0){
  38.                 System.out.println("Farkle!");
  39.             }
  40.            
  41.             System.out.println("Do you want to continue? (y/n)");
  42.             String userInput = input.nextLine();
  43.             if (userInput.equalsIgnoreCase("n")) {
  44.                 continueGame = false;
  45.             }
  46.         }
  47.         System.out.println("\nGame Over!\n\nYour total score: " + userTotalScore);
  48.        
  49.        
  50.        
  51.        
  52.        
  53.        
  54.     }
  55.    
  56.     // 1
  57.     public static int[] randomArray(int numberOfDice) {
  58.         int[] arrayRandom = new int[numberOfDice];
  59.         Random random = new Random();
  60.         for (int i = 0; i < numberOfDice; i++) {
  61.             arrayRandom[i] = random.nextInt(6) + 1; // 1 to 6 *inclusivly*
  62.         }
  63.         return arrayRandom;
  64.     }
  65.    
  66.     // 2 - dice being kept
  67.     public static void askUserToBank(int[] diceCounts, int[] diceRolls) {
  68.         Scanner input = new Scanner(System.in);
  69.         //  System.out.print(+randArray);
  70.         System.out.println("choose dice to keep: ");
  71.         String diceKept = input.nextLine();
  72.  
  73.         for (int i= 0; i <diceKept.length(); i++) {
  74.             char diceChar = diceKept.charAt(i);
  75.             int diceIndex = diceChar - '1';
  76.             if (diceIndex >= 0 && diceIndex < diceCounts.length) {
  77.                 diceCounts[diceIndex]++;
  78.                 diceRolls[diceIndex] = 0;
  79.             }
  80.         }
  81.         int usersResponce[] = {};
  82.         for (int i = 0; i < diceCounts.length; i++){
  83.            
  84.         }
  85.        
  86.     }
  87.    
  88.     // 3
  89.     public static int countScore(int[] countScoreArray) {
  90.         int userScore = 0;
  91.         int lc = 2;
  92.         for (int i = 1; i < countScoreArray.length; i++) {
  93.             if (countScoreArray[i] == 3) {
  94.                 userScore += lc * 100;
  95.             }
  96.             lc += 1;
  97.         }
  98.        
  99.         if (countScoreArray[0] == 3) {
  100.             userScore += 1000;
  101.         } else if (countScoreArray[0] < 3) {
  102.             userScore += 100 * countScoreArray[0];
  103.         } else if (countScoreArray[0] > 3) {
  104.             userScore += 1000 + ((countScoreArray[0] - 3) * 100);
  105.         }
  106.        
  107.         if (countScoreArray[4] < 3) {
  108.             userScore += 50 * countScoreArray[4];
  109.         }
  110.        
  111.         return userScore;
  112.     }
  113.    
  114.     public static int amountOfDicesToRoll(int[] diceCounts){
  115.         int num = 0;
  116.         for (int i = 0; i < diceCounts.length; i++){
  117.             if (diceCounts[i] != 0){
  118.                 num += 1;
  119.             }
  120.         }
  121.         return num;
  122.     }
  123.    
  124.    
  125.     public static void introduction(){
  126.         System.out.println("Welcome to Farkle!... Rules... Quit.. et.c");
  127.     }
  128.    
  129.     public static boolean validate(int toCheckValue,int[] array){
  130.         boolean test = Arrays.asList(array).contains(toCheckValue);
  131.         return test;
  132.        
  133.     }
  134.    
  135.    
  136.    
  137.    
  138.    
  139.    
  140.    
  141.    
  142.    
  143.    
  144.    
  145.    
  146.    
  147.    
  148.    
  149.    
  150. }
Advertisement
Add Comment
Please, Sign In to add comment