Ive created a network game. I am having issues with (seemingly) unexplainable errors. Note that the cards are added by to the ArrayList upon mouse clicks, and this class is run on its own thread.
private void waitForAction(){
tb.report("Waiting for user to make a move...");
selectedCards = new ArrayList<Card>();
while(selectedCards.size() < 2){
if(selectedCards.size() == 2)//Wtf is going on here...?
tb.report("This loop is (not) broken.");
else
tb.report("Looping..");
};
tb.report("This player has selected 2 cards.");
}
When I remove the else statement, the loop never exits, which is proven to me by the print(report()) methods. I had the same issue in earlier development, but it was corrected by adding the if part of the if-else statement. I am honestly baffled, logical reasoning tells me that JVM is not checking the condition because the thread is not running, however throughout the program I only ever call Thread's start() once, otherwise its untouched by my code. Any wiser sole's opinion would be much appreciated.
Aucun commentaire:
Enregistrer un commentaire