I'm making a multi-player game where each player has their own input/output console on the screen. I'm having a bit of trouble trying to do this. I don't want every player to see other player's in/outputs.
To use an analogy, I want to do something like playerOneConsole.out.println("Player One String");, instead of System.out.println("Player One String"); where everyone can see player one's stuff.
After reading some documentation, I've tried this, but it does not work as intended as it throws a NullPointerException:
public class Player {
String myName;
Console myConsole;
public Player(String name) {
myName = name;
myConsole = System.console();
}
public void takeTurn(String playerOptions){
myConsole.writer().print(playerOptions); //This is not right.
}
}
I want playerOptions to print exclusively to that player's console, not the System console.
By the way, I'm using NetBeans IDE 8.0.2 if that makes a difference.
myConsoleisnull, because you're running in an environment whereSystem.console()returnsnull, e.g. in Eclipse?