Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class MyProgram {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int[] diceRollsArray = new int[6];
- int[] diceCounts = {0, 0, 0, 0, 0, 0};
- int userTotalScore = 0; //stores total.
- boolean continueGame = true;
- //int userScore = countScore(diceCounts);
- //System.out.println("Score is: " + userScore);
- while (continueGame == true && userTotalScore < 2000){
- //start game by starting dice roll
- diceRollsArray = randomArray(6);
- //Printing the dice rolls
- System.out.println("Dice Roll: " + Arrays.toString(diceRollsArray));
- //resets the diceCounts so after the first round it resets
- //Arrays.fill(diceCounts, 0);
- for (int i = 0; i < diceCounts.length; i++){
- diceCounts[i] = 0;
- }
- // asks user which dices ones to keep
- askUserToBank(diceCounts,diceRollsArray);
- //validates users responce
- //***********validate(int toCheckValue,int[] array)
- //stores total score of user
- userTotalScore += countScore(diceCounts);
- //prints users total score
- System.out.println("Round Score: " + userTotalScore);
- //if the score is == 0 than quit because user has farkeled.
- if (userTotalScore == 0){
- System.out.println("Farkle!");
- }
- System.out.println("Do you want to continue? (y/n)");
- String userInput = input.nextLine();
- if (userInput.equalsIgnoreCase("n")) {
- continueGame = false;
- }
- }
- System.out.println("\nGame Over!\n\nYour total score: " + userTotalScore);
- }
- // 1
- public static int[] randomArray(int numberOfDice) {
- int[] arrayRandom = new int[numberOfDice];
- Random random = new Random();
- for (int i = 0; i < numberOfDice; i++) {
- arrayRandom[i] = random.nextInt(6) + 1; // 1 to 6 *inclusivly*
- }
- return arrayRandom;
- }
- // 2 - dice being kept
- public static void askUserToBank(int[] diceCounts, int[] diceRolls) {
- Scanner input = new Scanner(System.in);
- // System.out.print(+randArray);
- System.out.println("choose dice to keep: ");
- String diceKept = input.nextLine();
- for (int i= 0; i <diceKept.length(); i++) {
- char diceChar = diceKept.charAt(i);
- int diceIndex = diceChar - '1';
- if (diceIndex >= 0 && diceIndex < diceCounts.length) {
- diceCounts[diceIndex]++;
- diceRolls[diceIndex] = 0;
- }
- }
- int usersResponce[] = {};
- for (int i = 0; i < diceCounts.length; i++){
- }
- }
- // 3
- public static int countScore(int[] countScoreArray) {
- int userScore = 0;
- int lc = 2;
- for (int i = 1; i < countScoreArray.length; i++) {
- if (countScoreArray[i] == 3) {
- userScore += lc * 100;
- }
- lc += 1;
- }
- if (countScoreArray[0] == 3) {
- userScore += 1000;
- } else if (countScoreArray[0] < 3) {
- userScore += 100 * countScoreArray[0];
- } else if (countScoreArray[0] > 3) {
- userScore += 1000 + ((countScoreArray[0] - 3) * 100);
- }
- if (countScoreArray[4] < 3) {
- userScore += 50 * countScoreArray[4];
- }
- return userScore;
- }
- public static int amountOfDicesToRoll(int[] diceCounts){
- int num = 0;
- for (int i = 0; i < diceCounts.length; i++){
- if (diceCounts[i] != 0){
- num += 1;
- }
- }
- return num;
- }
- public static void introduction(){
- System.out.println("Welcome to Farkle!... Rules... Quit.. et.c");
- }
- public static boolean validate(int toCheckValue,int[] array){
- boolean test = Arrays.asList(array).contains(toCheckValue);
- return test;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment