Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4.  
  5. public class Shape
  6. {
  7. public int ID;
  8. }
  9.  
  10. public class IntersectingSprites
  11. {
  12. public static List<Shape> Shapes = new List<Shape>();
  13.  
  14. public static Dictionary<int, List<int>> ShapesList;
  15. [STAThread]
  16. static void Main()
  17. {
  18. ShapeCheck();
  19. }
  20.  
  21. public static void ShapeCheck()
  22. {
  23. for (int i = 0; i < 3; i++)
  24. {
  25. Shape newShape = new Shape();
  26. Shapes.Add(newShape);
  27. Shapes[i].ID = (i + 1);
  28. }
  29.  
  30. ShapesList = FindIntersections(Shapes);
  31. }
  32.  
  33. public static Dictionary<int, List<int>> FindIntersections(List<Shape> shapes)
  34. {
  35. Dictionary<int, List<int>> IntersectingShapes = new Dictionary<int, List<int>>();
  36. string result = "";
  37. string oneLineResult = "";
  38. List<string> finalResultLog = new List<string>();
  39.  
  40. for (int i = 0; i < shapes.Count; i++)
  41. {
  42. List<int> ids = new List<int>();
  43.  
  44. if (shapes[i].ID == 1) // if circle
  45. {
  46. ids.Add(shapes[1].ID); // add square to circles dictionary entry
  47. }
  48. else if (shapes[i].ID == 2) // if square
  49. {
  50. ids.Add(shapes[0].ID); // add circle to squares dictionary entry and
  51. ids.Add(shapes[2].ID); // add line to squares dictionary entry
  52. }
  53. else if (shapes[i].ID == 3) // if line
  54. {
  55. ids.Add(shapes[1].ID); // add square to lines dictionary entry
  56. }
  57.  
  58. IntersectingShapes.Add(shapes[i].ID, ids);
  59.  
  60. foreach (KeyValuePair<int, List<int>> ID in IntersectingShapes)
  61. {
  62. List<int> id = new List<int>();
  63. for (int k = 0; k < ID.Value.Count; k++)
  64. id.Add(ID.Value[k]);
  65.  
  66. result = shapes[i].ID + "->(" + ListToText(id) + ")";
  67.  
  68. }
  69. finalResultLog.Add(result);
  70. }
  71.  
  72. oneLineResult = (OneLineResultText(finalResultLog));
  73. Console.WriteLine(oneLineResult);
  74.  
  75. return IntersectingShapes;
  76. }
  77.  
  78. public static string ListToText(List<int> list)
  79. {
  80. string result = "";
  81.  
  82. foreach (var listMember in list)
  83. {
  84. if (list.Count > 0)
  85. {
  86. if (listMember != list[0])
  87. result += "," + listMember.ToString();
  88. else
  89. result += listMember.ToString();
  90. }
  91. }
  92. return result;
  93. }
  94.  
  95. public static string OneLineResultText(List<string> list)
  96. {
  97. string result = "";
  98. foreach (var listMember in list)
  99. {
  100. if (listMember != list[list.Count - 1])
  101. result += listMember.ToString() + ", ";
  102. else
  103. result += listMember.ToString();
  104. }
  105. return result;
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement