Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 private void Pickup(Board board, IBoardElement can)
 {
     board.RemoveElement(can);
 }
Ejemplo n.º 5
0
 public Point GetCurrentPosition(IBoardElement element)
 {
     return(_currentPositions[element]);
 }
Ejemplo n.º 6
0
 private void Pickup(Board board, IBoardElement can)
 {
     board.RemoveElement(can);
 }