protected virtual void OnFoodEatenEvent(Food source, EventArgs e) { if (OnFoodEaten != null) { OnFoodEaten(source, e); } }
public FoodVisual(Food source, Ellipse food) { this.source = source; this.food = food; food.Dispatcher.Invoke(new Action(() => food.Height = Food.getSize())); food.Dispatcher.Invoke(new Action(() => food.Width = Food.getSize())); food.Dispatcher.Invoke(new Action(() => food.Fill = new SolidColorBrush(Colors.LightGreen))); source.OnFoodEaten += source_OnFoodEaten; }
void source_OnFoodEaten(Food source, EventArgs e) { OnSourceEatenEvent(EventArgs.Empty); }
void MainWindow_OnFoodAddition(Food source, EventArgs e) { FoodVisual visual = null; Dispatcher.Invoke(new Action(() => visual = new FoodVisual(source, new Ellipse()))); foodVisuals.Add(visual); Dispatcher.Invoke(new Action(() => canvas.Children.Add(visual.getVisual()))); visual.OnSourceEaten += visual_OnSourceEaten; visual.update(); }
private void removeFood(Food food) { int[] arrayLocation = food.getArrayLocation(); foodGrid[arrayLocation[0],arrayLocation[1],arrayLocation[2]] = null; activeFood.Remove(food); OnFoodDeletionEvent(food, EventArgs.Empty); }
void food_OnFoodEaten(Food source, EventArgs e) { //When a food is eaten. Remove it and replace it with a new one. removeFood(source); //addFood(); }
private void addFood() { retry: Point position = new Point(ranGen.NextDouble() * world.getWorldSize().X, ranGen.NextDouble() * world.getWorldSize().Y); int[] arrayPosition = new int[3]; int[] xyPos = findGridCell(position); int zPos = 0; //Find an empty slot in the foodGrid Food arrayTest = null; while((arrayTest = foodGrid[xyPos[0],xyPos[1],zPos]) != null) { zPos++; if(zPos > arrayDepth) { goto retry; } } arrayPosition[0] = xyPos[0]; arrayPosition[1] = xyPos[1]; arrayPosition[2] = zPos; Food food = new Food(position, arrayPosition); foodGrid[arrayPosition[0], arrayPosition[1], arrayPosition[2]] = food; activeFood.Add(food); food.OnFoodEaten += food_OnFoodEaten; OnFoodAdditionEvent(food, EventArgs.Empty); }
protected virtual void OnFoodDeletionEvent(Food source, EventArgs e) { if (OnFoodDeletion != null) { OnFoodDeletion(source, e); } }