Пример #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
        static void Main(string[] args)
        {
            Menu menu = new Menu();

            ConsoleKey click = Console.ReadKey().Key;

            if (click == ConsoleKey.Enter)
            {
                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();

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

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

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

            else if (click == ConsoleKey.I)
            {
                Console.Clear();
                Rules rules = new Rules();
            }

            else if (click == ConsoleKey.Escape)
            {
                Environment.Exit(0);
            }
        }
Пример #3
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();
        }
Пример #4
0
        static void Main(string[] args)

        {
            LineInstaller line = new LineInstaller();

            line.DrawShapes();

            Point point = FoodFactory.GetRandomFood(119, 20, '+');

            Console.ForegroundColor = ColorHelper.GetRandomColor(new Random().Next(1, 5));
            point.DrawPoint();
            Console.ResetColor();
        }