mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-21 23:00:43 -08:00
Game now works
This commit is contained in:
@@ -49,27 +49,32 @@ public class Cube {
|
|||||||
if(readParsedBoolean()) {
|
if(readParsedBoolean()) {
|
||||||
out.println("HOW MUCH?");
|
out.println("HOW MUCH?");
|
||||||
do {
|
do {
|
||||||
wager = scanner.nextInt();
|
wager = Integer.parseInt(scanner.nextLine());
|
||||||
if(wager > money) {
|
if(wager > money) {
|
||||||
out.println("TRIED TO FOOL ME; BET AGAIN");
|
out.println("TRIED TO FOOL ME; BET AGAIN");
|
||||||
}
|
}
|
||||||
} while(wager > money);
|
} while(wager > money);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
playerLocation = new Location(1,1,1);
|
||||||
while(playerLocation.x + playerLocation.y + playerLocation.z != 9) {
|
while(playerLocation.x + playerLocation.y + playerLocation.z != 9) {
|
||||||
out.println("\nNEXT MOVE");
|
out.println("\nNEXT MOVE");
|
||||||
String input = scanner.nextLine();
|
String input = scanner.nextLine();
|
||||||
|
|
||||||
String[] stringValues = input.split(",");
|
String[] stringValues = input.split(",");
|
||||||
|
|
||||||
|
if(stringValues.length < 3) {
|
||||||
|
out.println("ILLEGAL MOVE, YOU LOSE.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int x = Integer.parseInt(stringValues[0]);
|
int x = Integer.parseInt(stringValues[0]);
|
||||||
int y = Integer.parseInt(stringValues[1]);
|
int y = Integer.parseInt(stringValues[1]);
|
||||||
int z = Integer.parseInt(stringValues[2]);
|
int z = Integer.parseInt(stringValues[2]);
|
||||||
|
|
||||||
Location location = new Location(x,y,z);
|
Location location = new Location(x,y,z);
|
||||||
|
|
||||||
if(x < 1 || x > 3 || y < 1 || y > 3 || z < 1 || z > 3 || isMoveValid(playerLocation,location)) {
|
if(x < 1 || x > 3 || y < 1 || y > 3 || z < 1 || z > 3 || !isMoveValid(playerLocation,location)) {
|
||||||
out.println("ILLEGAL MOVE, YOU LOSE.");
|
out.println("ILLEGAL MOVE, YOU LOSE.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -80,9 +85,18 @@ public class Cube {
|
|||||||
out.println("******BANG******");
|
out.println("******BANG******");
|
||||||
out.println("YOU LOSE!\n\n");
|
out.println("YOU LOSE!\n\n");
|
||||||
money -= wager;
|
money -= wager;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while(money > 0 && !doAnotherRound());
|
|
||||||
|
if(wager > 0) {
|
||||||
|
out.printf("YOU NOW HAVE %d DOLLARS\n",money);
|
||||||
|
}
|
||||||
|
|
||||||
|
} while(money > 0 && doAnotherRound());
|
||||||
|
|
||||||
|
out.println("TOUGH LUCK!");
|
||||||
|
out.println("\nGOODBYE.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean doAnotherRound() {
|
private boolean doAnotherRound() {
|
||||||
@@ -121,7 +135,11 @@ public class Cube {
|
|||||||
|
|
||||||
private boolean readParsedBoolean() {
|
private boolean readParsedBoolean() {
|
||||||
String in = scanner.nextLine();
|
String in = scanner.nextLine();
|
||||||
return in.toLowerCase().charAt(0) == 'y' || Boolean.parseBoolean(in);
|
try {
|
||||||
|
return in.toLowerCase().charAt(0) == 'y' || Boolean.parseBoolean(in) || Integer.parseInt(in) == 1;
|
||||||
|
} catch(NumberFormatException exception) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isMoveValid(Location from, Location to) {
|
private boolean isMoveValid(Location from, Location to) {
|
||||||
|
|||||||
Reference in New Issue
Block a user