Esempio n. 1
0
 public void Move()
 {
     var toReplace = _tail;
     _tail = _tail.Next ?? _head;
     switch (_head.Direction)
     {
         case MoveDirection.Up:
             SetXY(toReplace, _head.X, _head.Y - 1);
             break;
         case MoveDirection.Down:
             SetXY(toReplace, _head.X, _head.Y + 1);
             break;
         case MoveDirection.Left:
             SetXY(toReplace, _head.X - 1, _head.Y);
             break;
         case MoveDirection.Right:
             SetXY(toReplace, _head.X + 1, _head.Y);
             break;
         default:
             SetXY(toReplace, _head.X, _head.Y);
             break;
     }
     _head.Next = toReplace.Next == null ? null : toReplace;
     toReplace.Direction = _head.Direction;
     _head = toReplace;
     
 }
Esempio n. 2
0
 public void Eat()
 {
     var growthCell = new SnakeCell(_tail);
     if (_head.Direction == MoveDirection.Stop || _tail.Direction == MoveDirection.Stop) return;
     growthCell = _pushMethods[_tail.Direction](growthCell, _tail);
     _body.Add(growthCell);
     _tail = growthCell;
 }
Esempio n. 3
0
 public Snake(int stX, int stY)
 {
     _head = new SnakeCell {X = stX, Y = stY};
     _tail = _head;
     _body.Add(_head);
     _head.Direction = MoveDirection.Down;
     _tail.Direction = _head.Direction;
 }
Esempio n. 4
0
 private void SetXY(SnakeCell cell, int x, int y)
 {
     cell.X = x;
     cell.Y = y;
 }
Esempio n. 5
0
 private void MoveXY(SnakeCell cell, int dX, int dY)
 {
     cell.X += dX;
     cell.Y += dY;
 }