From 9131d0e2fd9a3894373775df084b5bdf395b6012 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Wed, 1 Jul 2020 14:29:00 +0200 Subject: [PATCH] Simplify FoodFactory#generateFood --- src/main/dev/lh/FoodFactory.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/dev/lh/FoodFactory.java b/src/main/dev/lh/FoodFactory.java index 3376b3c..ae8691a 100755 --- a/src/main/dev/lh/FoodFactory.java +++ b/src/main/dev/lh/FoodFactory.java @@ -76,8 +76,7 @@ public class FoodFactory { * @since Snake 1.0 */ public Food generateFood() { - int n = new Random().nextInt(Food.values().length + 1); - nextFood = n == Food.values().length ? generateFood() : Food.values()[n]; + nextFood = Food.values()[new Random().nextInt(Food.values().length)]; rectangleSize = nextFood.ordinal() + 2; setTimeToNextFoodMillis(); return nextFood;