示例#1
0
 protected virtual void OnFoodEatenEvent(Food source, EventArgs e)
 {
     if (OnFoodEaten != null)
     {
         OnFoodEaten(source, e);
     }
 }
示例#2
0
        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;
        }
示例#3
0
 void source_OnFoodEaten(Food source, EventArgs e)
 {
     OnSourceEatenEvent(EventArgs.Empty);
 }
示例#4
0
        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();
        }
示例#5
0
        private void removeFood(Food food)
        {
            int[] arrayLocation = food.getArrayLocation();
            foodGrid[arrayLocation[0],arrayLocation[1],arrayLocation[2]] = null;
            activeFood.Remove(food);

            OnFoodDeletionEvent(food, EventArgs.Empty);
        }
示例#6
0
 void food_OnFoodEaten(Food source, EventArgs e)
 {
     //When a food is eaten. Remove it and replace it with a new one.
     removeFood(source);
     //addFood();
 }
示例#7
0
        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);
        }
示例#8
0
 protected virtual void OnFoodDeletionEvent(Food source, EventArgs e)
 {
     if (OnFoodDeletion != null)
     {
         OnFoodDeletion(source, e);
     }
 }