another test

This commit is contained in:
Daniel Schneider 2025-03-12 11:42:30 +01:00
parent 2746a14af9
commit 40a19f0401

View File

@ -32,8 +32,13 @@ public class Cubez {
oCubez.checkRounds();
}
oCubez.clearScreen();
System.out.println("\nAll turns used up! Now for the result...\n\n");
oCubez.sSheet.printScores();
System.out.println("\nBetter luck next time!\n\n");
if(oCubez.sSheet.total<100) System.out.println("\nMy brother in christ, did you even try?\n\n");
if(oCubez.sSheet.total<200 && oCubez.sSheet.total >= 100) System.out.println("\nMaybe try that again?\n\n");
if(oCubez.sSheet.total<300 && oCubez.sSheet.total >= 200) System.out.println("\nBetter luck next time!\n\n");
if(oCubez.sSheet.total >= 300) System.out.println("\nHoly cow, that is a number!\n\n");
}
public void clearScreen() {
@ -80,55 +85,70 @@ public class Cubez {
public void storeCube() {
outputUI();
System.out.print("Pick cube to store: ");
System.out.print("Pick cube(z) to store: ");
String tmpIn = System.console().readLine();
int pos = Integer.parseInt(tmpIn);
if(pos<1 || pos>5) return;
if(cubeCache[pos-1] == 0) return;
int freePos = -1;
for(int i=0; i<cubeStorage.length; i++) {
if(cubeStorage[i] == 0) {
freePos = i;
break;
}
}
cubeStorage[freePos] = cubeCache[pos-1];
cubeCache[pos-1] = 0;
storedCubez = storedCubez+1;
int operations = tmpIn.length();
if(operations>5 || operations<=0) return;
for(int i=0;i<operations;i++) {
int pos = tmpIn.charAt(i) - '0';
if(pos<1 || pos>5) return;
if(cubeCache[pos-1] == 0) continue;
int freePos = -1;
for(int j=0; j<cubeStorage.length; j++) {
if(cubeStorage[j] == 0) {
freePos = j;
break;
}
}
cubeStorage[freePos] = cubeCache[pos-1];
cubeCache[pos-1] = 0;
storedCubez = storedCubez+1;
}
}
public void cacheCube() {
outputUI();
System.out.print("Pick cube to cache: ");
System.out.print("Pick cube(z) to cache: ");
String tmpIn = System.console().readLine();
int pos = Integer.parseInt(tmpIn);
if(pos<1 || pos>5) return;
if(cubeStorage[pos-1] == 0) return;
int freePos = -1;
for(int i=0; i<cubeCache.length; i++) {
if(cubeCache[i] == 0) {
freePos = i;
break;
}
}
int operations = tmpIn.length();
if(operations>5 || operations<=0) return;
cubeCache[freePos] = cubeStorage[pos-1];
cubeStorage[pos-1] = 0;
storedCubez = storedCubez-1;
for(int i=0;i<operations;i++) {
int pos = tmpIn.charAt(i) - '0';
if(pos<1 || pos>5) return;
if(cubeStorage[pos-1] == 0) return;
int freePos = -1;
for(int j=0; j<cubeCache.length; j++) {
if(cubeCache[j] == 0) {
freePos = j;
break;
}
}
cubeCache[freePos] = cubeStorage[pos-1];
cubeStorage[pos-1] = 0;
storedCubez = storedCubez-1;
}
}
public void endTurn() {
sSheet.setScore(cubeStorage);
boolean setScoreSuccessful = sSheet.setScore(cubeStorage);
for(int i=0;i<cubeStorage.length;i++) {
cubeStorage[i] = 0;
cubeCache[i] = 0;
if(setScoreSuccessful) {
for(int i=0;i<cubeStorage.length;i++) {
cubeStorage[i] = 0;
cubeCache[i] = 0;
}
rollsLeft = 3;
storedCubez = 0;
rounds = rounds + 1;
}
rollsLeft = 3;
storedCubez = 0;
}
public void quit() {
@ -146,8 +166,8 @@ public class Cubez {
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;
case "o": transferCubez(cubeStorage, cubeCache); storedCubez = 0; break;
case "m": transferCubez(cubeCache, cubeStorage); storedCubez = 5; break;
default: break;
}
}
@ -175,8 +195,6 @@ public class Cubez {
}
}
}
storedCubez = 0;
}
@ -229,34 +247,39 @@ public class Cubez {
if(numSum >= 63) this.bonus = 35;
}
public void setScore(int[] store) {
public boolean setScore(int[] store) {
clearScreen();
sSheet.printScores();
outputStorage();
System.out.print("\nWhat score to set? [type name] ");
String choice = System.console().readLine();
boolean sSuccess = false;
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;
case "aces": sSuccess = setNumbers(store, 1); return sSuccess;
case "twos": sSuccess = setNumbers(store, 2); return sSuccess;
case "threes": sSuccess = setNumbers(store, 3); return sSuccess;
case "fours": sSuccess = setNumbers(store, 4); return sSuccess;
case "fives": sSuccess = setNumbers(store, 5); return sSuccess;
case "sixes": sSuccess = setNumbers(store, 6); return sSuccess;
case "triple": sSuccess = setTuple(store, 3); return sSuccess;
case "quadruple": sSuccess = setTuple(store, 4); return sSuccess;
case "fulltime": sSuccess = setFulltime(store); return sSuccess;
case "escalator": sSuccess = setEscalator(store); return sSuccess;
case "elevator": sSuccess = setElevator(store); return sSuccess;
case "pentacube": sSuccess = setPENTACUBE(store); return sSuccess;
case "chance": sSuccess = setChance(store); return sSuccess;
case "": return false;
default: setScore(store); break;
}
return false;
}
public void setNumbers(int[] store, int number) {
public boolean setNumbers(int[] store, int number) {
int scoreTS = 0;
String yN = "n";
boolean sSuccess = false;
for (int i=0; i<store.length; i++) {
if (store[i] == number) scoreTS = scoreTS + store[i];
@ -266,49 +289,45 @@ public class Cubez {
case 1:
System.out.print("Set " + scoreTS + " for \"Aces\"? [y/n] ");
yN = System.console().readLine();
if(yN.contains("y")) { this.aces = scoreTS; } else { this.setScore(store); return; }
if(yN.contains("y")) { this.aces = scoreTS; } else { sSuccess = this.setScore(store); return sSuccess; }
this.total = this.total + scoreTS;
rounds = rounds + 1;
break;
return true;
case 2:
System.out.print("Set " + scoreTS + " for \"Twos\"? [y/n] ");
yN = System.console().readLine();
if(yN.contains("y")) { this.twos = scoreTS; } else { this.setScore(store); return; }
if(yN.contains("y")) { this.twos = scoreTS; } else { sSuccess = this.setScore(store); return sSuccess; }
this.total = this.total + scoreTS;
rounds = rounds + 1;
break;
return true;
case 3:
System.out.print("Set " + scoreTS + " for \"Threes\"? [y/n] ");
yN = System.console().readLine();
if(yN.contains("y")) { this.threes = scoreTS; } else { this.setScore(store); return; }
if(yN.contains("y")) { this.threes = scoreTS; } else { sSuccess = this.setScore(store); return sSuccess; }
this.total = this.total + scoreTS;
rounds = rounds + 1;
break;
return true;
case 4:
System.out.print("Set " + scoreTS + " for \"Fours\"? [y/n] ");
yN = System.console().readLine();
if(yN.contains("y")) { this.fours = scoreTS; } else { this.setScore(store); return; }
if(yN.contains("y")) { this.fours = scoreTS; } else { sSuccess = this.setScore(store); return sSuccess; }
this.total = this.total + scoreTS;
rounds = rounds + 1;
break;
return true;
case 5:
System.out.print("Set " + scoreTS + " for \"Fives\"? [y/n] ");
yN = System.console().readLine();
if(yN.contains("y")) { this.fives = scoreTS; } else { this.setScore(store); return; }
if(yN.contains("y")) { this.fives = scoreTS; } else { sSuccess = this.setScore(store); return sSuccess; }
this.total = this.total + scoreTS;
rounds = rounds + 1;
break;
return true;
case 6:
System.out.print("Set " + scoreTS + " for \"Sixes\"? [y/n] ");
yN = System.console().readLine();
if(yN.contains("y")) { this.sixes = scoreTS; } else { this.setScore(store); return; }
if(yN.contains("y")) { this.sixes = scoreTS; } else { sSuccess = this.setScore(store); return sSuccess; }
this.total = this.total + scoreTS;
rounds = rounds + 1;
break;
return true;
default:
return false;
}
}
public void setTuple(int[] store, int kind) {
public boolean setTuple(int[] store, int kind) {
int scoreTS = 0;
int[] freq = new int[7];
String kindText = ( (kind == 3) ? "Triple" : "Quadruple" );
@ -318,7 +337,13 @@ public class Cubez {
}
for(int i=0;i<freq.length;i++) {
if(freq[i] == kind) scoreTS = kind * i;
// if(freq[i] == kind) scoreTS = kind * i;
if(kind == 3) {
if(freq[i] >= 3) scoreTS = kind * i;
}
else {
if(freq[i] >= 4) scoreTS = kind * i;
}
}
if(scoreTS > 0) {
@ -332,22 +357,22 @@ public class Cubez {
System.out.print("Set " + scoreTS + " for \"" + kindText + "\"? [y/n] ");
String yN = System.console().readLine();
if(yN.contains("y")) {
if(kind == 3) {
this.threeOAK = scoreTS;
if(kind >= 4) {
this.fourOAK = scoreTS;
}
else {
this.fourOAK = scoreTS;
this.threeOAK = scoreTS;
}
}
else {
this.setScore(store); return;
boolean sSuccess = this.setScore(store); return sSuccess;
}
this.total = this.total + scoreTS;
rounds = rounds + 1;
return true;
}
public void setFulltime(int[] store) {
public boolean setFulltime(int[] store) {
int[] freq = new int[7];
boolean triplet = false;
boolean tuplet = false;
@ -368,12 +393,12 @@ public class Cubez {
System.out.print("Set " + scoreTS + " for \"Fulltime\"? [y/n] ");
String yN = System.console().readLine();
if(yN.contains("y")) { this.fullHouse = scoreTS; } else { this.setScore(store); return; }
if(yN.contains("y")) { this.fullHouse = scoreTS; } else { boolean sSuccess = this.setScore(store); return sSuccess; }
this.total = this.total + scoreTS;
rounds = rounds + 1;
return true;
}
public void setEscalator(int[] store) {
public boolean setEscalator(int[] store) {
int[] freq = new int[7];
int streak = 0;
int scoreTS = 0;
@ -384,6 +409,8 @@ public class Cubez {
for(int i=1;i<freq.length;i++) {
if(freq[i] == 1) streak = streak + 1;
if(streak == 4) break;
if(freq[i] == 0) streak = 0;
}
if (streak >= 4) {
@ -392,12 +419,12 @@ public class Cubez {
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; }
if(yN.contains("y")) { this.smallStraight = scoreTS; } else { boolean sSuccess = this.setScore(store); return sSuccess; }
this.total = this.total + scoreTS;
rounds = rounds + 1;
return true;
}
public void setElevator(int[] store) {
public boolean setElevator(int[] store) {
int[] freq = new int[7];
int streak = 0;
int scoreTS = 0;
@ -408,20 +435,22 @@ public class Cubez {
for(int i=1;i<freq.length;i++) {
if(freq[i] == 1) streak = streak + 1;
if(streak == 5) break;
if(freq[i] == 0) streak = 0;
}
if (streak >= 5) {
if (streak == 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; }
if(yN.contains("y")) { this.largeStraight = scoreTS; } else { boolean sSuccess = this.setScore(store); return sSuccess; }
this.total = this.total + scoreTS;
rounds = rounds + 1;
return true;
}
public void setPENTACUBE(int[] store) {
public boolean setPENTACUBE(int[] store) {
int[] freq = new int[7];
int scoreTS = 0;
boolean penta = false;
@ -438,23 +467,23 @@ public class Cubez {
System.out.print("Set " + scoreTS + " for \"PENTACUBE\"? [y/n] ");
String yN = System.console().readLine();
if(yN.contains("y")) { this.pentaCube = scoreTS; } else { this.setScore(store); return; }
if(yN.contains("y")) { this.pentaCube = scoreTS; } else { boolean sSuccess = this.setScore(store); return sSuccess; }
this.total = this.total + scoreTS;
rounds = rounds + 1;
return true;
}
public void setChance(int[] store) {
public boolean setChance(int[] store) {
int scoreTS = 0;
for(int i=0;i<store.length;i++) {
scoreTS = scoreTS + store[i];
}
System.out.print("Set " + scoreTS + " for \"Chance\"? [y/n] ");
String yN = System.console().readLine();
if(yN.contains("y")) { this.chance = scoreTS; } else { this.setScore(store); return; }
this.total = this.total + scoreTS;
rounds = rounds + 1;
System.out.print("Set " + scoreTS + " for \"Chance\"? [y/n] ");
String yN = System.console().readLine();
if(yN.contains("y")) { this.chance = scoreTS; } else { boolean sSuccess = this.setScore(store); return sSuccess; }
this.total = this.total + scoreTS;
return true;
}
}
}