mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 23:26:40 -08:00
invert if and factor out splat message
This commit is contained in:
@@ -59,7 +59,15 @@ public class Splat {
|
|||||||
System.out.printf("%10.2f %f\n", i, D);
|
System.out.printf("%10.2f %f\n", i, D);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!splat) {
|
if (splat) {
|
||||||
|
if (terminalReached) {
|
||||||
|
System.out.printf("%.2f SPLAT\n", (V / A) + ((jump.getAltitude() - (V * V / (2 * A))) / V));
|
||||||
|
} else {
|
||||||
|
System.out.printf("%.2f SPLAT\n", Math.sqrt(2 * jump.getAltitude() / A));
|
||||||
|
|
||||||
|
}
|
||||||
|
showRandomSplatMessage();
|
||||||
|
} else {
|
||||||
|
|
||||||
System.out.println("CHUTE OPEN");
|
System.out.println("CHUTE OPEN");
|
||||||
int J = 0;
|
int J = 0;
|
||||||
@@ -115,13 +123,39 @@ public class Splat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
boolean chosen = false;
|
||||||
|
while (!chosen) {
|
||||||
|
System.out.print("DO YOU WANT TO PLAY AGAIN ");
|
||||||
|
String Z = scanner.next();
|
||||||
|
if (Z.equals("YES")) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (Z.equals("NO")) {
|
||||||
|
System.out.print("PLEASE ");
|
||||||
|
while (true) {
|
||||||
|
Z = scanner.next();
|
||||||
|
if (Z.equals("YES")) {
|
||||||
|
chosen = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (Z.equals("NO")) {
|
||||||
|
System.out.println("SSSSSSSSSS.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
System.out.print("YES OR NO ");
|
||||||
|
}
|
||||||
|
continue;
|
||||||
} else {
|
} else {
|
||||||
if (terminalReached) {
|
System.out.print("YES OR NO ");
|
||||||
System.out.printf("%.2f SPLAT\n", (V / A) + ((jump.getAltitude() - (V * V / (2 * A))) / V));
|
}
|
||||||
} else {
|
}
|
||||||
System.out.printf("%.2f SPLAT\n", Math.sqrt(2 * jump.getAltitude() / A));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showRandomSplatMessage() {
|
||||||
switch (random.nextInt(10)) {
|
switch (random.nextInt(10)) {
|
||||||
case 0:
|
case 0:
|
||||||
System.out.println("REQUIESCAT IN PACE.");
|
System.out.println("REQUIESCAT IN PACE.");
|
||||||
@@ -155,36 +189,6 @@ public class Splat {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean chosen = false;
|
|
||||||
while (!chosen) {
|
|
||||||
System.out.print("DO YOU WANT TO PLAY AGAIN ");
|
|
||||||
String Z = scanner.next();
|
|
||||||
if (Z.equals("YES")) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (Z.equals("NO")) {
|
|
||||||
System.out.print("PLEASE ");
|
|
||||||
while (true) {
|
|
||||||
Z = scanner.next();
|
|
||||||
if (Z.equals("YES")) {
|
|
||||||
chosen = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (Z.equals("NO")) {
|
|
||||||
System.out.println("SSSSSSSSSS.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
System.out.print("YES OR NO ");
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
System.out.print("YES OR NO ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private InitialJumpConditions buildInitialConditions() {
|
private InitialJumpConditions buildInitialConditions() {
|
||||||
System.out.print("\n\n");
|
System.out.print("\n\n");
|
||||||
@@ -243,6 +247,7 @@ public class Splat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Immutable
|
||||||
static class InitialJumpConditions {
|
static class InitialJumpConditions {
|
||||||
private final float originalTerminalVelocity;
|
private final float originalTerminalVelocity;
|
||||||
private final float originalGravitationalAcceleration;
|
private final float originalGravitationalAcceleration;
|
||||||
|
|||||||
Reference in New Issue
Block a user