private static Food createRandomFood(int width, int height) { int x = Rnd.Next(width); int y = Rnd.Next(height); Food food = null; if (staticFood) { food = new Food(x, y); } else { double speed = Rnd.Next() * 2; double direction = Rnd.Next() * 2 * Math.PI; food = new MovingFood(x, y, direction, speed); } return(food); }
private void InitializeMovingFood() { var movingFoods = new List <MovingFood>(); var movingFoodCount = BaseConstants.MovingFoodCount; for (int i = 0; i < movingFoodCount; i++) { int size = BaseConstants.SquareSize; int x = random.Next(BaseConstants.MaxX - size); int y = random.Next(BaseConstants.MaxY - size); Position pos = new Position(x, y); var isOver = IsFoodOverObstacle(pos, size); if (!isOver) { MovingFood movingFood = new MovingFood(pos, size, BaseConstants.MovingFoodsSpeed); movingFoods.Add(movingFood); } else { i--; } } this.MovingFoods = movingFoods; }