Ejemplo n.º 1
0
        internal Robot Move()
        {
            var x            = Coordinates.X;
            var y            = Coordinates.Y;
            var compassPoint = CompassPoint;
            var name         = Name;

            return(Pattern.Match <CompassPoint, Robot>(compassPoint)
                   .When(c => c == CompassPoint.North, () => new Robot(name, RobotCoordinates.Create(x, y + 1), compassPoint))
                   .When(c => c == CompassPoint.South, () => new Robot(name, RobotCoordinates.Create(x, y - 1), compassPoint))
                   .When(c => c == CompassPoint.East, () => new Robot(name, RobotCoordinates.Create(x + 1, y), compassPoint))
                   .When(c => c == CompassPoint.West, () => new Robot(name, RobotCoordinates.Create(x - 1, y), compassPoint))
                   .Result);
        }
Ejemplo n.º 2
0
 internal static Robot Create(string name, RobotCoordinates coordinates, CompassPoint compassPoint)
 {
     return(new Robot(name, coordinates, compassPoint));
 }
Ejemplo n.º 3
0
 private Robot(string name, RobotCoordinates coordinates, CompassPoint compassPoint)
 {
     Coordinates  = coordinates;
     CompassPoint = compassPoint;
     Name         = name;
 }
Ejemplo n.º 4
0
        public RobotWarAggregate(IMemento memento)
        {
            var snapshot = memento as RobotWarMemento;

            if (snapshot == null)
            {
                throw new ApplicationException("memento type mismatch");
            }

            Id = snapshot.Id;
            ArenaCoordinates = new WriteOnce <ArenaCoordinates>();
            if (snapshot.ArenaCoordinates.HasValue)
            {
                ArenaCoordinates.Value = snapshot.ArenaCoordinates.Value;
            }
            _robots = snapshot.RobotMementos.Select(p => new KeyValuePair <string, Robot>(p.Name,
                                                                                          Robot.Create(p.Name, RobotCoordinates.Create(p.CoordinartesX, p.CoordinartesY), p.CompassPoint))).ToDictionary();
            Version = snapshot.Version;
        }
Ejemplo n.º 5
0
 private void Apply(RobotMoved evt)
 {
     _robots[evt.Name] = Domain.Robot.Create(evt.Name, RobotCoordinates.Create(evt.XPosition, evt.YPosition),
                                             EnumEx.MapByStringValue <Contracts.CompassPoint, CompassPoint>(evt.CompassPoint));
 }
Ejemplo n.º 6
0
 private void Apply(RobotAdded evt)
 {
     _robots.Add(evt.Name, Domain.Robot.Create(evt.Name, RobotCoordinates.Create(evt.XCoordinate, evt.YCoordinate),
                                               EnumEx.MapByStringValue <Contracts.CompassPoint, CompassPoint>(evt.CompassPoint)));
 }