Ejemplo n.º 1
0
        public void Run()
        {
            Console.SetWindowSize(SizeX + 1, SizeY + 1);
            Console.SetBufferSize(SizeX + 1, SizeY + 1);
            Console.CursorVisible = false;

            Console.ForegroundColor = ConsoleColor.Yellow;
            _walls = new Walls(SizeX, SizeY, WallsSymbol);
            Console.ResetColor();

            _foodFactory = new FoodFactory(SizeX, SizeY, FoodSymbol);
            _foodFactory.CreateFood();

            _snake = new Snake(SizeX / 2, SizeY / 2, SnakeSymbol, SnakeLength);

            // Каждые GameDelay секунд срабатывает метод Loop.
            _timer = new Timer(Loop, null, 0, GameDelay);

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey(true);
                    _snake.Rotation(key.Key);
                }
            }
        }
Ejemplo n.º 2
0
        public void GameResume()
        {
            FileStream snake_stream = new FileStream(@"C:\Users\User\Desktop\snake.xml", FileMode.Open, FileAccess.Read);
            FileStream walls_stream = new FileStream(@"C:\Users\User\Desktop\walls.xml", FileMode.Open, FileAccess.Read);
            FileStream food_stream  = new FileStream(@"C:\Users\User\Desktop\food.xml", FileMode.Open, FileAccess.Read);

            StreamReader sr = new StreamReader(@"C:\Users\User\Desktop\levelser.txt");


            XmlSerializer snake_xml = new XmlSerializer(typeof(Snake));
            XmlSerializer walls_xml = new XmlSerializer(typeof(Walls));
            XmlSerializer food_xml  = new XmlSerializer(typeof(Food));

            try
            {
                Game.snake = snake_xml.Deserialize(snake_stream) as Snake;
                int n = int.Parse(sr.ReadLine());
                Game.walls = new Walls(n);
                Game.walls = walls_xml.Deserialize(walls_stream) as Walls;
                Game.food  = food_xml.Deserialize(food_stream) as Food;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                sr.Close();
                snake_stream.Close();
                walls_stream.Close();
                food_stream.Close();
            }
        }
