Cant figure out where went wrong.
Hi, i somehow completed my codes but the codes get mixed up. Sometime it wont switch to next player or the desire result wont come out. Well take a look at part of my codes and hope someone could figure out for me.
Code:
// player 1
while (playerTurn == true) {
System.out.print("Player 1 :");
generateRandom();
for (int j = 0; j < wordGame.length; j++) {
System.out.print(wordGame[j] + " ");
}
System.out.println();
System.out
.println("Enter your World ( or Press @ to PASS or Press ! To Quit )");
inputs = scan.next();
playerInput = inputs.toCharArray();
// *****************************************************************************************************************
// Exiting the game
if (inputs.equals("!")) {
System.out.println("Player 1 score: " + player1);
System.out.println("Player 2 score: " + player2);
if (player1 > player2) {
System.out.println("player 1 won the game");
} else if (player1 == player2) {
System.out.println("Its a draw");
} else
System.out.println("Player 2 won the game");
System.exit(0);
}
// *****************************************************************************************************************
// Passing the game
else if (inputs.equals("@")) {
//System.out.println("Total score for word [Player 1]: 0");
//System.out.println("Total score for game: " + player1);
player1 += 0;
playerTurn = false;
}
// *****************************************************************************************************************
// Inputs for game
else if (inRandom(inputs, wordGame)) {
if (inDict(inputs, dict)) {
pointAssign();
System.out.println(playerInput);
System.out.println("Total score for word : " + points);
player1 += points;
System.out.println("Total score for game : " + player1);
points = 0;
playerTurn = false;
} else {
System.out.println("Error :An invalid word is formed.");
System.out
.println("Enter your World ( or Press @ to PASS or Press ! To Quit )");
playerInput = null;
inputs = scan.next();
playerInput = inputs.toCharArray();
System.out.println("");
}
} else if (inDict(inputs, dict) && !inRandom(inputs, wordGame)) {
System.out
.println("Error : A valid word is formed but one or more letter(s) used are not yours ");
System.out
.println("Enter your World ( or Press @ to PASS or Press ! To Quit )");
playerInput = null;
inputs = scan.next();
playerInput = inputs.toCharArray();
} else if (!inDict(inputs, dict) && !inRandom(inputs, wordGame)) {
System.out
.println("Error : one or more letter(s) used are not yours ");
System.out
.println("Enter your World ( or Press @ to PASS or Press ! To Quit )");
playerInput = null;
inputs = scan.next();
playerInput = inputs.toCharArray();
}
// *****************************************************************************************************************
// Player 2 turn
while (playerTurn == false) {
generateRandom();
System.out.print("Player 2 :");
for (int k = 0; k < wordGame.length; k++) {
System.out.print(wordGame[k] + " ");
}
System.out.println();
System.out
.println("Enter your World ( or Press @ to PASS or Press ! To Quit )");
inputs = scan.next();
playerInput = inputs.toCharArray();
// *****************************************************************************************************************
// Exiting the game for player2
if (inputs.equals("!")) {
System.out.println("Player 1 score: " + player1);
System.out.println("Player 2 score: " + player2);
if (player1 > player2) {
System.out.println("player 1 won the game");
} else if (player1 == player2) {
System.out.println("Its a draw");
} else
System.out.println("Player 2 won the game");
System.exit(0);
}
// *****************************************************************************************************************
// Passing the game for player2
else if (inputs.equals("@")) {
//System.out.println("Total score for word[Player 2]: 0");
//System.out.println("Total score for game: " + player2);
player2 += 0;
playerTurn = true;
}
// *****************************************************************************************************************
// Inputs for game for player2
else if (inRandom(inputs, wordGame)) {
if (inDict(inputs, dict)) {
pointAssign();
System.out.println(playerInput);
System.out.println("Total score for word : " + points);
player2 += points;
System.out.println("Total score for game : " + player2);
points = 0;
playerTurn = true;
} else {
System.out.println("Error :An invalid word is formed.");
System.out
.println("Enter your World ( or Press @ to PASS or Press ! To Quit )");
playerInput = null;
inputs = scan.next();
playerInput = inputs.toCharArray();
System.out.println("");
}
} else if (inDict(inputs, dict) && !inRandom(inputs, wordGame)) {
System.out
.println("Error : A valid word is formed but one or more letter(s) used are not yours ");
System.out
.println("Enter your World ( or Press @ to PASS or Press ! To Quit )");
playerInput = null;
inputs = scan.next();
playerInput = inputs.toCharArray();
} else if (!inDict(inputs, dict) && !inRandom(inputs, wordGame)) {
System.out
.println("Error : one or more letter(s) used are not yours ");
System.out
.println("Enter your World ( or Press @ to PASS or Press ! To Quit )");
playerInput = null;
inputs = scan.next();
playerInput = inputs.toCharArray();
}
}
seriously need these help