So I'm trying to code UNO in Java, and I'm still trying to generate cards. I'm not too sure what the problem here is, but for some reason, my code catches an error inside my methods. I've checked my code a few times already and it isn't a syntax error, so I legitimately don't know what's going on with it.
I've temporarily stopped coding this for now so that I won't create any more errors before you guys tell me what's wrong, to make it easier to modify it. Please tell me what I did wrong!
public class JavaUNO {
public static void main(String[] args) throws Exception {
boolean inProgress = false;
boolean drawCard = false;
String[][] playerDeck = {{}};
byte playerDeckLength = 0;
// MAIN OUTPUT
try {
// INITIALIZATION
Scanner scan = new Scanner(System.in);
// PROGRAM STARTING PROMPT
System.out.println("> Deck:");
// **PLAYER DECK INIT**
try {
System.out.println("> Cards Generated:");
while (playerDeckLength < 7) {
// **CARD GENERATION**
try {
// INITIALIZATION
double randType = Math.random();
double randColor = Math.random();
playerDeck[playerDeckLength][0] = "";
playerDeck[playerDeckLength][1] = "";
// GENERATES RANDOM CARD TYPE
if (randType < 0.066) {
playerDeck[playerDeckLength][0] = "0";
} else if (randType < 0.132) {
playerDeck[playerDeckLength][0] = "1";
} else if (randType < 0.198) {
playerDeck[playerDeckLength][0] = "2";
} else if (randType < 0.264) {
playerDeck[playerDeckLength][0] = "3";
} else if (randType < 0.33) {
playerDeck[playerDeckLength][0] = "4";
} else if (randType < 0.396) {
playerDeck[playerDeckLength][0] = "5";
} else if (randType < 0.462) {
playerDeck[playerDeckLength][0] = "6";
} else if (randType < 0.528) {
playerDeck[playerDeckLength][0] = "7";
} else if (randType < 0.594) {
playerDeck[playerDeckLength][0] = "8";
} else if (randType < 0.66) {
playerDeck[playerDeckLength][0] = "9";
} else if (randType < 0.726) {
playerDeck[playerDeckLength][0] = "Reverse Cycle";
} else if (randType < 0.792) {
playerDeck[playerDeckLength][0] = "+2 Cards";
} else if (randType < 0.858) {
playerDeck[playerDeckLength][0] = "+4 Cards";
} else if (randType < 0.924) {
playerDeck[playerDeckLength][0] = "Skip Turn";
} else if (randType < 1) {
playerDeck[playerDeckLength][0] = "Color Change";
}
//GENERATES RANDOM CARD COLOR
if (randColor < 0.25) {
playerDeck[playerDeckLength][1] = "Blue";
} else if (randColor < 0.5) {
playerDeck[playerDeckLength][1] = "Yellow";
} else if (randColor < 0.75) {
playerDeck[playerDeckLength][1] = "Red";
} else if (randColor < 1) {
playerDeck[playerDeckLength][1] = "Green";
}
//CHECKS IF CARD IS WILDCARD
if (playerDeck[playerDeckLength][0] == "+4 Cards") {
playerDeck[playerDeckLength][1] = "Wildcard";
} else if (playerDeck[playerDeckLength][0] == "+2 Cards") {
playerDeck[playerDeckLength][1] = "Wildcard";
} else if (playerDeck[playerDeckLength][0] == "Color Change") {
playerDeck[playerDeckLength][1] = "Wildcard";
}
playerDeckLength += 1;
} catch (Exception e) {
System.out.println("");
System.out.println("> An uncaught error occured!");
System.out.println("> Location: Card Generation");
}
System.out.println("Type: " + playerDeck[playerDeckLength][0] + "; Color: " +
playerDeck[playerDeckLength][1]);
}
} catch (Exception e) {
System.out.println("");
System.out.println("> An uncaught error occured!");
System.out.println("> Location: Player Deck Init");
}
} catch (Exception e) {
System.out.println("");
System.out.println("> An uncaught error occured!");
System.out.println("> Location: Main Output");
}
}
}
COMMAND PROMPT:
> Deck:
> Cards Generated:
> An uncaught error occurred!
> Location: Card Generation
> An uncaught error occurred!
> Location: Player Deck Init