Exemplo n.º 1
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);
                }
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(82, 27);

            //Отрисовка рамочки.
            HorisontalLine lowLine   = new HorisontalLine(1, 78, 25, '=');
            HorisontalLine topLine   = new HorisontalLine(1, 78, 2, '=');
            VerticalLine   leftLine  = new VerticalLine(1, 3, 24, '|');
            VerticalLine   rightLine = new VerticalLine(78, 3, 24, '|');

            lowLine.DrawLine();
            topLine.DrawLine();
            leftLine.DrawLine();
            rightLine.DrawLine();

            //Отрисовка еды.
            FoodCreator foodCreator = new FoodCreator(82, 27, '@');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            //Отрисовка змейки.
            Point startPoint = new Point(3, 4, '*');
            Snake snake      = new Snake(startPoint, 4, Direction.RIGHT);

            snake.DrawLine();

            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.Control(key.Key);
                }
                //Thread.Sleep(100);
                //snake.Move();
            }



            Console.ReadLine();
        }
Exemplo n.º 3
0
        public Walls(int mapWidht, int mapHeight)
        {
            wallList = new List <Figure>();
            HorisontalLine upLine    = new HorisontalLine(0, mapWidht - 2, 0, '+');
            HorisontalLine downLine  = new HorisontalLine(0, mapWidht - 2, mapHeight - 1, '+');
            VerticalLine   leftLine  = new VerticalLine(0, mapHeight - 1, 0, '+');
            VerticalLine   rightLine = new VerticalLine(0, mapHeight - 1, mapWidht - 2, '+');

            wallList.Add(upLine);
            wallList.Add(downLine);
            wallList.Add(leftLine);
            wallList.Add(rightLine);
        }