Example #1
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);

            Walls walls = new Walls(80, 25);

            walls.Draw();

            //Отрисовка точек
            Point p     = new Point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.RIGHT);

            snake.Drow();

            FoodCreator foodCreator = new FoodCreator(80, 25, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();


            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }

                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }
                Thread.Sleep(100);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.SetCursorPosition(33, 11);
            Console.WriteLine("GAME OVER");
            Console.SetCursorPosition(33, 12);
            Console.WriteLine("Thanks for Watching");
            Console.SetCursorPosition(33, 13);
            Console.WriteLine("Maks EMS production with GeekBrains");
            Console.SetCursorPosition(33, 14);
            Console.WriteLine("Press Enter for exit");
            Console.ReadLine();
        }
Example #2
0
        static void Main(string[] args)
        {
            Console.WindowWidth  = 85;
            Console.WindowHeight = 25;
            Console.SetBufferSize(85, 25);
            Console.CursorVisible = false;

            Walls walls = new Walls(85, 25);

            walls.Draw();

            Point p = new Point(4, 5, '*');

            Snake snake = new Snake(p, 3, Direction.RIGHT);

            snake.Draw();

            Food  newFood = new Food(85, 25, '$');
            Point food    = newFood.Create();

            food.Draw();

            while (true)
            {
                if (walls.Hit(snake) || snake.HitTail())
                {
                    break;
                }

                if (snake.Eat(food))
                {
                    food = newFood.Create();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }
                Thread.Sleep(150);

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

            Console.Clear();
            walls.Draw();

            Console.SetCursorPosition(37, 12);
            Console.WriteLine("You Lose!");

            Console.ReadKey();
        }
Example #3
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(88, 25);

            //Отрисовка стен - рамочки
            Walls walls = new Walls(88, 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, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            //Управление змейкой
            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail()) //если змейка натолкнулась на препятствие или хвост, то гейм овер
                {
                    break;
                }
                if (snake.Eat(food)) // если змейка поела, то создаем новую еду, иначе змейка двигается дальше
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else //иначе - двигаемся дальше
                {
                    snake.Move();
                }

                Thread.Sleep(100);

                if (Console.KeyAvailable)                   // была ли нажата какая-либо клавиша
                {
                    ConsoleKeyInfo key = Console.ReadKey(); // получаем значение нажатой клавиши
                    snake.HandleKey(key.Key);               // изменяем направление змейки
                }
            }

            //Чтобы не отображался курсор
            Console.CursorVisible = false;
        }
Example #4
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(mapWidth, mapHeight);
            Console.SetBufferSize(mapWidth, mapHeight);

            Walls walls = new Walls(mapWidth, mapHeight);

            walls.Draw();

            Snake snake = new Snake(new Point(50, 20, '*'), 6, Direction.RIGHT);

            snake.Draw();

            FoodCreatot foodCreatot = new FoodCreatot(mapWidth, mapHeight, '&', '%', '$', '#');
            Point       food        = foodCreatot.CreateFood();

            food.Draw();

            while (true)
            {
                if (walls.Collision(snake) || snake.TailCollision())
                {
                    Console.Beep();
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreatot.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }

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

                Thread.Sleep(100);
            }
            Console.Clear();
            Console.SetCursorPosition((mapWidth / 2) - 4, mapHeight / 2);
            Console.WriteLine(" GAME OVER ");
            Console.ReadKey();
        }
Example #5
0
        static void Main(string[] args)
        {
            // создаем границы консоли Arkasha
            Console.SetBufferSize(80, 25);

            Walls walls = new Walls(80, 25);

            walls.Draw();


            //отрисовка точек
            Point p     = new Point(10, 10, '*');
            Snake snake = new Snake(p, 3, Direction.RIGHT);

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(80, 25, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
            WriteGameOver();
            Console.ReadLine();
        }
Example #6
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(80, 25);
            Console.SetBufferSize(80, 25);
            Console.CursorVisible = false;

            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, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
        }
Example #7
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80,25); //установить размер окна и убрать возможность перемотки

            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, '$');
            Point food = foodCreator.CreateFood();
            food.Draw();

            while(true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    Console.Clear();
                    Console.SetCursorPosition(37, 7);
                    Console.Write("YOU LOSE");
                    break;
                }
                if(snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);

                if (Console.KeyAvailable) //нажата ли какая-либо клавиша
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }

            Console.ReadKey();
        }
Example #8
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(1, 1);
            Console.SetBufferSize(80, 25);
            Console.SetWindowSize(80, 25);

            HorisontalLine upline    = new HorisontalLine(0, 78, 0, '+');
            VerticalLine   rigthline = new VerticalLine(0, 0, 24, '+');
            HorisontalLine downline  = new HorisontalLine(0, 78, 24, '+');
            VerticalLine   leftline  = new VerticalLine(78, 0, 24, '+');

            upline.Draw();
            rigthline.Draw();
            downline.Draw();
            leftline.Draw();

            Point p     = new Point(4, 5, '*');
            Snake snake = new Snake(p, 3, Direction.RIGTH);

            snake.Draw();

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

            food.Drow();

            while (true)
            {
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Drow();
                }
                else
                {
                    snake.Move();
                }
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.directionOfMovement(key.Key);
                }
                Thread.Sleep(300);
                snake.Move();
            }
        }
Example #9
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(120, 30);

            Walls walls = new Walls(120, 30);

            walls.Draw();


            //Отрисовка точек
            point p     = new point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.right);

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(120, 30, '$');
            point       food        = foodCreator.CreateFood();

            food.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }
                Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
            WriteGameOver();
            Console.ReadLine();
        }
Example #10
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(120, 30);

            Wall walls = new Wall(120, 30);

            walls.Draw();

            Point p     = new Point(50, 10, '*');
            Snake snake = new Snake(p, 4, Direction.left);

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(120, 30, 'o');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }


                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key);
                }
                Thread.Sleep(400);
                snake.Move();
            }
        }
Example #11
0
        public static void Main(string[] args)
        {
            // Отрисовка рамочки
            HorizontalLine upLine    = new HorizontalLine(0, 150, 0, '+');
            HorizontalLine downLine  = new HorizontalLine(0, 150, 15, '+');
            VerticalLine   leftLine  = new VerticalLine(0, 15, 0, '+');
            VerticalLine   rightLine = new VerticalLine(0, 15, 150, '+');
//            upLine.Draw();
//            downLine.Draw();
//            leftLine.Draw();
//            rightLine.Draw();

            // Отрисовка точек
            Point p     = new Point(5, 4, '*');
            Snake snake = new Snake(p, 3, Direction.RIGHT);

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(80, 25, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            while (true)
            {
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
        }
Example #12
0
        static void Main(string[] args)
        {
            // Console.SetBufferSize(60, 20);

            Walls walls = new Walls(60, 20);

            walls.Draw();

            //отрисовка точек
            Point p     = new Point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.Right);

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(60, 20, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                else if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }
                Thread.Sleep(150);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
        }
Example #13
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);
            HorizontalLine upLine = new HorizontalLine(0,78,0,'+');
            HorizontalLine downLine = new HorizontalLine(0, 78, 24, '+');
            VerticalLine leftLine = new VerticalLine(0, 24, 0, '+');
            VerticalLine rightLine = new VerticalLine(0, 24, 78, '+');

            upLine.Draw();
            downLine.Draw();
            leftLine.Draw();
            rightLine.Draw();

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

            FoodCreator foodCreator = new FoodCreator(80, 25, '$');
            Point food = foodCreator.CreateFood();
            food.Draw();

            while (true)
            {
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }

                //if (Console.KeyAvailable)
                //{
                //    ConsoleKeyInfo key = Console.ReadKey();
                //    snake.HandleKey(key.Key);
                //}
                Thread.Sleep(300);
                //snake.Move();
            }
        }
Example #14
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);

            Walls walls = new Walls(80, 25);
            walls.Drow();

            //Отрисовка точек
            Point p = new Point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.RIGHT);
            snake.Drow();

            FoodCreator foodCreator = new FoodCreator(80, 25, '$');
            Point food = foodCreator.CreateFood();
            food.Drow();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Drow();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
        }
Example #15
0
        static void Main(string[] args)
        {
            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 foodcreat = new FoodCreator(80, 25, '&');
            Point       food      = foodcreat.CreateFood();

            food.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodcreat.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.Go(key.Key);
                }
                Thread.Sleep(100);
                snake.Move();
            }
        }
