Added tryChance method to MathUtilities

This commit is contained in:
Treeku
2014-06-16 10:40:45 +01:00
parent 2f547870ac
commit cdf8c96c94
+22
View File
@@ -22,6 +22,7 @@
package resources.common;
import java.math.BigDecimal;
import java.util.Random;
import engine.resources.scene.*;
@@ -68,4 +69,25 @@ public class MathUtilities {
BigDecimal dec = new BigDecimal(seconds);
return dec.remainder(new BigDecimal(3600)).divide(new BigDecimal(60), BigDecimal.ROUND_FLOOR).intValue();
}
public static boolean tryChance(int chance) {
if (chance <= 0) {
return false;
}
if (chance >= 100) {
return true;
}
chance = (100 - chance);
Random random = new Random();
if (random.nextInt(chance + 1) == 1) {
return true;
}
return false;
}
}