private SnakeSegment GetNextCell() { SnakeSegment head = _snake.Last(); SnakeSegment nextCell = new SnakeSegment(head); nextCell.Move(Settings.SizeCell, Direction); return(nextCell); }
private void MoveBody() { SnakeSegment tail = _snake.First(); _snake.Remove(tail); SnakeSegment head = GetNextCell(); _snake.Add(head); }
private bool Eat(Fruit fruit) { SnakeSegment head = _snake.Last(); if (head.IsHit(fruit)) { _snake.Add(new SnakeSegment(fruit)); return(true); } return(false); }
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; } }
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); }
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)); }