I have the following code for the user to pick a winner between four options. The variables p1, p2, p3 and p4 are determined by a compare method prior to being used here (the value is always between -3 and 3, 3 being a winner). The problem I'm having is that sometimes, and only sometimes a WINNING evaluation returns the toast for a TIE. I've include the variables in the toast message, only to make sure the correct value is being passed. All values are correct. So I'm at a loss. Can anyone give me any ideas why this might be happening? It seemed to be only happening when one player evaluated to 3, and another to -3. So I 'artificially' inflated all variables by 3, so that same scenario would then return a 6 and a 3. But the problem persists. The only thing I can think of is it may be a buffering, or cache issue. But all the variables are re-initialized to 0 on each pass by an onClick action. Please help. Thank you.
public void EvaluatePlayer1(View view) {
if(p1>=p2 && p1>=p3 && p1>=p4){
if(p1 == p2 || p1 == p3 || p1 == p4){
Toast.makeText(getApplicationContext(), p1 + " It's a tie.",
Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(), p1 + " You chose the winner!",
Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(getApplicationContext(), p1 + "You chose a loser!",
Toast.LENGTH_SHORT).show();
} }
Aucun commentaire:
Enregistrer un commentaire