Example #16
0
        static void Main(string[] args)
        {
            int choise;
            int mode;
            int speed;

menu:
            Console.Clear();
            Console.WriteLine("\t$ ЗМЕЙКА ВОЛКОВА $\t telegram автора: serega_vlk\n\n");
            Console.WriteLine("1. играть");
            Console.WriteLine("2. выход");
            choise = Convert.ToInt32(Console.ReadLine());
            if (choise == 1)
            {
menu1:
                Console.Clear();
                Console.WriteLine("\t$ ЗМЕЙКА ВОЛКОВА $\t telegram автора: serega_vlk\n\n");
                Console.WriteLine("Выберите сложность\n");
                Console.WriteLine("1. Тренировка");
                Console.WriteLine("2. Арена");
                Console.WriteLine("3. Назад");
                choise = Convert.ToInt32(Console.ReadLine());
                if (choise == 1)
                {
                    Console.Clear();
                    mode = 1;
                }
                else if (choise == 2)
                {
                    Console.Clear();
                    mode = 2;
                }
                else if (choise == 3)
                {
                    Console.Clear();
                    goto menu;
                }
                else
                {
                    Console.Clear();
                    goto menu1;
                }
menu2:
                Console.Clear();
                Console.WriteLine("\t$ ЗМЕЙКА ВОЛКОВА $\t telegram автора: serega_vlk\n\n");
                Console.WriteLine("Выберите скорость\n");
                Console.WriteLine("1. Легкая - 130");
                Console.WriteLine("2. Средняя - 100");
                Console.WriteLine("3. Сложная - 70");
                Console.WriteLine("4. Хардкор - 40");
                Console.WriteLine("5. Назад");
                choise = Convert.ToInt32(Console.ReadLine());
                if (choise == 1)
                {
                    Console.Clear();
                    speed = 130;
                    goto start;
                }
                else if (choise == 2)
                {
                    Console.Clear();
                    speed = 100;
                    goto start;
                }
                else if (choise == 3)
                {
                    Console.Clear();
                    speed = 70;
                    goto start;
                }
                else if (choise == 4)
                {
                    Console.Clear();
                    speed = 40;
                    goto start;
                }
                else if (choise == 5)
                {
                    Console.Clear();
                    goto menu1;
                }
                else
                {
                    Console.Clear();
                    goto menu2;
                }
            }
            else if (choise == 2)
            {
                return;
            }
            else
            {
                Console.Clear();
                goto menu;
            }
start:
            int weight = 80;
            int  height = 25;
            Wall frames = new Wall(weight, height);

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

            snake.Draw();

            FoodCreator foodcreator = new FoodCreator(weight, height, '%');
            Point       food        = foodcreator.CreateFood();

            food.Draw();

            Console.SetCursorPosition(90, 0);
            Console.Write("Для выхода нажмите esc");
            Console.SetCursorPosition(90, 2);
            Console.Write("Сложность: " + mode);
            Console.SetCursorPosition(90, 3);
            Console.Write("Скорость: " + speed);

            int  counter = 0;
            bool check   = true;

            while (true)
            {
                if (snake.SnakeLenght() && check && mode == 2)
                {
                    weight = weight - 4;
                    height = height - 1;
                    Console.Clear();
                    foodcreator = new FoodCreator(weight - 5, height - 2, '%');
                    frames      = new Wall(weight, height);
                    frames.Draw();
                    food.Draw();
                    snake.Draw();
                    Console.SetCursorPosition(90, 0);
                    Console.Write("Для выхода нажмите esc");
                    Console.SetCursorPosition(90, 2);
                    Console.Write("Сложность: " + mode);
                    Console.SetCursorPosition(90, 3);
                    Console.Write("Скорость: " + speed);
                    check = false;
                }
                if (frames.IsHit(snake) || snake.IsHitTail())
                {
                    Console.SetCursorPosition(90, 15);
                    Console.Write("Вы проиграли(((");
                    Console.SetCursorPosition(90, 17);
                    Console.Write("Ваш счет: " + Convert.ToString(counter));
                    Console.SetCursorPosition(90, 19);
                    Console.Write("Нажмите esc для выхода в меню");
                    while (true)
                    {
                        ConsoleKeyInfo key1 = Console.ReadKey();
                        if (key1.Key == ConsoleKey.Escape)
                        {
                            break;
                        }
                    }
                    goto menu;
                }
                if (snake.Eat(food))
                {
                    counter++;
                    while (true)
                    {
                        food = foodcreator.CreateFood();
                        if (snake.IsHitPoint(food))
                        {
                            continue;
                        }
                        else
                        {
                            break;
                        }
                    }
                    food.Draw();
                    check = true;
                }
                else
                {
                    snake.Move();
                }
                Thread.Sleep(speed);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    if (key.Key == ConsoleKey.LeftArrow)
                    {
                        snake.direction = Direction.LEFT;
                    }
                    else if (key.Key == ConsoleKey.RightArrow)
                    {
                        snake.direction = Direction.RIGHT;
                    }
                    else if (key.Key == ConsoleKey.UpArrow)
                    {
                        snake.direction = Direction.UP;
                    }
                    else if (key.Key == ConsoleKey.DownArrow)
                    {
                        snake.direction = Direction.DOWN;
                    }
                    else if (key.Key == ConsoleKey.Escape)
                    {
                        Console.Clear();
                        Console.SetCursorPosition(0, 0);
                        goto menu;
                    }
                }
            }
        }
