Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Diagnostics.Metrics;
- using System.Numerics;
- namespace Genius_tests
- {
- public class Part
- {
- public string PartName { get; set; }
- public Vector3 Position { get; set; }
- private PartState PartState = PartState.Idle;
- public PartState CurrentState { get { return PartState; } }
- public int Id; // оказывается рекурсия это плохо
- public int _Id {
- get
- {
- return Id;
- }
- private set
- {
- Id = value;
- }
- }
- public void AttachToPoint(Vector3 newstate)
- {
- Position = newstate;
- PartState = PartState.Installed;
- }
- public Part Clone()
- {
- return new Part(PartName,Position, Id);
- }
- public Part(string name, Vector3 pos, int id)
- {
- PartName = name;
- Position = pos;
- Id = id;
- }
- }
- public class PartFactory
- {
- public static List<string> partsList = new() { "truba", "glue", "tape","zaglushka" };
- public static List<Vector3> vecPosition = new() { new Vector3(1,1,1), new Vector3(2, 1, 3), new Vector3(0, 0, 0), new Vector3(7, 2, 7) };
- public static int currentPartsListIndex = 0 ;
- public static Part Spawn()
- {
- Part subject = new Part(PartFactory.partsList[PartFactory.currentPartsListIndex], PartFactory.vecPosition[PartFactory.currentPartsListIndex], PartFactory.currentPartsListIndex);
- Part detail = subject.Clone();
- currentPartsListIndex++;
- return detail;
- }
- }
- public class JointPoint
- {
- public static List<Vector3> fixedPosition = new() {new Vector3(9,9,9), new Vector3(10, 10, 10), new Vector3(20, 20, 20), new Vector3(30, 30, 30), };
- public static List<int> suitableID = new() {0, 2, 1, 3 }; //здесь порядок в котором должны парты садиться на новые координаты.
- public static List<bool> enabled = new() {true, true, true, true};
- public static void Check(Part detail)
- {
- int counter = 0; // вот это разобрать бы
- foreach (var detailFind in suitableID)
- {
- if (enabled[detailFind] == true)
- {
- if (detailFind == detail.Id)
- {
- detail.AttachToPoint(fixedPosition[counter]);
- //enabled[counter] = false; было так, не работало
- enabled[detail.Id] = false;
- }
- }
- counter++;
- }
- }
- }
- public enum PartState
- {
- Idle,
- Installed
- }
- public class test
- {
- public static void Main()
- {
- Console.WriteLine("Enter any key...");
- string? startP = Console.ReadLine();
- // здесь более точный вывод
- /*for (int i = 0; i < 4; i++)
- {
- Console.WriteLine("Trying to create first detail:\n");
- Part Detail = PartFactory.Spawn();
- Console.WriteLine($"created detail with index: {PartFactory.currentPartsListIndex - 1}");
- Console.WriteLine("it's pos: " + Detail.Position);
- Console.WriteLine("attempt to connect w/ joint point");
- JointPoint.Check(Detail);
- Console.WriteLine("new coordinates:" + Detail.Position);
- Console.WriteLine("Enter any key to continue: ");
- startP = Console.ReadLine();
- }*/
- List<Part> detailList = new();
- for (int i = 0; i < 10; i++)
- {
- if (PartFactory.currentPartsListIndex>3)
- {
- Console.WriteLine("out of details! список кончился \n");
- break;
- }
- detailList.Add(PartFactory.Spawn());
- }
- //List<Part> detailList = new() { PartFactory.Spawn(), PartFactory.Spawn(), PartFactory.Spawn(), PartFactory.Spawn() };
- for (int i = 0; i < 4; i++)
- {
- if (detailList[i].CurrentState == PartState.Idle)
- {
- Console.WriteLine("ID of detail:" + detailList[i].Id);
- Console.WriteLine("old coordinates:" + detailList[i].Position);
- JointPoint.Check(detailList[i]);
- Console.WriteLine("new coordinates:" + detailList[i].Position + "\n");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement