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); }
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)); }
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; }
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))); }