Example #1
0
        public Point1 GetNextPoint()
        {
            Point1 head      = pList.Last();
            Point1 nextPoint = new Point1(head);

            nextPoint.Move(1, direction);
            return(nextPoint);
        }
Example #2
0
 public VerticalLine(int yUp, int yDown, int x, char sym)
 {
     pList = new List <Point1>();
     for (int y = yUp; y <= yDown; y++)
     {
         Point1 p = new Point1(x, y, sym);
         pList.Add(p);
     }
 }
Example #3
0
 public HorizontalLine(int xLeft, int xRight, int y, char sym)
 {
     pList = new List <Point1>();
     for (int x = xLeft; x <= xRight; x++)
     {
         Point1 p = new Point1(x, y, sym);
         pList.Add(p);
     }
 }
Example #4
0
 private bool IsHit(Point1 point)
 {
     foreach (var p in pList)
     {
         if (p.IsHit(point))
         {
             return(true);
         }
     }
     return(false);
 }
Example #5
0
 public Snake(Point1 tail, int length, Direction _direction)
 {
     direction = _direction;
     pList     = new List <Point1>();
     for (int i = 0; i < length; i++)
     {
         Point1 p = new Point1(tail);
         p.Move(i, direction);
         pList.Add(p);
     }
 }
Example #6
0
        internal void Move()
        {
            Point1 tail = pList.First();

            pList.Remove(tail);
            Point1 head = GetNextPoint();

            pList.Add(head);

            tail.Clear();
            head.Draw();
        }
Example #7
0
        internal bool Eat(Point1 food)
        {
            Point1 head = GetNextPoint();

            if (head.IsHit(food))
            {
                food.sym = head.sym;
                pList.Add(food);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #8
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(1, 1);
            Console.SetBufferSize(80, 25);
            Console.SetWindowSize(80, 25);

            Walls walls = new Walls(80, 25);

            walls.Draw();

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

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(80, 25, '$');
            Point1      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 #9
0
        static void Main(string[] args)
        {
            Point1 p1 = new Point1();

            p1.x   = 1;
            p1.y   = 3;
            p1.sym = '*';

            p1.Draw();

            Point1 p2 = new Point1();

            p2.x   = 4;
            p2.y   = 5;
            p2.sym = '#';

            p2.Draw();

            Console.ReadLine();
        }
Example #10
0
 public bool IsHit(Point1 p)
 {
     return(p.x == this.x && p.y == this.y);
 }
Example #11
0
 public Point1(Point1 p)
 {
     x   = p.x;
     y   = p.y;
     sym = p.sym;
 }