Example #17
0
        public static void PlayGame()
        {
            while (true)
            {
                if (direction == 1)
                {
                    snake.Move(-1, 0);
                }
                if (direction == 2)
                {
                    snake.Move(1, 0);
                }
                if (direction == 3)
                {
                    snake.Move(0, -1);
                }
                if (direction == 4)
                {
                    snake.Move(0, 1);
                }

                Console.SetCursorPosition(0, 0);
                Console.WriteLine("High score : " + " " + points + "   Score: " + score + " " + "Level" + " " + level);
                Console.SetCursorPosition(0, 1);
                Console.WriteLine("If you want to save current score, enter [Probel]");
                Console.SetCursorPosition(0, 2);
                Console.WriteLine("If you want to quit, enter [Escape] ");


                if (snake.CollisionWithWall(wall) || snake.Collision())
                {
                    Console.Clear();
                    Console.SetCursorPosition(7, 7);
                    StreamReader sr = new StreamReader(@"C:\Users\Compag\Desktop\PP-2\week5\SnakeGame\Snake\gameover.txt");
                    string       s  = sr.ReadToEnd();
                    Console.WriteLine(s);
                    Console.WriteLine("High Score : " + " " + points + "Your Score is " + score);

                    Console.ReadKey();

                    Console.Clear();
                    speed = 400;
                    snake = new Snake();
                    level = 1;
                    wall  = new Wall(level);
                    score = 0;

                    while (!food.foodonwall(wall) || !food.foononsnake(snake))
                    {
                        food.SetRandomPos();
                        Console.SetCursorPosition(food.x, food.y);
                        Console.Write("$");
                    }
                }

                if (snake.Eat(food))
                {
                    snake.AddBody();
                    food.SetRandomPos();
                    score += 10;
                    points = Math.Max(points, score);
                    Console.SetCursorPosition(food.x, food.y);
                    Console.Write("$");

                    while (!food.foodonwall(wall) || !food.foononsnake(snake))
                    {
                        food.SetRandomPos();
                        Console.SetCursorPosition(food.x, food.y);
                        Console.Write("$");
                    }
                }
                if (score == level * 50)
                {
                    Console.Clear();
                    level++;
                    wall = new Wall(level);

                    speed = Math.Max(1, speed - 100);

                    while (!food.foodonwall(wall) || !food.foononsnake(snake))
                    {
                        food.SetRandomPos();
                        Console.SetCursorPosition(food.x, food.y);
                        Console.Write("$");
                    }
                }
                // Console.Clear();
                snake.Draw();
                food.ShowFood();
                wall.WallDraw();
                Thread.Sleep(speed);
            }
        }
Example #18
0
        static void Main(string[] args)
        {
            //Установим размер окна консоли
            Console.SetWindowSize(105, 30);

            //Ограждение игрового поля
            HorizontalLine horizontalLine = new HorizontalLine(0, 100, 0, '*');

            horizontalLine.Draw();

            HorizontalLine horizontalLine2 = new HorizontalLine(0, 100, 24, '*');

            horizontalLine2.Draw();


            VerticalLine verticalLine = new VerticalLine(0, 24, 0, '*');

            verticalLine.Draw();

            VerticalLine verticalLine2 = new VerticalLine(0, 24, 100, '*');

            verticalLine2.Draw();

            //Cоздаём змею
            //точка её хвоста
            Point tail = new Point(2, 2, 'x');
            //змея длиной 3, ползёт вправо
            Snake snake = new Snake(tail, 10, Direction.right);

            snake.Draw();

            Food food = new Food(100, 24, 'o');

            food.MakeFood(ref snake.coordinats);

            //движение и управление змейкой
            while (true)
            {
                //Проверяем не закончилась ли игра если змея столкнулась с самой собой или оградой поля
                if (snake.Collision())
                {
                    break;
                }

                //Проверяем съела ли змея фрукт, если да генерим новый
                if (snake.Eat(food))
                {
                    food.MakeFood(ref snake.coordinats);
                    snake.Draw();
                }

                //Смотрим нажатия клавиш пользователем
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    //Вызываем метод управления направлением змеи из класса Snake
                    snake.SnakeControl(key.Key);
                }
                //Движение змеи
                snake.Move();
                Thread.Sleep(300);
            }
        }
