Ejemplo n.º 1
0
        private Coordinate Move()
        {
            var x = _coordinate.X;
            var y = _coordinate.Y;

            switch (_direction)
            {
            case North:
                if (_grid.HitObstacle(new Coordinate(x + 1, y)))
                {
                    _obstacleHit = true;
                }
                else
                {
                    x = x + 1 > _grid.Height ? 0 : x + 1;
                }
                break;

            case South:
                if (_grid.HitObstacle(new Coordinate(x - 1, y)))
                {
                    _obstacleHit = true;
                }
                else
                {
                    x = x - 1 < 0 ? _grid.Height : x - 1;
                }
                break;

            case East:
                if (_grid.HitObstacle(new Coordinate(x, y + 1)))
                {
                    _obstacleHit = true;
                }
                else
                {
                    y = y + 1 > _grid.Width ? 0 : y + 1;
                }
                break;

            case West:
                if (_grid.HitObstacle(new Coordinate(x, y - 1)))
                {
                    _obstacleHit = true;
                }
                else
                {
                    y = y - 1 < 0 ? _grid.Width : y - 1;
                }
                break;
            }

            return(new Coordinate(x, y));
        }