Simplify FoodFactory#generateFood
This commit is contained in:
parent
c7035ff2c5
commit
9131d0e2fd
@ -76,8 +76,7 @@ public class FoodFactory {
|
|||||||
* @since Snake 1.0
|
* @since Snake 1.0
|
||||||
*/
|
*/
|
||||||
public Food generateFood() {
|
public Food generateFood() {
|
||||||
int n = new Random().nextInt(Food.values().length + 1);
|
nextFood = Food.values()[new Random().nextInt(Food.values().length)];
|
||||||
nextFood = n == Food.values().length ? generateFood() : Food.values()[n];
|
|
||||||
rectangleSize = nextFood.ordinal() + 2;
|
rectangleSize = nextFood.ordinal() + 2;
|
||||||
setTimeToNextFoodMillis();
|
setTimeToNextFoodMillis();
|
||||||
return nextFood;
|
return nextFood;
|
||||||
|
Loading…
Reference in New Issue
Block a user