Пример #1
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(120, 120);

            Walls walls = new Walls(80, 25);

            walls.Draw();

            Point p = new Point(1, 3, 'O');

            /*p1.x = 1;
             * p1.y = 3;
             * p1.sym = '*';*/
            Snake snake = new Snake(p, 4, Direction.RIGHT);

            snake.Draw();

            Score score = new Score(75, 1);

            score.UpdateScore();

            FoodCreator foodCreator = new FoodCreator(70, 25, '#');
            Point       food        = foodCreator.CreateFood();

            food.Draw(ConsoleColor.Green);

            FoodCreator badfoodCreator = new FoodCreator(50, 10, '¤');
            Point       badfood        = badfoodCreator.CreateFood();

            badfood.Draw(ConsoleColor.Red);


            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    Score.score += 5;
                    score.UpdateScore();
                    food = foodCreator.CreateFood();
                    food.Draw(ConsoleColor.Green);
                }
                if (snake.NOEat(badfood))
                {
                    Score.score -= 5;
                    score.UpdateScore();
                    badfood = badfoodCreator.CreateFood();
                    badfood.Draw(ConsoleColor.Red);
                }
                if (Score.score <= -1)
                {
                    Console.Clear();
                    Console.SetCursorPosition(50, 10);
                    Console.Write("Game Over");
                }
                else
                {
                    snake.Move();
                }
                Thread.Sleep(100);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
            Console.SetCursorPosition(50, 10);
            Console.Write("Game Over");
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(85, 35);

            Walls walls = new Walls(80, 25);

            walls.Draw();

            Point p     = new Point(4, 5, '#');
            Snake snake = new Snake(p, 4, Direction.RIGHT);

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(80, 25, '#', '0', '+');
            Point       food        = foodCreator.CreateFood();
            Point       Sfood       = foodCreator.CreateFoodS();
            Point       Bfood       = foodCreator.CreateFoodB();

            food.Draw();

            Parametrs settings = new Parametrs();
            Sounds    sound    = new Sounds(settings.GetResourceFolder());

            sound.Play();
            Sounds sound1 = new Sounds(settings.GetResourceFolder());
            Sounds soundS = new Sounds(settings.GetResourceFolder());
            Sounds soundB = new Sounds(settings.GetResourceFolder());
            Score  score  = new Score(settings.GetResourceFolder());

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    Console.Beep(300, 500);
                    Thread.Sleep(50);
                    Console.Beep(300, 500);
                    Thread.Sleep(50);
                    Console.Beep(300, 500);
                    Thread.Sleep(50);
                    Console.Beep(250, 500);
                    Thread.Sleep(50);
                    Console.Beep(350, 250);
                    Console.Beep(300, 500);
                    Thread.Sleep(50);
                    Console.Beep(250, 500);
                    Thread.Sleep(50);
                    Console.Beep(350, 250);
                    Console.Beep(300, 500);
                    Thread.Sleep(50);
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                    sound1.PlayEat();
                    score.UpCurrentPoints();
                    score.ShowCurrentPoints();
                    if (score.ShowPoint() % 50 == 0)
                    {
                        Sfood = foodCreator.CreateFoodS();
                        Sfood.Draw();
                        Bfood = foodCreator.CreateFoodB();
                        Bfood.Draw();
                    }
                }
                if (snake.Eat(Sfood))
                {
                    score.UpPoinS();
                    score.ShowCurrentPoints();
                    soundS.PlayEatS();
                }
                if (snake.Eat(Bfood))
                {
                    score.DownPointB();
                    score.ShowCurrentPoints();
                    soundB.PlayEatB();
                }
                else
                {
                    snake.Move();
                }
                Thread.Sleep(200);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
            score.WriteGameOver();
        }