Dr Java Code problem?

I am supposed to write a basic Tic Tac Toe game with Dr Java. I came up with code, but the professor isn't telling me what the problem is...?

{

System.out.println("Invalid marker, try again");

}

}

markerOk = false;

while (!markerOk) {

System.out.print("Select any letter as " + game.getPlayer2() + "'s marker: ");

String marker = game.getPrompt();

if (marker.length() == 1 &&

Character.isLetter(marker.toCharArray()[0]))

{

markerOk = true;

game.setMarker2(marker.toCharArray()[0]);

}

else

{

System.out.println("Invalid marker, try again");

}

}

boolean continuePlaying = true;

while (continuePlaying) {

game.init();

System.out.println();

System.out.println(game.getRules());

System.out.println();

System.out.println(game.drawBoard());

System.out.println();

String player = null;

while (!game.winner() && game.getPlays() < 9) {

player = game.getCurrentPlayer() == 1 ? game.getPlayer1() : game.getPlayer2();

boolean validPick = false;

while (!validPick) {

System.out.print("It is " + player + "'s turn. Pick a square: ");

String square = game.getPrompt();

if (square.length() == 1 && Character.isDigit(square.toCharArray()[0])) {

int pick = 0;

try {

pick = Integer.parseInt(square);

} catch (NumberFormatException e) {

//Do nothing here, it'll evaluate as an invalid pick on the next row.

}

validPick = game.placeMarker(pick);

}

if (!validPick) {

System.out.println("Square can not be selected. Retry");

}

}

game.switchPlayers();

System.out.println();

System.out.println(game.drawBoard());

System.out.println();

}

if (game.winner()) {

System.out.println("Game Over - " + player + " WINS!!!");

} else {

System.out.println("Game Over - Draw");

}

System.out.println();

System.out.print("Play again? (Yes or No): ");

String choice = game.getPrompt();

if (!choice.equalsIgnoreCase("Yes")) {

continuePlaying = false;

}

}

}

public static void main(String[] args) {

Main main = new Main();

main.play();

}

}

Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Helpful Social

Copyright © 2024 QUIZLS.COM - All rights reserved.