Example #19
0
 protected override void Update(GameTime gameTime)
 {
     if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || ((Keyboard.GetState().IsKeyDown(Keys.Escape)) && (gamestate == Gamestate.Mainmenu)))
     {
         Exit();
     }
     if ((gamestate == Gamestate.Mainmenu) && (Mouse.GetState().X > 877) && (Mouse.GetState().X < 1101) && (Mouse.GetState().Y > 425) && (Mouse.GetState().Y < 479) && (Mouse.GetState().LeftButton == ButtonState.Pressed))
     {
         Exit();
     }
     if ((Mouse.GetState().X > 877) && (Mouse.GetState().X < 1101) && (Mouse.GetState().Y > 250) && (Mouse.GetState().Y < 301) && (Mouse.GetState().LeftButton == ButtonState.Pressed))
     {
         gamestate = Gamestate.Game;
     }
     base.Update(gameTime);
     if (gamestate == Gamestate.Game)
     {
         Snake.Move(speed);
         Snake.Eat();
         Apple.Spawn();
         Snake.Loop();
         Snake.Rip();
         if (Upmenu.Paused())
         {
             gamestate = Gamestate.Pausemenu;
         }
         if ((Keyboard.GetState().IsKeyDown(Keys.Escape)) && (!Pausemenu.IsEscPressedGame))
         {
             gamestate = Gamestate.Pausemenu;
             Pausemenu.IsEscPressed = true;
         }
         if (Keyboard.GetState().IsKeyUp(Keys.Escape))
         {
             Pausemenu.IsEscPressedGame = false;
         }
     }
     if ((Snake.Rip()) && (gamestate == Gamestate.Game))
     {
         gamestate = Gamestate.Rip;
     }
     if (gamestate == Gamestate.Rip)
     {
         if (Ripmenu.Buttons() == "new")
         {
             Random random = new Random();
             gamestate = Gamestate.Game;
             Snake.turns.Clear();
             Snake.bodies.Clear();
             Head.X         = random.Next(300, 600);
             Head.Y         = random.Next(100, 620);
             Head.Direction = Direction.Right;
             Snake.Length   = 1;
             Snake.bodies.Add(new Body());
             Snake.bodies[0].X         = Head.X - 64;
             Snake.bodies[0].Y         = Head.Y;
             Snake.bodies[0].Direction = Head.Direction;
             Apple.IsEaten             = true;
             Snake.Add();
             Upmenu.Score = 0;
         }
         if (Ripmenu.Buttons() == "exit")
         {
             Exit();
         }
     }
     if (gamestate == Gamestate.Pausemenu)
     {
         if (Pausemenu.Buttons() == "continue")
         {
             gamestate = Gamestate.Game;
         }
         if (Pausemenu.Buttons() == "new")
         {
             Random random = new Random();
             gamestate = Gamestate.Game;
             Snake.turns.Clear();
             Snake.bodies.Clear();
             Head.X         = random.Next(300, 600);
             Head.Y         = random.Next(100, 620);
             Head.Direction = Direction.Right;
             Snake.Length   = 1;
             Snake.bodies.Add(new Body());
             Snake.bodies[0].X         = Head.X - 64;
             Snake.bodies[0].Y         = Head.Y;
             Snake.bodies[0].Direction = Head.Direction;
             Apple.IsEaten             = true;
             Snake.Add();
             Upmenu.Score = 0;
         }
         if (Pausemenu.Buttons() == "exit")
         {
             Exit();
         }
         if (Keyboard.GetState().IsKeyUp(Keys.Escape))
         {
             Pausemenu.IsEscPressed = false;
         }
     }
 }