Exemple #1
0
        public void SpawnFood()
        {
            foodTimer.Stop();

            //remove food
            if (CurrentFood != null)
            {
                if (Board[CurrentFood.Position.X, CurrentFood.Position.Y] == FoodService.GetBoardValue(CurrentFood.Id))
                {
                    Board[CurrentFood.Position.X, CurrentFood.Position.Y] = 0;
                    drawArea.DrawSquare(CurrentFood.Position, "Background");
                }
                CurrentFood = null;
            }

            //pick position
            Point randomPosition;

            do
            {
                randomPosition = new Point(random.Next(1, BoardSizeX - 2), random.Next(1, BoardSizeY - 2));
            } while (Board[randomPosition.X, randomPosition.Y] != 0); //we need an empty tile

            //spawn food, place it on board, draw it
            CurrentFood = FoodService.NewFood(FoodService.RandomId(), randomPosition);

            Board[CurrentFood.Position.X, CurrentFood.Position.Y] = FoodService.GetBoardValue(CurrentFood.Id);

            drawArea.DrawFood(CurrentFood);

            //set up timer
            foodTimer.Interval = CurrentFood.LifeSpan;
            foodTimer.Start();
        }
Exemple #2
0
        private void EatCurrentFood(ushort FoodBoardValue, Point position)
        {
            Food CurrentFoodFake = FoodService.NewFood(FoodBoardValue, position);

            toGrow     += CurrentFoodFake.Nutrition;
            ScoreToAdd += CurrentFoodFake.Nutrition * 100;
        }