private void RemoveConnector(int x, int y) { if (x == 0 || x == myCurrentMap.Width - 1) { int arrno = x == 0 ? 0 : 2; for (int i = 0; i < myConArrows[arrno].Count; ++i) { ConnectorArrow arr = myConArrows[arrno][i]; if (y < arr.ConnectorInfo.Y || y > arr.ConnectorInfo.Y + arr.ConnectorInfo.Size) { continue; } int end = arr.ConnectorInfo.Y + arr.ConnectorInfo.Size; arr.ConnectorInfo.Size = y - arr.ConnectorInfo.Y; if (arr.ConnectorInfo.Size == 0) { myConArrows[arrno].Remove(arr); } if (end - y - 1 > 0) { myConArrows[arrno].Add(new ConnectorArrow(arr.ConnectorInfo.X, y + 1, true, end - y - 1)); } return; } } else if (y == 0 || y == myCurrentMap.Height - 1) { int arrno = y == 0 ? 1 : 3; for (int i = 0; i < myConArrows[arrno].Count; ++i) { ConnectorArrow arr = myConArrows[arrno][i]; if (x < arr.ConnectorInfo.X || x > arr.ConnectorInfo.X + arr.ConnectorInfo.Size) { continue; } int end = arr.ConnectorInfo.X + arr.ConnectorInfo.Size; arr.ConnectorInfo.Size = x - arr.ConnectorInfo.X; if (arr.ConnectorInfo.Size == 0) { myConArrows[arrno].Remove(arr); } if (end - x - 1 > 0) { myConArrows[arrno].Add(new ConnectorArrow(x + 1, arr.ConnectorInfo.Y, false, end - x - 1)); } return; } } }
private void AddConnector(int x, int y) { ConnectorArrow addedTo = null; if (x == 0 || x == myCurrentMap.Width - 1) { int arrno = x == 0 ? 0 : 2; foreach (ConnectorArrow arr in myConArrows[arrno]) { if (arr.ConnectorInfo.Y == y + 1) { arr.ConnectorInfo.Y -= 1; arr.ConnectorInfo.Size++; addedTo = arr; break; } else if (arr.ConnectorInfo.Y + arr.ConnectorInfo.Size == y) { arr.ConnectorInfo.Size++; addedTo = arr; break; } else if (y < arr.ConnectorInfo.Y || y > arr.ConnectorInfo.Y + arr.ConnectorInfo.Size) { continue; } return; } if (addedTo == null) { myConArrows[arrno].Add(new ConnectorArrow(x, y, true, 1)); } else { myConArrows[arrno].Remove(addedTo); foreach (ConnectorArrow arr in myConArrows[arrno]) { if (arr.ConnectorInfo.Y + arr.ConnectorInfo.Size == addedTo.ConnectorInfo.Y) { arr.ConnectorInfo.Size += addedTo.ConnectorInfo.Size; return; } else if (arr.ConnectorInfo.Y == addedTo.ConnectorInfo.Y + addedTo.ConnectorInfo.Size) { arr.ConnectorInfo.Y -= addedTo.ConnectorInfo.Size; arr.ConnectorInfo.Size += addedTo.ConnectorInfo.Size; return; } } myConArrows[arrno].Add(addedTo); } } else if (y == 0 || y == myCurrentMap.Height - 1) { int arrno = y == 0 ? 1 : 3; foreach (ConnectorArrow arr in myConArrows[arrno]) { if (arr.ConnectorInfo.X == x + 1) { arr.ConnectorInfo.X -= 1; arr.ConnectorInfo.Size++; addedTo = arr; break; } else if (arr.ConnectorInfo.X + arr.ConnectorInfo.Size == x) { arr.ConnectorInfo.Size++; addedTo = arr; break; } else if (x < arr.ConnectorInfo.X || x > arr.ConnectorInfo.X + arr.ConnectorInfo.Size) { continue; } return; } if (addedTo == null) { myConArrows[arrno].Add(new ConnectorArrow(x, y, false, 1)); } else { myConArrows[arrno].Remove(addedTo); foreach (ConnectorArrow arr in myConArrows[arrno]) { if (arr.ConnectorInfo.X + arr.ConnectorInfo.Size == addedTo.ConnectorInfo.X) { arr.ConnectorInfo.Size += addedTo.ConnectorInfo.Size; return; } else if (arr.ConnectorInfo.X == addedTo.ConnectorInfo.X + addedTo.ConnectorInfo.Size) { arr.ConnectorInfo.X -= addedTo.ConnectorInfo.Size; arr.ConnectorInfo.Size += addedTo.ConnectorInfo.Size; return; } } myConArrows[arrno].Add(addedTo); } } }