public Terminal Clone() { var clone = (Terminal)MemberwiseClone(); clone.BaseElement = BaseElement.Clone(); return(clone); }
protected override bool MouseDown(MouseButtonEventArgs args) { MouseElement = element.Clone(); if (element is LaserMonochrome laser) { laser.Wavelength = Utility.random.Next(400, 650); } return(true); }
public Tree ReplaceSellLCNode(int index, BaseElement subTree) { var newTree = Clone(); // 特殊処理 if (index == 1 || index == 2) { newTree.SellLCRoot.ChildrenNodes[index - 1] = subTree; return(newTree); } var root = newTree.SellLCRoot; var queue = new Queue <BaseElement>(); for (int i = 0; i < root.ChildrenCount; i++) { root.ChildrenNodes[i].ParentNode = SellLCRoot; queue.Enqueue(root.ChildrenNodes[i]); } while (queue.Count != 0) { var tempNode = queue.Dequeue(); index--; if (index == 0) { BaseElement parent = tempNode.ParentNode; for (int i = 0; i < parent.ChildrenCount; i++) { if (parent.ChildrenNodes[i].Equals(tempNode)) { parent.ChildrenNodes[i] = subTree.Clone(); newTree.SellLCRoot = root; return(newTree); } } } for (int i = 0; i < tempNode.ChildrenCount; i++) { tempNode.ChildrenNodes[i].ParentNode = tempNode; queue.Enqueue(tempNode.ChildrenNodes[i]); } } return(null); }
public Tree ReplaceBuyNode(int index, BaseElement subTree) { var newTree = Clone(); var queue = new Queue <BaseElement>(); // 特殊処理 if (index == 1 || index == 2) { newTree.BuyRoot.ChildrenNodes[index - 1] = subTree.Clone(); // parentNodeの参照削除 queue.Clear(); queue.Enqueue(newTree.BuyRoot.ChildrenNodes[index - 1]); while (queue.Count != 0) { var node = queue.Dequeue(); node.ParentNode = null; for (int j = 0; j < node.ChildrenCount; j++) { queue.Enqueue(node.ChildrenNodes[j]); } } return(newTree); } var root = newTree.BuyRoot; for (int i = 0; i < root.ChildrenCount; i++) { root.ChildrenNodes[i].ParentNode = BuyRoot; queue.Enqueue(root.ChildrenNodes[i]); } while (queue.Count != 0) { var tempNode = queue.Dequeue(); index--; if (index == 0) { BaseElement parent = tempNode.ParentNode; for (int i = 0; i < parent.ChildrenCount; i++) { if (parent.ChildrenNodes[i].Equals(tempNode)) { parent.ChildrenNodes[i] = subTree.Clone(); newTree.BuyRoot = root; // parentNodeの参照削除 queue.Clear(); queue.Enqueue(newTree.BuyRoot); while (queue.Count != 0) { var node = queue.Dequeue(); node.ParentNode = null; for (int j = 0; j < node.ChildrenCount; j++) { queue.Enqueue(node.ChildrenNodes[j]); } } return(newTree); } } } for (int i = 0; i < tempNode.ChildrenCount; i++) { tempNode.ChildrenNodes[i].ParentNode = tempNode; queue.Enqueue(tempNode.ChildrenNodes[i]); } } return(null); }