java - Android: Random number decides players' turn -


i want create random integer between 1 , 2 (for player1 , player2). if it's 1, player 1 should win first move, , if it's 2, player 2 should win first move. tried this, it's not working:

random generator = new random(); int rand = generator.nextint(2) + 1;  if(rand == 1){     player1 = true;     player2 = false;     toast.maketext(getapplicationcontext(), playeronename + " won first move!", toast.length_short); } else {     player1 = false;     player2 = true;     toast.maketext(getapplicationcontext(), playertwoname + " won first move!", toast.length_short); } 

it doesn't give errors, nothing happens. it's player 1 takes first move, , toast doesn't appear!

first notice toast command not complete, , should be:

 toast.maketext(getapplicationcontext(), playeronename + " won first move!", toast.length_short).show(); 

then you'll have better on what's


Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -