public void Move(IBoardElement boardElement, Direction direction) { var pos = _currentPositions[boardElement]; int newX = pos.X; int newY = pos.Y; switch (direction) { case Direction.North: newX--; break; case Direction.South: newX++; break; case Direction.East: newY++; break; case Direction.West: newY--; break; } var newPosition = new Point(newX, newY); // var newPosition = GetNewPosition[direction](pos); if (!PointInsidePlayArea(newPosition)) { throw new InvalidMoveException(); } RemoveElement(boardElement); AddElement(boardElement, newPosition); }
public void AddElement(IBoardElement boardElement, Point position) { if (!PointInsidePlayArea(position)) { throw new ArgumentException("Position is not on board", "position"); } _playArea[position.X, position.Y].Add(boardElement); _currentPositions[boardElement] = position; }
public void RemoveElement(IBoardElement boardElement) { if (boardElement == null) { throw new ArgumentNullException("boardElement"); } if (!_currentPositions.ContainsKey(boardElement)) { throw new ArgumentException("Element not on board", "boardElement"); } var pos = _currentPositions[boardElement]; _playArea[pos.X, pos.Y].Remove(boardElement); _currentPositions.Remove(boardElement); }
private void Pickup(Board board, IBoardElement can) { board.RemoveElement(can); }
public Point GetCurrentPosition(IBoardElement element) { return(_currentPositions[element]); }
private void Pickup(Board board, IBoardElement can) { board.RemoveElement(can); }