I have searched many topics for my problem, read a lot... but they were not exactly as mine.
I'm getting the "Unreachable Code" compilation error from Eclipse IDE.
I don't understand why my code is unreachable! It is simple though! Here it is...
public String doAction(int action, Player P1, Player P2) {
switch(action) {
case 'a':
case 'A':
CriticalChance = ThreadLocalRandom.current() .nextInt(CritMin,CritMax+1);
if(CriticalChance <= 5) {
int temp = ThreadLocalRandom.current().nextInt(31,50+1);
P1.setAttack(temp);
} else {
P2.deductHp(P1.newNormalAttack());
}
if(CriticalChance <= 5) {
String temp = String.format("CRITICAL STRIKE! "+P1.getName()+" did "+P1.getAttack()+" damage to "+P2.getName()+"\n");
return temp;
} else {
String temp = String.format(P1.getName()+" did "+P1.getAttack()+" damage to "+P2.getName()+"\n");
return temp;
}
if(P2.getHp() > 0) {
String temp = String.format(P2.getName()+"'s Remaining HP is "+P2.getHp()+"\n");
return temp;
} else {
String temp = String.format(P2.getName()+" Bled To Death!!\n");
return temp;
}
break;
}
}
Please Help! If you need more info, plz tell me.