Example #1
0
        private void Loop(object obj)
        {
            if (_walls.IsHitBySnake(_snake.GetHead()) || _snake.IsHitYourSelf(_snake.GetHead()))
            {
                _timer.Change(0, Timeout.Infinite);
            }
            else if (_snake.Eat(_foodFactory.Food))
            {
                _foodFactory.CreateFood();
            }
            else
            {
                _snake.Move();
            }

            return;
        }
Example #2
0
        private void Loop(object obj)
        {
            if (_walls.IsHitBySnake(_snake.GetHead()) || _snake.IsHitYourSelf(_snake.GetHead()))
            {
                _timer.Dispose();

                PrintLose();
            }
            else if (_snake.Eat(_foodFactory.Food))
            {
                _foodFactory.CreateFood();
            }
            else
            {
                if (_snake.CountFruit == 10)
                {
                    PrintWin();
                }
                else
                {
                    _snake.Move();
                }
            }
        }