mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-23 07:29:02 -08:00
Match Formatting to Original Program
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.lang.management.PlatformLoggingMXBean;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class Roulette {
|
public class Roulette {
|
||||||
@@ -35,135 +35,143 @@ public class Roulette {
|
|||||||
out.println(" ROULETTE");
|
out.println(" ROULETTE");
|
||||||
out.println(" CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
|
out.println(" CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
|
||||||
out.println("WELCOME TO THE ROULETTE TABLE\n");
|
out.println("WELCOME TO THE ROULETTE TABLE\n");
|
||||||
out.println("DO YOU WANT INSTRUCTIONS");
|
out.print("DO YOU WANT INSTRUCTIONS? ");
|
||||||
if(scanner.nextLine().toLowerCase().charAt(0) != 'n') {
|
if(scanner.nextLine().toLowerCase().charAt(0) != 'n') {
|
||||||
printInstructions();
|
printInstructions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
Bet[] bets = queryBets();
|
Bet[] bets = queryBets();
|
||||||
|
|
||||||
out.println("SPINNING...\n\n\n");
|
out.print("SPINNING...\n\n");
|
||||||
int result = random.nextInt(1,39);
|
int result = random.nextInt(1,39);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Equivalent to following line
|
Equivalent to following line
|
||||||
if(RED_NUMBERS.contains(result)) {
|
if(result == 37) {
|
||||||
|
out.println("00");
|
||||||
|
} else if(result == 38) {
|
||||||
|
out.println("0");
|
||||||
|
} else if(RED_NUMBERS.contains(result)) {
|
||||||
out.println(result + " RED");
|
out.println(result + " RED");
|
||||||
} else {
|
} else {
|
||||||
out.println(result + " BLACK");
|
out.println(result + " BLACK");
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
switch(result) {
|
out.println(switch(result) {
|
||||||
case 37 -> out.print("00");
|
case 37 -> "00";
|
||||||
case 38 -> out.print("0");
|
case 38 -> "0";
|
||||||
default -> out.println(result + (RED_NUMBERS.contains(result) ? " RED\n" : " BLACK\n"));
|
default -> result + (RED_NUMBERS.contains(result) ? " RED" : " BLACK");
|
||||||
}
|
});
|
||||||
|
|
||||||
betResults(bets,result);
|
betResults(bets,result);
|
||||||
out.println();
|
out.println();
|
||||||
|
|
||||||
out.println("TOTALS:\tME\tYOU");
|
out.println("TOTALS:\tME\t\tYOU");
|
||||||
out.println("\t\t" + houseBalance + "\t" + playerBalance);
|
out.format("\t\t%5d\t%d\n",houseBalance,playerBalance);
|
||||||
|
|
||||||
} while(playAgain());
|
} while(playAgain());
|
||||||
if(playerBalance <= 0) {
|
if(playerBalance <= 0) {
|
||||||
out.println("THANKS FOR YOUR MONEY\nI'LL USE IT TO BUY A SOLID GOLD ROULETTE WHEEL");
|
out.println("THANKS FOR YOUR MONEY\nI'LL USE IT TO BUY A SOLID GOLD ROULETTE WHEEL");
|
||||||
} else if(houseBalance <= 0) {
|
} else {
|
||||||
out.println("TO WHOM SHALL I MAKE THE CHECK");
|
printCheck();
|
||||||
String name = scanner.nextLine();
|
|
||||||
out.println();
|
|
||||||
for(int i = 0; i < 72; i++) {
|
|
||||||
out.print("-");
|
|
||||||
}
|
|
||||||
out.println();
|
|
||||||
for(int i = 0; i < 50; i++) {
|
|
||||||
out.print(" ");
|
|
||||||
}
|
|
||||||
out.println("CHECK NO. " + random.nextInt(0,1000));
|
|
||||||
out.println();
|
|
||||||
for(int i = 0; i < 40; i++) {
|
|
||||||
out.print(" ");
|
|
||||||
}
|
|
||||||
out.println(LocalDateTime.now());
|
|
||||||
out.println("\n");
|
|
||||||
out.println("PAY TO THE ORDER OF----- " + name + "------$" + (playerBalance - 1000));
|
|
||||||
out.println("\n");
|
|
||||||
for(int i = 0; i < 10; i++) {
|
|
||||||
out.print(" ");
|
|
||||||
}
|
|
||||||
out.println("THE MEMORY BANK OF NEW YORK");
|
|
||||||
for(int i = 0; i < 40; i++) {
|
|
||||||
out.print(" ");
|
|
||||||
}
|
|
||||||
out.println("THE COMPUTER");
|
|
||||||
for(int i = 0; i < 40; i++) {
|
|
||||||
out.print(" ");
|
|
||||||
}
|
|
||||||
out.println("----------X-----");
|
|
||||||
for(int i = 0; i < 72; i++) {
|
|
||||||
out.print("-");
|
|
||||||
}
|
|
||||||
out.println("\n");
|
|
||||||
out.println("COME BACK SOON");
|
|
||||||
}
|
}
|
||||||
|
out.println("COME BACK SOON!");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printCheck() {
|
||||||
|
out.print("TO WHOM SHALL I MAKE THE CHECK? ");
|
||||||
|
String name = scanner.nextLine();
|
||||||
|
|
||||||
|
out.println();
|
||||||
|
for(int i = 0; i < 72; i++) {
|
||||||
|
out.print("-");
|
||||||
|
}
|
||||||
|
out.println();
|
||||||
|
|
||||||
|
for(int i = 0; i < 50; i++) {
|
||||||
|
out.print(" ");
|
||||||
|
}
|
||||||
|
out.println("CHECK NO. " + random.nextInt(0,100));
|
||||||
|
|
||||||
|
for(int i = 0; i< 40; i++) {
|
||||||
|
out.print(" ");
|
||||||
|
}
|
||||||
|
out.println(LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||||
|
out.println();
|
||||||
|
|
||||||
|
out.println("PAY TO THE ORDER OF -----" + name + "----- $" + (playerBalance));
|
||||||
|
out.println();
|
||||||
|
|
||||||
|
for(int i = 0; i < 40; i++) {
|
||||||
|
out.print(" ");
|
||||||
|
}
|
||||||
|
out.println("THE MEMORY BANK OF NEW YORK");
|
||||||
|
|
||||||
|
for(int i = 0; i < 40; i++) {
|
||||||
|
out.print(" ");
|
||||||
|
}
|
||||||
|
out.println("THE COMPUTER");
|
||||||
|
|
||||||
|
for(int i = 0; i < 40; i++) {
|
||||||
|
out.print(" ");
|
||||||
|
}
|
||||||
|
out.println("----------X-----");
|
||||||
|
|
||||||
|
for(int i = 0; i < 72; i++) {
|
||||||
|
out.print("-");
|
||||||
|
}
|
||||||
|
out.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean playAgain() {
|
private boolean playAgain() {
|
||||||
if(playerBalance > 0) {
|
|
||||||
if(houseBalance <= 0) {
|
if(playerBalance <= 0) {
|
||||||
out.println("YOU BROKE THE HOUSE!");
|
out.println("OOPS! YOU JUST SPENT YOUR LAST DOLLAR!");
|
||||||
//using default values
|
return false;
|
||||||
playerBalance = 101000;
|
} else if(houseBalance <= 0) {
|
||||||
}
|
out.println("YOU BROKE THE HOUSE!");
|
||||||
|
playerBalance = 10100;
|
||||||
|
houseBalance = 0;
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
out.println("PLAY AGAIN?");
|
out.println("PLAY AGAIN?");
|
||||||
return scanner.nextLine().toLowerCase().charAt(0) == 'y';
|
return scanner.nextLine().toLowerCase().charAt(0) == 'y';
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Bet[] queryBets() {
|
private Bet[] queryBets() {
|
||||||
int numBets = -1;
|
int numBets = -1;
|
||||||
while(numBets < 1) {
|
while(numBets < 1) {
|
||||||
out.println("HOW MANY BETS");
|
out.print("HOW MANY BETS? ");
|
||||||
try {
|
try {
|
||||||
numBets = Integer.parseInt(scanner.nextLine());
|
numBets = Integer.parseInt(scanner.nextLine());
|
||||||
} catch(NumberFormatException exception) {
|
} catch(NumberFormatException ignored) {}
|
||||||
out.println("THAT IS NOT A NUMBER");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Bet[] bets = new Bet[numBets];
|
Bet[] bets = new Bet[numBets];
|
||||||
|
|
||||||
for(int i = 0; i < numBets; i++) {
|
for(int i = 0; i < numBets; i++) {
|
||||||
try {
|
while(bets[i] == null) {
|
||||||
out.println("BET NUMBER " + (i + 1) + ":");
|
try {
|
||||||
String[] values = scanner.nextLine().split(",");
|
out.print("NUMBER" + (i + 1) + "? ");
|
||||||
int betNumber = Integer.parseInt(values[0]);
|
String[] values = scanner.nextLine().split(",");
|
||||||
int betValue = Integer.parseInt(values[1]);
|
int betNumber = Integer.parseInt(values[0]);
|
||||||
|
int betValue = Integer.parseInt(values[1]);
|
||||||
|
|
||||||
for(int j = 0; j < i; j++) {
|
for(int j = 0; j < i; j++) {
|
||||||
if(bets[j].num == betNumber) {
|
if(bets[j].num == betNumber) {
|
||||||
out.println("YOU MADE THAT BET ONCE ALREADY,DUM-DUM");
|
out.println("YOU MADE THAT BET ONCE ALREADY,DUM-DUM");
|
||||||
throw new Exception();
|
betNumber = -1; //Since -1 is out of the range, this will throw it out at the end
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(betNumber < 1 || betNumber > 50 || betValue < 5 || betValue > 500) {
|
if(betNumber > 0 && betNumber <= 50 && betValue >= 5 && betValue <= 500) {
|
||||||
out.println("INVALID VALUE, TRY AGAIN");
|
bets[i] = new Bet(betValue,betNumber);
|
||||||
i--;
|
}
|
||||||
continue;
|
} catch(Exception ignored) {}
|
||||||
}
|
|
||||||
|
|
||||||
bets[i] = new Bet(betNumber,betValue);
|
|
||||||
|
|
||||||
} catch(Exception exception) {
|
|
||||||
if(exception instanceof NumberFormatException) {
|
|
||||||
out.println("SYNTAX ERROR, TRY AGAIN");
|
|
||||||
}
|
|
||||||
i--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bets;
|
return bets;
|
||||||
|
|||||||
Reference in New Issue
Block a user