okay, so I'm working on a boardgame. The first 'while loop' checks if the game is over, the inner 'while loop' is supposed to wait for the user input (squareSelector and rooSelector are my mouselisteners, 'k' and 's' are the input that are supposed to be returned by the listeners) However the 'while loop' crashes my program and blocking my listeners from working. I read up about this and found out that swing is single threaded and so my listeners can't work while the whileloop is active. However I need to wait for the input in order to avoid nullpointers. Any ideas on how to solve this ? (as in a different approach, or how to make my loop wait for the input)
the gameloop
while(currentPlayer.haveIWon() == false){
//wait for input
while(!inputIsDone){
System.out.println("waiting for move");
System.out.println(squareSelector.isDone() + " " + rooSelector.isDone()) ;
checkInput() ;
if(squareSelector.isDone() && rooSelector.isDone()){
inputIsDone = true ;
}
}
//update board
currentPlayer.performMove(k, s);
rooSelector.setDone(false);
squareSelector.setDone(false);
inputIsDone = false ;
//currentPlayer.setInput(false);
//repaint
Main.getState().getComponent().repaint();
}
//display winnner thing
the checkInput method
public void checkInput(){
if(rooSelector.getSelected() != null){
k = rooSelector.getSelected() ;
}
if(squareSelector.getSelected() != null){
s = squareSelector.getSelected() ;
}
}
If you need more code to understand what's going on let me know and I will add more.