Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- public class Shape
- {
- public int ID;
- }
- public class IntersectingSprites
- {
- public static List<Shape> Shapes = new List<Shape>();
- public static Dictionary<int, List<int>> ShapesList;
- [STAThread]
- static void Main()
- {
- ShapeCheck();
- }
- public static void ShapeCheck()
- {
- for (int i = 0; i < 3; i++)
- {
- Shape newShape = new Shape();
- Shapes.Add(newShape);
- Shapes[i].ID = (i + 1);
- }
- ShapesList = FindIntersections(Shapes);
- }
- public static Dictionary<int, List<int>> FindIntersections(List<Shape> shapes)
- {
- Dictionary<int, List<int>> IntersectingShapes = new Dictionary<int, List<int>>();
- string result = "";
- string oneLineResult = "";
- List<string> finalResultLog = new List<string>();
- for (int i = 0; i < shapes.Count; i++)
- {
- List<int> ids = new List<int>();
- if (shapes[i].ID == 1) // if circle
- {
- ids.Add(shapes[1].ID); // add square to circles dictionary entry
- }
- else if (shapes[i].ID == 2) // if square
- {
- ids.Add(shapes[0].ID); // add circle to squares dictionary entry and
- ids.Add(shapes[2].ID); // add line to squares dictionary entry
- }
- else if (shapes[i].ID == 3) // if line
- {
- ids.Add(shapes[1].ID); // add square to lines dictionary entry
- }
- IntersectingShapes.Add(shapes[i].ID, ids);
- foreach (KeyValuePair<int, List<int>> ID in IntersectingShapes)
- {
- List<int> id = new List<int>();
- for (int k = 0; k < ID.Value.Count; k++)
- id.Add(ID.Value[k]);
- result = shapes[i].ID + "->(" + ListToText(id) + ")";
- }
- finalResultLog.Add(result);
- }
- oneLineResult = (OneLineResultText(finalResultLog));
- Console.WriteLine(oneLineResult);
- return IntersectingShapes;
- }
- public static string ListToText(List<int> list)
- {
- string result = "";
- foreach (var listMember in list)
- {
- if (list.Count > 0)
- {
- if (listMember != list[0])
- result += "," + listMember.ToString();
- else
- result += listMember.ToString();
- }
- }
- return result;
- }
- public static string OneLineResultText(List<string> list)
- {
- string result = "";
- foreach (var listMember in list)
- {
- if (listMember != list[list.Count - 1])
- result += listMember.ToString() + ", ";
- else
- result += listMember.ToString();
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement