commit 2746a14af9bd802122476d913d73c70c46246739 Author: Daniel Schneider Date: Mon Jan 27 13:15:23 2025 +0100 INIT: game playable, but code messy, contains boilerplate, terminal cooked mode is anoying and should be set to raw diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6b468b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.class diff --git a/Cubez.java b/Cubez.java new file mode 100644 index 0000000..2df3e4d --- /dev/null +++ b/Cubez.java @@ -0,0 +1,460 @@ +public class Cubez { + + private static boolean done; + private ScoreSheet sSheet = new ScoreSheet(); + private int[] cubeCache = new int[5]; + private int[] cubeStorage = new int[5]; + private int storedCubez = 0; + private int rollsLeft = 3; + private int rounds = 0; + + public static void main(String[] args) { + System.out.println(" ___ _ ____"); + System.out.println("| _| _ _ | |_ ___ |_ /"); + System.out.println("| <__| | || . \\/ ._> / /"); + System.out.println("`___/`___||___/\\___./___|"); + System.out.print("press return key to start... good luck!"); + System.console().readLine(); + + Cubez oCubez = new Cubez(); + while(!done) { + if(oCubez.sSheet.bonus == 0) oCubez.sSheet.checkBonus(); + + oCubez.outputUI(); + + System.out.println("score: " + oCubez.sSheet.total + ", turns left: " + (13 - oCubez.rounds) + ", rolls left: " + oCubez.rollsLeft + "\n\n"); + System.out.println("[s]tore cube [c]ache cube [r]oll cubez, "); + System.out.println("[m]egastore [o]mnicache "); + System.out.println("[v]iew scores [e]nd turn [q]uit Cubez\n"); + System.out.print("Pick action: "); + + oCubez.handleUserInput(); + oCubez.checkRounds(); + } + + oCubez.sSheet.printScores(); + System.out.println("\nBetter luck next time!\n\n"); + } + + public void clearScreen() { + System.out.print("\033[H\033[2J"); + System.out.flush(); + } + + public int rollD6() { + int tmp = ((int)(Math.random() * 6)) + 1; + return tmp; + } + + public void rollCache() { + int rolls = 5 - storedCubez; + for(int i=0; i<5; i++) { + cubeCache[i] = rollD6(); + if(i>(rolls-1)) cubeCache[i] = 0; + } + rollsLeft = rollsLeft-1; + } + + public void outputCache() { + for(int i=0; i5) return; + if(cubeCache[pos-1] == 0) return; + + int freePos = -1; + for(int i=0; i5) return; + if(cubeStorage[pos-1] == 0) return; + + int freePos = -1; + for(int i=0; i0) rollCache(); break; + case "v": sSheet.printScores(); System.console().readLine(); break; + case "e": endTurn(); break; + case "q": quit(); break; + case "o": transferCubez(cubeStorage, cubeCache); break; + case "m": transferCubez(cubeCache, cubeStorage); break; + default: break; + } + } + + public void checkRounds() { + if(rounds == 13) done = true; + } + + private int sum(int[] arr) { + int s=0; + for(int i=0;i 0) { + for(int i=0;i= 63) this.bonus = 35; + } + + public void setScore(int[] store) { + clearScreen(); + sSheet.printScores(); + outputStorage(); + System.out.print("\nWhat score to set? [type name] "); + String choice = System.console().readLine(); + + switch (choice) { + case "aces": setNumbers(store, 1); break; + case "twos": setNumbers(store, 2); break; + case "threes": setNumbers(store, 3); break; + case "fours": setNumbers(store, 4); break; + case "fives": setNumbers(store, 5); break; + case "sixes": setNumbers(store, 6); break; + case "triple": setTuple(store, 3); break; + case "quadruple": setTuple(store, 4); break; + case "fulltime": setFulltime(store); break; + case "escalator": setEscalator(store); break; + case "elevator": setElevator(store); break; + case "pentacube": setPENTACUBE(store); break; + case "chance": setChance(store); break; + default: setScore(store); break; + } + } + + public void setNumbers(int[] store, int number) { + int scoreTS = 0; + String yN = "n"; + + for (int i=0; i 0) { + scoreTS = 0; + + for(int i=0;i= 4) { + scoreTS = 30; + } + + System.out.print("Set " + scoreTS + " for \"Escalator\"? [y/n] "); + String yN = System.console().readLine(); + if(yN.contains("y")) { this.smallStraight = scoreTS; } else { this.setScore(store); return; } + this.total = this.total + scoreTS; + rounds = rounds + 1; + } + + public void setElevator(int[] store) { + int[] freq = new int[7]; + int streak = 0; + int scoreTS = 0; + + for(int i=0;i= 5) { + scoreTS = 40; + } + + System.out.print("Set " + scoreTS + " for \"Elevator\"? [y/n] "); + String yN = System.console().readLine(); + if(yN.contains("y")) { this.largeStraight = scoreTS; } else { this.setScore(store); return; } + this.total = this.total + scoreTS; + rounds = rounds + 1; + } + + public void setPENTACUBE(int[] store) { + int[] freq = new int[7]; + int scoreTS = 0; + boolean penta = false; + + for(int i=0;i