Ejemplo n.º 1
0
        private SnakeSegment GetNextCell()
        {
            SnakeSegment head     = _snake.Last();
            SnakeSegment nextCell = new SnakeSegment(head);

            nextCell.Move(Settings.SizeCell, Direction);

            return(nextCell);
        }
Ejemplo n.º 2
0
        private void MoveBody()
        {
            SnakeSegment tail = _snake.First();

            _snake.Remove(tail);
            SnakeSegment head = GetNextCell();

            _snake.Add(head);
        }
Ejemplo n.º 3
0
        private bool Eat(Fruit fruit)
        {
            SnakeSegment head = _snake.Last();

            if (head.IsHit(fruit))
            {
                _snake.Add(new SnakeSegment(fruit));
                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        public Snake(int length, Keys direction)
        {
            _snake    = new List <SnakeSegment>();
            Direction = direction;
            SnakeSegment tail = new SnakeSegment(CenterFieldX, CenterFieldY);

            for (int i = 0; i < length; i++)
            {
                SnakeSegment nextCell = new SnakeSegment(tail, Direction);
                _snake.Add(nextCell);
                tail = nextCell;
            }
        }
Ejemplo n.º 5
0
        private bool IsHitTail()
        {
            SnakeSegment head = _snake.Last();

            for (int i = 0; i < _snake.Count - 2; i++)
            {
                if (head.IsHit(_snake[i]))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 6
0
        public bool Equals(SnakeSegment cell)
        {
            if (ReferenceEquals(cell, null))
            {
                return(false);
            }

            if (ReferenceEquals(this, cell))
            {
                return(true);
            }

            if (GetType() != cell.GetType())
            {
                return(false);
            }

            return((X == cell.X) && (Y == cell.Y));
        }