private bool SnakeTouchesWall()
        {
            LaserPositionAndColors snakeHeadPosition = _snake.SnakePositions.Last();

            return(snakeHeadPosition.X >= _settings.maxRight || snakeHeadPosition.X <= _settings.maxLeft ||
                   snakeHeadPosition.Y >= _settings.maxHeight || snakeHeadPosition.Y <= _settings.minHeight);
        }
        private bool SnakeTouchesDot()
        {
            LaserPositionAndColors snakeHeadPosition = _snake.SnakePositions.Last();

            return(snakeHeadPosition.Y >= _dot.RightWallPosition.FirstPosition.Y &&
                   snakeHeadPosition.Y <= _dot.RightWallPosition.SecondPosition.Y &&
                   snakeHeadPosition.X >= _dot.BottomWallPosition.FirstPosition.X &&
                   snakeHeadPosition.X <= _dot.BottomWallPosition.SecondPosition.X);
        }
        private bool SnakeTouchesHimself()
        {
            LaserPositionAndColors snakeHeadPosition = _snake.SnakePositions.Last();

            foreach (var snakeBodyPosition in _snake.SnakePositions.GetRange(0, _snake.SnakePositions.Count - 1))
            {
                if (snakeHeadPosition.Y == snakeBodyPosition.Y && snakeHeadPosition.X == snakeBodyPosition.X)
                {
                    return(true);
                }
            }

            return(false);
        }
        private void DrawSnake()
        {
            for (int i = 0; i < _snake.SnakePositions.Count; i++)
            {
                LaserPositionAndColors snakePositionAndColors = _snake.SnakePositions[i];

                _laser.SendTo(snakePositionAndColors.X, snakePositionAndColors.Y);
                if (i == 0)
                {
                    System.Threading.Thread.SpinWait(30000);
                }
                _laser.On(snakePositionAndColors.LaserColors);
            }

            _laser.Off();
        }
예제 #5
0
        public void Project(PatternOptions options)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            AnimationSpeed animationSpeed = options.AnimationSpeed;
            int            iterations     = 0;

            var random = new Random(Guid.NewGuid().GetHashCode());
            List <LaserPositionAndColors> laserPosAndColors = GetPredifinedLaserPositionAndColors();

            int previousColorChange = 0;

            bool xToLeft = false;
            bool yUp     = false;

            while (stopwatch.ElapsedMilliseconds < options.DurationMilliseconds || iterations < options.Total * 100)
            {
                iterations++;

                LaserPositionAndColors lastLaserPositionAndColors = laserPosAndColors.Last();
                int x = lastLaserPositionAndColors.X;
                int y = lastLaserPositionAndColors.Y;

                if (xToLeft)
                {
                    x -= random.Next(-10 / (int)animationSpeed, (int)animationSpeed * 3 + 15);
                }
                else
                {
                    x += random.Next(-10 / (int)animationSpeed, (int)animationSpeed * 3 + 15);
                }

                if (yUp)
                {
                    y += random.Next(-10 / (int)animationSpeed, (int)animationSpeed * 3 + 15);
                }
                else
                {
                    y -= random.Next(-10 / (int)animationSpeed, (int)animationSpeed * 3 + 15);
                }

                if (x >= _settings.maxRight && !xToLeft)
                {
                    xToLeft = true;
                }
                else if (x <= _settings.maxLeft && xToLeft)
                {
                    xToLeft = false;
                }

                if (y >= _settings.maxHeight && yUp)
                {
                    yUp = false;
                }
                else if (y <= _settings.minHeight && !yUp)
                {
                    yUp = true;
                }

                var color = lastLaserPositionAndColors.LaserColors;
                if (iterations - previousColorChange > 25)
                {
                    previousColorChange = iterations;
                    color = _laserPatternHelper.GetRandomLaserColors();
                }

                laserPosAndColors.Add(new LaserPositionAndColors
                {
                    LaserColors = color,
                    Y           = y,
                    X           = x
                });

                foreach (var laserposAndColor in laserPosAndColors)
                {
                    _laser.SendTo(laserposAndColor.X, laserposAndColor.Y);
                    _laser.On(laserposAndColor.LaserColors);
                }

                if (laserPosAndColors.Count > 100 - (int)animationSpeed)
                {
                    laserPosAndColors.RemoveRange(0, 1);
                }
            }

            _laser.Off();
        }