示例#1
0
        private static bool Update()
        {
            _snake.Direction = _input.GetNewDirection();
            var oldTail = _snake.Tail;

            _snake.Move();

            if (_snake.GetBody().Skip(1).Any(n => Equals(n, _snake.Head)))
            {
                return(true);
            }
            if (!_area.AllFields.Contains((_snake.Head.X, _snake.Head.Y)))
            {
                return(true);
            }

            if (IsPositionEqual(_snake.Head, _food))
            {
                _area.Score++;
                _area.PrintScore();
                _snake.Grow(oldTail);
                _food.SpawnNew(_area, _snake);
                _renderer.Redraw(_snake.Head);
            }
            else
            {
                _renderer.Redraw(_snake.Head, oldTail);
            }

            _renderer.Draw(_food);
            return(false);
        }
示例#2
0
        private void aTimer_Tick(object sender, EventArgs e)
        {
            if (snake.Dieded())
            {
                aTimer.Stop();
                aTimeModeTimer.Enabled = false;
                EnableMenu(true);
            }
            else
            {
                snake.DoMove();

                //eat
                if (snake.head.Bounds.IntersectsWith(food.foodLocator))
                {
                    SoundPlayer eat = new SoundPlayer(Properties.Resources.Eat1);
                    eat.Play();
                    food = new Food(this, aSuperFood, aFood, snake);
                    snake.Grow();
                }

                if (Controls.Contains(aSuperFood))
                {
                    foodTime++;
                }
                if (foodTime >= 30)
                {
                    foodTime = 0;
                    Controls.Remove(aSuperFood);
                    food.superFoodLocator = new Rectangle();
                }

                if (snake.head.Bounds.IntersectsWith(food.superFoodLocator))
                {
                    SoundPlayer superEat = new SoundPlayer(Properties.Resources.Eat2);
                    superEat.Play();

                    Controls.Remove(aSuperFood);
                    food.superFoodLocator = new Rectangle();
                    foodTime = 0;
                    snake.Grow();
                    snake.Grow();
                    snake.Grow();
                }
            }
            directionChanged = false;
        }