Esempio n. 1
0
        public Walls(int mapWidth, int mapHeight)
        {
            wallList = new List <Figure>();


            //Отрисовка рамочки
            HorizontalLines upLine    = new HorizontalLines(0, mapWidth - 2, 0, '+');
            HorizontalLines downLine  = new HorizontalLines(0, mapWidth - 2, mapWidth - 1, '+');
            VerticalLines   leftLine  = new VerticalLines(0, mapHeight - 1, 0, '+');
            VerticalLines   rightLine = new VerticalLines(0, mapHeight - 1, mapWidth - 2, '+');

            wallList.Add(upLine);
            wallList.Add(downLine);
            wallList.Add(leftLine);
            wallList.Add(rightLine);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            //Console.SetBufferSize(80, 25);

            Walls walls = new Walls(80, 25);

            walls.Draw();



            //Рамочка



            HorizontalLines upline    = new HorizontalLines(0, 78, 0, '+');
            HorizontalLines downline  = new HorizontalLines(0, 78, 24, '+');
            VerticalLines   leftline  = new VerticalLines(0, 24, 0, '+');
            VerticalLines   rightline = new VerticalLines(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 (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);
                }
            }


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