Ejemplo n.º 3
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())
                {
                    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);
                }
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            //Console.SetBufferSize(80,25);

            //Отрисовка рамки
            Walls walls = new Walls(80, 25);

            walls.Draw();

            /*
             * 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.Drow();
             * downLine.Drow();
             * leftLine.Drow();
             * rightLine.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.Draw();


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

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

                snake.Move();
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            int points = 0;

            //Установка размера окна консоли (блокировка изменения размера окна и прокрутки)
            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();

                    points++;
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }
                //скорость движения змейки
                if (points <= 25)
                {
                    Thread.Sleep(300 - (points * 10));
                }
                else
                {
                    Thread.Sleep(50);
                }

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
            WriteGameOver(points);
            Console.ReadLine();
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Console.Title = "Счет: 0";
            Console.SetWindowSize(101, 27);
            Walls w     = new Walls(100, 26);
            Snake snake = new Snake(10, 10, 'o', 7, Direction.RIGHT);

            snake.Draw();
            snake.Move();

            FoodCreator fc = new FoodCreator();

            while (true)
            {
                if (snake.CrashedIntoItself() || snake.CrashedIntoTheWall(w))
                {
                    break;
                }
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo keyInfo = Console.ReadKey();
                    snake.ChangeDirection(keyInfo);
                }
                if (snake.NextStepWithFood(fc.F))
                {
                    snake.Eat(fc.F);
                    fc = new FoodCreator();
                }

                Thread.Sleep(100);
                snake.Move();
            }
        }
Ejemplo n.º 7
0
        public void Menu()
        {
            Console.SetCursorPosition(30, 10);
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write("SNAKE THE GAME\n");
            Console.SetCursorPosition(24, 14);
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("Нажми Enter для начала игры");

            Console.ReadLine();

            Console.Clear();

            Walls walls = new Walls();

            walls.Draw();

            Console.SetCursorPosition(15, 10);
            Console.Write("Управление: единичное короткое нажатие на стрелки\n");
            Console.SetCursorPosition(27, 12);
            Console.Write("UP DOWN LEFT RIGHT\n");
            Console.SetCursorPosition(27, 16);
            Console.Write("Жми Enter и погнали!");
            Console.ReadLine();
            Console.Clear();

            walls.Draw();
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);
            Walls w = new Walls(80, 25);

            w.Draw();
            Snake       snake       = new Snake(new Point(2, 5, '*'), 4, Direction.DOWN);
            FoodCreator foodCreator = new FoodCreator(25, 80, '&');
            Point       food        = foodCreator.getFood();

            food.Draw();
            snake.Draw();
            while (true)
            {
                if (w.isStrike(snake) || snake.isStrike())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.getFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }
                if (Console.KeyAvailable)
                {
                    snake.keyHandler(Console.ReadKey().Key);
                }
                Thread.Sleep(200);
            }
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            Console.Write("Enter your name: ");
            string name = Console.ReadLine();

            Console.SetWindowSize(75, 25);

            Walls walls = new Walls(62, 25);

            walls.Draw();

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

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(62, 25, '$', ConsoleColor.Green);
            Point       food        = foodCreator.CreateFood();

            food.Draw();
            Score score = new Score(0, 1);            //score-0, level-1

            score.speed = 50;
            score.ScoreWrite();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    score.ScoreUp();
                    score.ScoreWrite();
                    food = foodCreator.CreateFood();
                    food.Draw();
                    if (score.ScoreUp())
                    {
                        score.speed -= 10;
                    }
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(score.speed);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
            WriteGameOver(name);
            Console.ReadLine();
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);

            Walls walls = new Walls(80, 25);

            walls.Draw();

            Point p     = new Point(1, 5, '*');
            Snake snake = new Snake(p, 20, Direktion.RIGHT);

            snake.Drow();

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

            food.Draw();

            while (true)
            {
                Thread.Sleep(100);

                if (Console.KeyAvailable && walls.IsHit(snake) == false)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HendleKey(key.Key);
                }

                if (snake.IsHitTail())
                {
                    break;
                }

                if (snake.Eat(food, -77, -23))
                {
                    food = foodCreator.CreateFood(snake);
                    food.Draw();
                }

                if (snake.Eat(food, 1, 1))
                {
                    food = foodCreator.CreateFood(snake);
                    food.Draw();
                }

                if (walls.IsHit(snake))
                {
                    snake.Move(-77, -23);
                    walls.Draw();
                }
                else
                {
                    snake.Move(1, 1);
                }
            }

            WriteGameOver();
            Console.ReadLine();
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            //Point FirstPoint = new Point(10, 5, '*');
            //FirstPoint.drawPoint();
            //Console.ReadLine();

            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();

            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.DrawPoint();


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

                Thread.Sleep(100);

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

            //Console.ReadLine();
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            // Рисуем границы
            Walls wall = new Walls(80, 25);

            wall.Draw();

            //рисуем змею
            Point p     = new Point(4, 5, '*');
            Snake snake = new Snake(p, 5, Direction.RIGHT);

            snake.Draw();

            //создаём еду
            FoodCreator foodCeator = new FoodCreator(78, 23, '$');
            Point       food       = foodCeator.CreateFood();

            food.Draw();

            while (true)
            {
                if (snake.crossingWall() || snake.crossingBody()) // проверка столкновения
                {
                    Console.Clear();
                    Console.WriteLine("Ты проиграл!");
                    Console.ReadLine();
                    break;
                }

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

                Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.iMoveTo(key.Key);
                }
            }
        }
        static void Main(string[] args)
        {
            int timeSleep = 100;

            Console.CursorVisible = false;

            Console.SetWindowSize(80, 25);
            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())
                {
                    break;
                }

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

                    timeSleep -= 15;

                    if (timeSleep < 1)
                    {
                        timeSleep = 10;
                    }
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(timeSleep);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }

            WriteGameOver();
            Console.ReadLine();
        }
Ejemplo n.º 14
0
 public void CreateObjects()
 {
     snake = new Snake();
     walls = new Walls();
     food  = new Food();
     walls.GenerateWalls(level);
     food.FoodGenerate();
 }
Ejemplo n.º 15
0
 public Game()
 {
     snake = new Snake();
     walls = new Walls();
     food  = new Food();
     walls.GenerateWalls();
     food.FoodGenerate();
 }
Ejemplo n.º 16
0
        public static void Main(string[] args)
        {
            // size of map
            int MaxMapWidth = 80;
            int MaxMapHeight = 25;

            Console.SetBufferSize(MaxMapWidth, MaxMapHeight);

            // drow frame
            Walls walls = new Walls(MaxMapWidth, MaxMapHeight);
            walls.Draw();

            // drow point draw snake

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

            // draw food

            FoodCreater foodCreator = new FoodCreater (MaxMapWidth, MaxMapHeight, '$');
            Point food = foodCreator.CreateFood ();
            //Console.ForegroundColor = ConsoleColor.Cyan;
            food.Draw ();

            while (true) {
                // data de perete
                if (walls.IsHit (snake) || snake.IsHitTail()) break;

                // daca maninca

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

                Thread.Sleep (200);

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

                    if (key.Key == ConsoleKey.Escape)
                        break;
                }

            }
            // END

            Console.ForegroundColor = ConsoleColor.Red;
            Console.SetCursorPosition(MaxMapWidth/3 , 10);
            Console.WriteLine ("--=***=--  E N D  --=***=--");
            Console.SetCursorPosition(MaxMapWidth/3 , 12);
            //Thread.Sleep (300);
            //Console.ReadLine ();
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            Music music = new Music();

            music.MainMusic();

            Walls walls = new Walls(100, 25);

            walls.Draw();

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

            snake.Draw();

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

            food.Draw();

            int xOffsetO4ki = 40;
            int yOffsetO4ki = 26;

            int o4ki = 0;

            WriteText("Баллы:" + o4ki, xOffsetO4ki, yOffsetO4ki);

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    music.EatSound();
                    food = foodCreator.CreateFood();
                    food.Draw();
                    o4ki++;
                    Console.SetCursorPosition(xOffsetO4ki, yOffsetO4ki);
                    WriteText("Баллы:" + o4ki, xOffsetO4ki, yOffsetO4ki);
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
            music.GameOver();
            WriteGameOver(o4ki);
            Console.ReadLine();
        }
Ejemplo n.º 18
0
 public static void CreateObjects()
 {
     snake = new Snake();      //
     //Game.snake.AddElements();//
     walls = new Walls(level); //
     food  = new Food();       //
     //walls.StartLevel(level);//
     // food.FoodGenerate();
 }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            //Console.WriteLine(Console.BufferHeight.ToString());
            //Console.WriteLine(Console.BufferWidth.ToString());
            //Console.WriteLine(Console.SetWindowSize);
            //Console.WriteLine(Console.LargestWindowWidth);
            //Console.SetBufferSize(80, 25);
            Console.SetWindowSize(80, 25);
            Console.CursorVisible = false;

            Walls walls = new Walls(80, 25);

            walls.Draw();

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

            snake.Draw(ConsoleColor.Green);

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

            food.Draw(ConsoleColor.Yellow);

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

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

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
                Thread.Sleep(100);
                //snake.Move();
            }

            Console.SetCursorPosition(35, 12);
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Game over!");
            Console.ReadKey();
        }
Ejemplo n.º 20
0
        public bool CrashedIntoTheWall(Walls w)
        {
            Point head = Plist.First();

            if (head.X == 0 || head.X == w.Width || head.Y == w.Heigh || head.Y == 0)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            // Рисуем границы
            Walls wall = new Walls(80, 25);
            wall.Draw();

            //рисуем змею
            Point p = new Point(4, 5, '*');
            Snake snake = new Snake(p, 5, Direction.RIGHT);
            snake.Draw();

            //создаём еду
            FoodCreator foodCeator = new FoodCreator(78, 23, '$');
            Point food = foodCeator.CreateFood();
            food.Draw();

            while (true)
            {

                if (snake.crossingWall() || snake.crossingBody()) // проверка столкновения
                {
                    Console.Clear();
                    Console.WriteLine("Ты проиграл!");
                    Console.ReadLine();
                    break;
                }

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

                Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.iMoveTo(key.Key);
                }
            }
        }
Ejemplo n.º 22
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())
                {
                    break;
                }

                // змейка кушает
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(200);

                // проверка на нажатие какой либо клавиши
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandlKey(key.Key);
                }
            }

            WriteGameOver();
            Console.ReadKey();
        }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);
            Walls walls = new Walls(80, 25);

            walls.Draw();


            HorisontalLine lowLine = new HorisontalLine(0, 78, 0, '+');

            lowLine.Drow();
            HorisontalLine upperLine = new HorisontalLine(0, 78, 24, '+');

            upperLine.Drow();
            VerticalLine leftLine = new VerticalLine(0, 0, 24, '+');

            leftLine.Drow();
            VerticalLine rightLine = new VerticalLine(78, 0, 24, '+');

            rightLine.Drow();

            Point p1    = new Point(4, 4, '*');
            Snake snake = new Snake(p1, 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);
                }
            }
        }
Ejemplo n.º 24
0
        static void Main(string[] args)
        {
            Walls walls = new Walls(1, 80);

            walls.Draw();

            //Отрисовка рамки
            //HotizontalLine line = new HotizontalLine(1,60,0,'-');
            //line.Drow();
            //HotizontalLine line1 = new HotizontalLine(1, 60, 25, '-');
            //line1.Drow();

            //VerticalLine line2 = new VerticalLine(1, 24, 1, '|');
            //line2.Drow();
            //VerticalLine line3 = new VerticalLine(1, 24, 60, '|');
            //line3.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.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);
                }
            }
        }
Ejemplo n.º 25
0
        public void game_draw()
        {
            Console.Clear();
            Console.Title = "Snake";
            Console.SetWindowSize(101, 26);

            Walls walls = new Walls(101, 26);

            walls.Draw();


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

            snake.Draw();
            FoodCreator foodCreator = new FoodCreator(101, 26, '¤', ConsoleColor.Green);
            Point       food        = foodCreator.CreateFood();

            food.Draw();
            Score score = new Score(0, 1);//score =0, level=1

            score.speed = 135;
            score.ScoreWrite();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    score.ScoreUp();
                    score.ScoreWrite();
                    food = foodCreator.CreateFood();
                    food.Draw();
                    //sound.Stop("stardust.mp3");
                    if (score.ScoreUp())
                    {
                        score.speed -= 10;
                    }
                }
                else
                {
                    snake.Move();
                }
                Thread.Sleep(score.speed);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey(true);
                    snake.HandleKey(key.Key);
                }
            }
        }
Ejemplo n.º 26
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);
            int speed = 100;
            GameObjects gameObjects = new GameObjects();
            char sym = '$';

            // Создадим и отобразим стены. Так же занесём их в список объектов
            Walls walls = new Walls('+');
            gameObjects.Add(walls);

            // Создадим змейку
            Snake snake = new Snake(new Point(2, 3, '*'), 3, Direction.RIGHT);
            gameObjects.Add(snake);
            // Создадим еду
            FoodCreator foodCreator = new FoodCreator('$');
            foodCreator.CreateFood(gameObjects, 1);
            gameObjects.Add(foodCreator);

            while(true)
            {
                if (gameObjects.Intersect(snake))
                {
                    Figure intersectFigure = new Figure();
                    int intersectObjectNum = gameObjects.GetIntersectObjectNum(snake);
                    intersectFigure = gameObjects.GetObject(intersectObjectNum);
                    if(intersectFigure.GetObjectType() == ObjectTypes.FOOD)
                    {
                        gameObjects.DeleteObject(intersectObjectNum);
                        snake.Eat();
                        FoodCreator foodCreator2 = new FoodCreator('$');
                        foodCreator2.CreateFood(gameObjects, 2);
                        gameObjects.Add(foodCreator2);
                    }
                    else
                    {
                        Console.SetCursorPosition(10, 10);
                        Console.ForegroundColor = ConsoleColor.DarkRed;
                        Console.WriteLine("Game Over");
                        Console.ReadLine();
                        break;
                    }
                }
                // Проверим нажата ли кнопка
                if (Console.KeyAvailable)
                {
                    // Если таки нажата, то изменим направление в соответсвии с нажатием
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandelKey(key.Key);
                }
                Thread.Sleep(speed);
                snake.Move();
            }
        }
Ejemplo n.º 27
0
        static void Main()
        {
            Console.SetBufferSize(150, 50);
            Console.WindowHeight  = 50;
            Console.WindowWidth   = 150;
            Console.CursorVisible = false;

            Walls walls = new Walls(148, 49);

            walls.Draw();

            Point p1    = new Point(10, 10, '*');
            Snake snake = new Snake(p1, 7, Direction.RIGHT);

            snake.Draw();
            snake.Move();


            FoodCreator foodCreator = new FoodCreator(149, 48, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();



            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    Console.Clear();
                    Console.SetCursorPosition(75, 25);
                    Console.WriteLine("GAME OVER");
                    Console.ReadKey();
                }

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


                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key);
                }
                Thread.Sleep(100);
            }
        }
Ejemplo n.º 28
0
        static void Main(string[] args)
        {
            const int MAP_WIDTH  = 80;
            const int MAP_HEIGHT = 25;

            Console.SetWindowSize(MAP_WIDTH, MAP_HEIGHT + 2);
            Console.SetBufferSize(MAP_WIDTH, MAP_HEIGHT + 2);

            Walls walls = new Walls(MAP_WIDTH, MAP_HEIGHT);

            walls.Draw();

            DrawScore(MAP_HEIGHT, 0);

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

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(MAP_WIDTH, MAP_HEIGHT, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    DrawGameOver();
                    DrawScore(1, snake.Score);
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                    DrawScore(MAP_HEIGHT, snake.Score);
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    snake.HandleKey(Console.ReadKey().Key);
                }
            }

            Console.ReadKey();
        }
Ejemplo n.º 29
0
        public Game()
        {
            Console.SetWindowSize(100, 30);
            Walls walls = new Walls(80, 25);

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

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

            food.Draw();
            Params settings = new Params();
            Sounds sound    = new Sounds(settings.GetResourceFolder());

            sound.PlayBackground();
            Score count = new Score(0);

            count.ScoreInGame();
            Sounds soundEat = new Sounds(settings.GetResourceFolder());

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                    count.ScoreUp();
                    count.ScoreInGame();
                    soundEat.PlayEat();
                }
                else
                {
                    snake.Move();
                }
                Thread.Sleep(100);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.Button(key.Key);
                }
            }
            new GameOverSnake();
            sound.PlayEnd();
            Thread.Sleep(5000);
            new EndScore(count.GetScore(), settings.GetResourceFolder());
        }
Ejemplo n.º 30
0
        static void Main(string[] args)
        {
            //Начальное положение змейки
            Point p1 = new Point(1, 3, '*');

            //Создание и отрисовка стен-рамки
            Walls walls = new Walls(Console.WindowWidth, Console.WindowHeight);

            walls.Draw();

            //Создание и отрисовка змейки
            Snake snake = new Snake(p1, 4, Direction.Right);

            snake.Draw();

            //Создание генератора еды
            FoodCreator foodCreator = new FoodCreator(Console.WindowWidth - 1, Console.WindowHeight - 1, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            //Отключение отображения курсора
            Console.CursorVisible = false;
            //Цикл игры
            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(true);
                    snake.HandleKey(key.Key);
                }
            }

            Console.ReadKey();
        }
Ejemplo n.º 31
0
        static void Main(string[] args)
        {
            Walls walls = new Walls(80, 25);

            walls.Draw();

            //*ОТРИСОВКА РАМОЧКИ
            //HorizontalLine upLine = new HorizontalLine(0, Console.BufferWidth - 1, 0, 'X');
            //HorizontalLine downLine = new HorizontalLine(0, Console.BufferWidth - 1, 28, 'X');
            //VerticalLine leftLine = new VerticalLine(0, 28, 0, 'X');
            //VerticalLine rightLine = new VerticalLine(0, 28, Console.BufferWidth - 1, 'X');
            //upLine.Drow();
            //downLine.Drow();
            //leftLine.Drow();
            //rightLine.Drow();


            //Отрисовка точек
            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);
                }
            }
        }
Ejemplo n.º 32
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(1, 1);
            Console.SetBufferSize(80, 25);
            Console.SetWindowSize(80, 25);
            Console.CursorVisible = false;

            Console.WriteLine("Правила игры: Нельзя врезаться в стену. Чтобы змейка росла - нужно есть @!");
            Console.ReadLine();

            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();
                    snake.Draw();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
            WriteGameOver();
            Console.ReadLine();
        }
Ejemplo n.º 33
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())
                {
                    break;
                }
                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(100);
            }
            Console.ForegroundColor = ConsoleColor.Yellow;
            int y = 9;

            WriteLine("============================", 26, y++);
            WriteLine("Game over", 35, y++);
            WriteLine("", 26, y += 2);
            WriteLine("Created by:  Oleg Glytenko", 28, y++);
            WriteLine("My first game!!!", 32, y++);
            WriteLine("============================", 26, y++);
            Console.SetCursorPosition(0, 0);
            Thread.Sleep(1000);
            Console.ReadKey();
        }
Ejemplo n.º 34
0
        static void Main(string[] args)
        {
            //размер окна
            Console.SetWindowSize(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.DrawLine();

            //еда
            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);
                }
            }
        }
Ejemplo n.º 35
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())
                {
                    break;
                }
                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(100);
            }
            Console.ForegroundColor = ConsoleColor.Yellow;
            int y = 9;
            WriteLine("============================", 26, y++);
            WriteLine("Game over", 35, y++);
            WriteLine("", 26, y += 2);
            WriteLine("Created by:  Oleg Glytenko", 28, y++);
            WriteLine("My first game!!!", 32, y++);
            WriteLine("============================", 26, y++);
            Console.SetCursorPosition(0, 0);
            Thread.Sleep(1000);
            Console.ReadKey();
        }
Ejemplo n.º 36
0
        static void Main(string[] args)
        {
            Walls walls = new Walls(80,25);
            walls.Draw();

            Point tale = new Point(2, 12, '*');
            Snake snake = new Snake(tale,7,Direction.right);
            snake.Draw();

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

            Console.SetCursorPosition(0, 0);
            Console.Write("Score: 0");
            int s = 0;

            while (true)
            {
                if (walls.isHit(snake.points.Last()) || snake.IsHit())
                {
                    break;
                }

                if (snake.Eat(food))
                {
                    s++;
                    Console.SetCursorPosition(0, 0);
                    Console.Write("Score: "+s);
                    Thread.Sleep(10);
                    food = foodCreator.CreateFood();
                    food.Show();
                }

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

                Thread.Sleep(150);
                snake.Move();
            }
            Console.SetCursorPosition(30, 12);
            Console.WriteLine("OLOLO!!!!!!!!!!!!!!!!!");
            Console.ReadLine();
        }
Ejemplo n.º 37
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(Console.WindowWidth, Console.WindowHeight);

            // Рамка
            Walls walls = new Walls(Console.WindowWidth, Console.WindowHeight);
            walls.Draw();

            //Змея
            Point p = new Point(4,5);
            Snake snake = new Snake(p, 4, Direction.RIGHT);
            snake.Draw();

            //Еда
            FoodCreator foodCreator = new FoodCreator(Console.WindowWidth, Console.WindowHeight, '$');
            Point food = foodCreator.CreateFood();
            Console.ForegroundColor = ConsoleColor.Cyan;
            food.Draw();
            Console.ResetColor();

            //Двигаем
            while(true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                    break;
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    food.Draw();
                    Console.ResetColor();
                }
                else snake.Move();
                Thread.Sleep(200);
                if (Console.KeyAvailable)
                {
                    snake.HandleKey(Console.ReadKey().Key);
                }
            }
            Console.SetCursorPosition(Console.WindowWidth / 2, Console.WindowHeight / 2);
            snake.Clear();
            food.Clear();
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Good Bye!");
            Console.ResetColor();
            Console.ReadLine();
        }
Ejemplo n.º 38
0
        public static void Main(string[] args)
        {
            Walls walls = new Walls( 79, 24 );
            walls.Draw();

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

            FoodCreator foodCreator = new FoodCreator( 77, 22, '$' );
            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();
        }
Ejemplo n.º 39
0
        static void Main(string[] args)
        {
            int t;
            Console.WriteLine("      Выберите свой уровень игры:\nвысокий - 1, средний - 2 или низкий - 3");
            ConsoleKeyInfo cinf= Console.ReadKey();
            t = (cinf.KeyChar - 48) * 100;
            Console.Clear();
            Console.SetBufferSize(80, 25);
            Walls wall = new Walls(80, 25);
            wall.Drow();

            Point p1 = new Point(3, 3, '*',ColorSnake.WHITE);
            Snake sn = new Snake(p1, 5, Direction.RIGHT);
            sn.Draw();
            FoodCreator fc = new FoodCreator(80, 25, '$',ColorSnake.YELLOW);
            Point food = fc.CreateFood();
            food.Draw();
            while (true)
            {
                if (wall.IsHit(sn) || sn.IsHitTail())
                    break;
                if (sn.Eat(food))
                {
                    food = fc.CreateFood();
                    food.Draw();
                }
                else
                    sn.Move();
                Thread.Sleep(t);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    sn.HandleKey(key.Key);
                }
            }
            Console.Clear();
            Console.WriteLine("   Игра окончена! \nСпасибо за внимание.");
            Console.ReadLine();
        }
Ejemplo n.º 40
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Green;   // Welcome to the Matrix

            Console.SetBufferSize(120, 30); // Set console window size

            Point point = new Point(4, 5, '@'); // Start snake position and default snake symbol
            Hero snake = new Hero(point, 4, Direction.RIGHT); // point = start dir. position and snake symbol, 4 = default snake lenght, default direction
            snake.DrawFigure();

            FoodCreator foodCreator = new FoodCreator(100, 25, '#'); // Max range of food spawn and default food symbol
            Point foodPoint = foodCreator.CreateFood();
            foodPoint.DrawPoint();

            Walls walls = new Walls(120, 25); // Max x and y position of walls
            walls.DrawWalls();

            while (true)
            {

                if (snake.Eat(foodPoint))
                {
                    foodPoint = foodCreator.CreateFood();
                    foodPoint.DrawPoint();
                } else
                {
                    snake.MoveHero();
                }
                Thread.Sleep(300);

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

            }
        }
Ejemplo n.º 41
0
        static void Main(string[] args)
        {
            // Dimensions
            //int winW = Console.WindowWidth - 1;
            //int winH = Console.WindowHeight - 1;
            int winH = 20;
            int winW = 34;

            ushort level = 1;

            // Border
            Walls walls = new Walls(winW, winH);
            walls.Draw();

            // Snake
            Point tl = new Point(10, 10, '*');
            Snake snake = new Snake(tl, 3, Direction.RIGHT);

            // Food
            FoodFactory foodfactory = new FoodFactory(winH, winW, '$');
            Point food = foodfactory.createFood(snake);
            Console.ForegroundColor = ConsoleColor.Yellow;
            food.Draw();
            Console.ResetColor();

            // Infinite loop
            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    // Snake dies
                    Console.SetCursorPosition(2, 2);
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("Snake collapsed...");
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodfactory.createFood(snake);
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    food.Draw();
                    Console.ResetColor();
                    // level up every 5 feeds and level cap is 40 (121 - level * 3 must be > 0)
                    if (snake.length % 5 == 0 && level < 40)
                        level++;
                }
                else
                {
                    snake.Move();
                }
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey(true);
                    snake.HandleKey(key.Key);
                    if (key.Key == ConsoleKey.Q)
                        break; // Get the hell out of this infinite loop
                }

                // Thread.Sleep(80); // Control FPS here
                Thread.Sleep(121 - level * 3);

                Console.SetCursorPosition(2, 1);
                Console.Write("Length: " + snake.length + " Level: " + level);
            }

            // Print banner and wait for Enter key
            Console.ForegroundColor = ConsoleColor.Yellow;
            int endplaneX = Math.Abs((winW / 2) - 15);
            Console.SetCursorPosition(endplaneX, 7);
            Console.Write("===============================");
            Console.SetCursorPosition(endplaneX, 8);
            Console.Write("| Thank you for playing. Bye! |");
            Console.SetCursorPosition(endplaneX, 9);
            Console.Write("|   Press Enter key to quit.  |");
            Console.SetCursorPosition(endplaneX, 10);
            Console.Write("===============================");
            while (Console.ReadKey(true).Key != ConsoleKey.Enter) { }
        }
Ejemplo n.º 42
0
        static void Main(string[] args)
        {
            int TARGET_SNAKE_LENGTH;
            int result;

            TARGET_SNAKE_LENGTH = 10;

            Console.SetBufferSize(80, 25);

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

            ShowMenu();

            while (true)
            {
                ConsoleKeyInfo action = Console.ReadKey();
                if (action.Key == ConsoleKey.S)
                {
                    Console.Clear();
                    walls.Draw();
                    result = 0;

                    Point p = new Point(40, 12, '*');
                    Snake snake = new Snake(p, 5, Direction.LEFT);
                    snake.Draw();

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

                    while (true)
                    {

                        if (walls.IsHit(snake) || snake.IsHitTail())
                        {
                            result = 0;
                            break;
                        }
                        if (snake.GetLength() >= TARGET_SNAKE_LENGTH)
                        {
                            result = 1;
                            break;
                        }
                        if (snake.Eat(food))
                        {
                            food = foodCreator.CreateFood();
                            food.Draw();
                        }
                        else
                        {
                            snake.Move();
                        }

                        Thread.Sleep(300);

                        if (Console.KeyAvailable)
                        {
                            ConsoleKeyInfo key = Console.ReadKey();
                            snake.HandleKey(key.Key);
                        }
                    }
                    Console.Clear();
                    walls.Draw();
                    ShowMenu();
                    if (result==1)
                        ShowMessage("ПОЗДРАВЛЯЕМ! ВЫ ВЫИГРАЛИ.");
                    else
                        ShowMessage("ВЫ ПРОИГРАЛИ. ПОПРОБУЙТЕ ЕЩЁ РАЗ.");
                }
                else if (action.Key == ConsoleKey.E)
                {
                    break;
                }
            }

            /*
            Console.SetCursorPosition(32, 12);
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("===============");
            Console.SetCursorPosition(33, 13);
            Console.WriteLine("ИГРА ОКОНЧЕНА");
            Console.SetCursorPosition(32, 14);
            Console.WriteLine("===============");
            Console.ReadLine();
            */
        }