Ejemplo n.º 1
0
        public bool HitSelf()
        {
            CSnakePart head = Body[0];
            bool       hit  = false;

            for (int i = 1; i < Body.Count; i++)
            {
                hit = head.DrawRect.IntersectsWith(Body[i].DrawRect);
                if (hit)
                {
                    break;
                }
            }
            return(hit);
        }
Ejemplo n.º 2
0
        public bool HitWall(int __maxWidth, int __maxHeight)
        {
            CSnakePart head   = Body[0];
            int        buffer = CSnakePart.Size;

            if ((head.Location.X <= buffer) || (head.Location.X >= (__maxWidth - buffer)))
            {
                return(true);
            }
            if ((head.Location.Y <= buffer) || (head.Location.Y >= (__maxHeight - buffer)))
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        public void Add(int __section)
        {
            int buffer = CSnakePart.Size * 2;

            for (int i = 0; i < __section; i++)
            {
                if (Body.Count > 0)
                {
                    CSnakePart lastPart = Body[Body.Count - 1];
                    int        x        = 0;
                    int        y        = 0;
                    switch (Direction)
                    {
                    case EDirection.Left:
                        x = lastPart.Location.X + buffer;
                        y = lastPart.Location.Y;
                        break;

                    case EDirection.Right:
                        x = lastPart.Location.X - buffer;
                        y = lastPart.Location.Y;
                        break;

                    case EDirection.Up:
                        x = lastPart.Location.X;
                        y = lastPart.Location.Y + buffer;
                        break;

                    case EDirection.Down:
                        x = lastPart.Location.X;
                        y = lastPart.Location.Y - buffer;
                        break;

                    default:
                        break;
                    }
                    Body.Add(new CSnakePart(x, y));
                }
                else
                {
                    Body.Add(new CSnakePart(150, 100));
                }
            }
        }
Ejemplo n.º 4
0
        public void Update(EDirection __direction)
        {
            Direction = __direction;
            // все идут за головой
            for (int i = Body.Count - 1; i > 0; i--)
            {
                CSnakePart leader = Body[i - 1];
                Body[i].Update(leader.Location.X, leader.Location.Y);
            }

            // только голова меняет направление

            CSnakePart head = Body[0];
            int        x = 0, y = 0;
            int        buffer = CSnakePart.Size * 2;

            switch (Direction)
            {
            case EDirection.Left:
                x = head.Location.X - buffer;
                y = head.Location.Y;
                break;

            case EDirection.Right:
                x = head.Location.X + buffer;
                y = head.Location.Y;
                break;

            case EDirection.Up:
                x = head.Location.X;
                y = head.Location.Y - buffer;
                break;

            case EDirection.Down:
                x = head.Location.X;
                y = head.Location.Y + buffer;
                break;

            default:
                break;
            }
            head.Update(x, y);
        }
Ejemplo n.º 5
0
        public bool CanEatFood(CFood __f)
        {
            CSnakePart head = Body[0];

            return(head.DrawRect.IntersectsWith(__f.DrawRect));
        }