protected internal override void PerformOperation() { IEnumerable <Coordinates> locations = ShipList.GetAllLocations(Position, Orientation, Ship.Length); foreach (Coordinates coords in locations) { if (coords.X < 0 || coords.Y < 0 || coords.X >= Ship.Owner.Match.FieldSize.X || coords.Y >= Ship.Owner.Match.FieldSize.Y) { throw new InvalidEventException(this, String.Format("The ship {0} was placed out of bounds.", Ship)); } foreach (Ship otherShip in Ship.Owner.Ships) { if (otherShip.IsPlaced && otherShip.IsAt(coords)) { throw new InvalidEventException(this, String.Format("The ship {0} conflicts with ship {1}.", Ship, otherShip)); } } } Ship.Location = Position; Ship.Orientation = Orientation; Ship.Locations = new HashSet <Coordinates>(locations); Ship.RemainingLocations = new HashSet <Coordinates>(Ship.Locations); Ship.IsPlaced = true; Ship.Active = true; }