private async Task End(string str) { GameOver = true; if (str == "X") { await Task.Run(() => { Player1Items.Add(str); }); LS1.Items.Add(str + $" ({Player1Items.Count})"); LS1.ScrollIntoView(LS1.Items[LS1.Items.Count - 1]); } else { await Task.Run(() => { Player2Items.Add(str); }); LS2.Items.Add(str + $" ({Player2Items.Count})"); LS2.Items.MoveCurrentToLast(); LS2.ScrollIntoView(LS2.Items.CurrentItem); } }
/// <summary> /// Merges two lines together if they share a common end point. /// </summary> /// <param name="line1">The first line to be considered.</param> /// <param name="line2">The second line to be considered.</param> /// <param name="sfType">The type of shapefile the lines are a part of.</param> /// <param name="resultShp">The two lines merged into one multipart line</param> /// <returns>True if merging was successful, false otherwise.</returns> private static bool MergeLines(ref MapWinGIS.Shape line1, ref MapWinGIS.Shape line2, MapWinGIS.ShpfileType sfType, out MapWinGIS.Shape resultShp) { MapWinGIS.Shape mShp = new MapWinGIS.ShapeClass(); mShp.Create(sfType); //int pt = 0; //int prt = 0; if (line1 == null && line2 == null) { resultShp = mShp; return(false); } if (line1 == null && line2 != null) { resultShp = line2; return(false); } if (line2 == null) { resultShp = line1; return(false); } Topology2D.MultiLineString MLS1 = new MapWinGeoProc.Topology2D.MultiLineString(line1); Topology2D.MultiLineString MLS2 = new MapWinGeoProc.Topology2D.MultiLineString(line2); Topology2D.LineString LS2; // Join the linestrings from MLS1 where possible int j = 0; while (j < MLS1.NumGeometries) { LS2 = MLS1.GeometryN[j] as Topology2D.LineString; Topology2D.LineString LS1; Topology2D.Geometry outGeom; for (int i = 0; i < MLS1.NumGeometries; i++) { if (i == j) { continue; } LS1 = MLS1.GeometryN[i] as Topology2D.LineString; outGeom = LS1.Union(LS2); // Attempt to join each linestring to linestrings in MLS1 if (outGeom != null) { MLS1.GeometryN[i] = outGeom; MLS1.GeometryN.RemoveAt(j); continue; // don't increment j because we removed one instead } } j++; } // Add each linestring to MLS1, merging into single linestrings where possible while (MLS2.NumGeometries > 0) { LS2 = MLS2.GeometryN[0] as Topology2D.LineString; Topology2D.LineString LS1; Topology2D.Geometry outGeom; bool merged = false; for (int i = 0; i < MLS1.NumGeometries; i++) { LS1 = MLS1.GeometryN[i] as Topology2D.LineString; outGeom = LS1.Union(LS2); // Attempt to join each linestring to linestrings in MLS1 if (outGeom != null) { // The endpoint merge was successful MLS1.GeometryN[i] = outGeom; merged = true; break; } } // If they don't connect, add the linestring to the end of the list if (merged == false) { // endPoint merging was not successful MLS1.GeometryN.Add(LS2); } // either way, remove the line MLS2.GeometryN.RemoveAt(0); } resultShp = Topology2D.GeometryFactory.mwShapeFromMultiLineString(MLS1, sfType); return(true); }