Пример #1
0
Файл: Snake.cs Проект: MIDgar/t
        public ClassPoint GetNextPoint()
        {
            ClassPoint head      = pList.Last();
            ClassPoint nextPoint = new ClassPoint(head);

            nextPoint.Move(1, direction);
            return(nextPoint);
        }
Пример #2
0
Файл: VLine.cs Проект: MIDgar/t
 public VLine(int yTop, int yBottom, int x, char ch)
 {
     pList = new List <ClassPoint>();
     for (int y = yTop; y <= yBottom; y++)
     {
         ClassPoint p = new ClassPoint(x, y, ch);
         pList.Add(p);
     }
 }
Пример #3
0
 public HLine(int xLeft, int xRight, int y, char ch)
 {
     pList = new List <ClassPoint>();
     for (int x = xLeft; x <= xRight; x++)
     {
         ClassPoint p = new ClassPoint(x, y, ch);
         pList.Add(p);
     }
 }
Пример #4
0
 public bool IsHit(ClassPoint point)
 {
     foreach (var p in pList)
     {
         if (p.IsHit(point))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #5
0
Файл: Snake.cs Проект: MIDgar/t
 public Snake(ClassPoint tail, int lenght, Direction _direction)
 {
     direction = _direction;
     pList     = new List <ClassPoint>();
     for (int i = 0; i < lenght; i++)
     {
         ClassPoint p = new ClassPoint(tail);
         p.Move(i, direction);
         pList.Add(p);
     }
 }
Пример #6
0
Файл: Snake.cs Проект: MIDgar/t
        internal void Move()
        {
            ClassPoint tail = pList.First();

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

            pList.Add(head);

            tail.Clear();
            head.pointDraw();
        }
Пример #7
0
Файл: Snake.cs Проект: MIDgar/t
        internal bool Eat(ClassPoint food)
        {
            ClassPoint head = GetNextPoint();

            if (head.IsHit(food))
            {
                food.ch = head.ch;
                pList.Add(food);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #8
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);
            Walls walls = new Walls(80, 25);

            walls.Draw();

            ClassPoint p = new ClassPoint(2, 4, '*');

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

            snake.Draw();

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

            food.pointDraw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    By bye = new By();
                    bye.SayBy();
                    break;
                }

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

            Console.ReadKey();
        }
Пример #9
0
 public bool IsHit(ClassPoint p)
 {
     return(p.x == this.x && p.y == this.y);
 }
Пример #10
0
 public ClassPoint(ClassPoint p)
 {
     x  = p.x;
     y  = p.y;
     ch = p.ch;
 }