示例#1
0
        public void StartGame(User user)
        {
            if (user == null)
            {
                user = new User();
            }

            int score = 0;

            var lineInstallers = new LineInstaller();

            lineInstallers.DrawShapes();

            var food = FoodFactory.GetRandomFood(70, 20, '+');

            Console.ForegroundColor = ColorHelper.GetRandomColor(new Random().Next(1, 4));
            food.DrawPoint();
            Console.ResetColor();

            var snake = new Snake();

            snake.CreateSnake(5, new Point(5, 5, '8'), Enums.DirectionEnum.Right);
            snake.DrawLine();

            ScoreHelper.GetScore(score);

            while (true)
            {
                if (lineInstallers.Collision(snake) || snake.CollisionOnTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    score++;
                    ScoreHelper.GetScore(score);


                    food = FoodFactory.GetRandomFood(70, 20, '+');
                    Console.ForegroundColor = ColorHelper.GetRandomColor(new Random().Next(1, 4));
                    food.DrawPoint();
                    Console.ResetColor();
                }

                Thread.Sleep(100);
                snake.Move();

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.PressKey(key.Key);
                }
            }

            user.Score = score;
            userService.SaveScore(user);
        }
示例#2
0
        public void Start()
        {
            // if (user == null)
            // user = new User();

            int score = 0;

            Console.Clear();
            LineInstaller line = new LineInstaller();

            line.DrawShapes();
            Point food = FoodFactory.GetRandomFood(119, 20, '+');

            Console.ForegroundColor = ColorHelper.GetRandomColor(new Random().Next(1, 5));
            food.DrawPoint();
            Console.ResetColor();
            Snake snake = new Snake();

            snake.CreateSnake(5, new Point(5, 5, 'z'), DirectionEnum.Right);
            snake.DrawLine();

            ScoreHelper.GetScore(score);
            while (true)
            {
                if (line.Collision(snake) || snake.CollisionWithOwnTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    score++;
                    ScoreHelper.GetScore(score);

                    food = FoodFactory.GetRandomFood(119, 20, '+');
                    Console.ForegroundColor = ColorHelper.GetRandomColor(new Random().Next(1, 5));
                    food.DrawPoint();
                    Console.ResetColor();
                }

                Thread.Sleep(_levelSelect);
                snake.Move();

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.PressKey(key.Key);
                }
            }

            Concede();
            Console.ReadKey();
        }