Example #1
0
        public void FindPlaceAndCreateNullor(Node node1, Node node2, string type)
        {
            string line      = "";
            int    row       = 0;
            int    column    = 0;
            int    id        = gameController.scheme.GetElementMaxId() + 1;
            string direction = "";

            var blockingElements = FindBlockingElements(node1, node2, ref direction);

            blockingElements.Remove(node1);
            blockingElements.Remove(node2);

            Norator  norator  = null;
            Nullator nullator = null;

            foreach (var elem in blockingElements)
            {
                if (elem is Norator)
                {
                    norator = (Norator)elem;
                }
                if (elem is Nullator)
                {
                    nullator = (Nullator)elem;
                }
            }

            blockingElements.Remove(norator);
            blockingElements.Remove(nullator);

            row    = direction == "U" ? node2.GetY() : node1.GetY();
            column = direction == "L" ? node2.GetX() : node1.GetX();

            if (!blockingElements.Any())
            {
                line = (direction == "R") || (direction == "L")
                    ? id + " " + (row - 1) + " " + (column + 4) + " R " + node1.GetId() + " " + node2.GetId()
                    : id + " " + (row + 4) + " " + (column - 1) + " D " + node1.GetId() + " " + node2.GetId();

                PlaceElement(ref line, type);

                int wireId = gameController.scheme.GetWireMaxId() + 1;
                int id1    = direction == "U" || direction == "L" ? node1.GetId() : node2.GetId();

                line = (direction == "R" || direction == "L")
                    ? wireId + " " + row + " " + column + " " + 6 + " R " + id1 + " N " + id + " E"
                    : wireId + " " + row + " " + column + " " + 6 + " D " + id1 + " N " + id + " E";

                PlaceWire(ref line);

                int length = (direction == "R") || (direction == "L")
                    ? Math.Abs(node1.GetX() - node2.GetX()) - 4
                    : Math.Abs(node1.GetY() - node2.GetY()) - 4;

                //Если элемент слишком короткий(т.е. он не дотягивается до второго узла), то лучше пририсовать ему провод, чтобы нормально все выглядело
                if (length > 8)
                {
                    wireId = gameController.scheme.GetWireMaxId() + 1;

                    id1 = direction == "U" || direction == "L" ? node2.GetId() : node1.GetId();

                    line = (direction == "R") || (direction == "L")
                        ? wireId + " " + row + " " + (column + 12) + " " + (length - 7) + " R " + id1 + " N " + id + " E"
                        : wireId + " " + (row + 12) + " " + column + " " + (length - 7) + " D " + id1 + " N " + id + " E";

                    PlaceWire(ref line);
                    line = "";
                }

                //Если у узлов не совпадают ни X, ни Y (здесь нужен будет еще один провод)
                if ((node1.GetX() != node2.GetX()) && (node1.GetY() != node2.GetY()))
                {
                    wireId = gameController.scheme.GetWireMaxId();

                    int wireRow    = 0;
                    int wireColumn = 0;

                    if ((direction == "R") || (direction == "L"))
                    {
                        wireRow    = node2.GetY() > node1.GetY() ? node1.GetY() : node2.GetY();
                        wireColumn = node2.GetX();
                    }
                    else
                    {
                        wireRow    = node2.GetY();
                        wireColumn = node2.GetX() > node1.GetX() ? node1.GetX() : node2.GetX();
                    }

                    length = (direction == "R") || (direction == "L")
                             ? Math.Abs(node1.GetY() - node2.GetY()) + 1
                             : Math.Abs(node1.GetX() - node2.GetX()) + 1;

                    line = (direction == "R") || (direction == "L")
                        ? (wireId + 1) + " " + wireRow + " " + wireColumn + " " + length + " D " + node1.GetId() + " N " + node2.GetId() + " N"
                        : (wireId + 1) + " " + wireRow + " " + wireColumn + " " + length + " R " + node1.GetId() + " N " + node2.GetId() + " N";

                    PlaceWire(ref line);
                    line = "";

                    line = (direction == "R") || (direction == "L")
                        ? (gameController.scheme.GetNodeMaxId() + 1) + " " + node1.GetY() + " " + node2.GetX()
                        : (gameController.scheme.GetNodeMaxId() + 1) + " " + node2.GetY() + " " + node1.GetX();
                    PlaceNode(ref line);
                    node2 = gameController.scheme.GetNode(gameController.scheme.GetNodeMaxId());
                }
            }
            else if (blockingElements.Count == 1)
            {
                //Если есть блокирующие элементы и нужно как-то считать положение элемента
                //TO DO
                direction = node1.GetY() == node2.GetY() ? "R" : "D";

                if (direction == "R" && node1.GetX() > node2.GetX())
                {
                    var temp = node1;
                    node1 = node2;
                    node2 = temp;
                }
                if (direction == "D" && node1.GetY() > node2.GetY())
                {
                    var temp = node1;
                    node1 = node2;
                    node2 = temp;
                }

                id   = gameController.scheme.GetElementMaxId() + 1;
                line = direction == "R"
                    ? id + " " + (node1.GetY() - 4) + " " + (node1.GetX() + 4) + " R " + node1.GetId() + " " + node2.GetId()
                    : id + " " + (node1.GetY() + 4) + " " + (node1.GetX() + 2) + " D " + node1.GetId() + " " + node2.GetId();
                PlaceElement(ref line, type);

                int wireId = gameController.scheme.GetWireMaxId() + 1;
                line = direction == "R"
                    ? wireId + " " + (node1.GetY() - 3) + " " + node1.GetX() + " 6 R " + id + " E"
                    : wireId + " " + node1.GetY() + " " + (node1.GetX() + 3) + " 6 D " + id + " E";
                PlaceWire(ref line);

                Wire wire1 = gameController.scheme.GetWire(wireId);

                wireId++;
                line = direction == "R"
                    ? wireId + " " + (node1.GetY() - 3) + " " + (node1.GetX() + 12) + " 6 R " + id + " E"
                    : wireId + " " + (node1.GetY() + 12) + " " + (node1.GetX() + 3) + " 6 D " + id + " E";
                PlaceWire(ref line);

                Wire wire2 = gameController.scheme.GetWire(wireId);

                wireId++;
                line = direction == "R"
                    ? wireId + " " + (node1.GetY() - 3) + " " + node1.GetX() + " 4 D " + node1.GetId() + " N"
                    : wireId + " " + node1.GetY() + " " + node1.GetX() + " 4 R " + node1.GetId() + " N";
                PlaceWire(ref line);

                Wire wire3 = gameController.scheme.GetWire(wireId);
                gameController.scheme.AddWireToObject(wire1, wire3);

                wireId++;
                line = direction == "R"
                    ? wireId + " " + (node2.GetY() - 3) + " " + node2.GetX() + " 4 D " + node2.GetId() + " N"
                    : wireId + " " + node2.GetY() + " " + node2.GetX() + " 4 R " + node2.GetId() + " N";
                PlaceWire(ref line);

                Wire wire4 = gameController.scheme.GetWire(wireId);
                gameController.scheme.AddWireToObject(wire2, wire4);
            }
        }
Example #2
0
        public void PlaceWire(ref string line)
        {
            int id = Int32.Parse(GetSubString(ref line, line.IndexOf(' ')));

            int startRow    = Int32.Parse(GetSubString(ref line, line.IndexOf(' ')));
            int startColumn = Int32.Parse(GetSubString(ref line, line.IndexOf(' ')));

            int length = Int32.Parse(GetSubString(ref line, line.IndexOf(' ')));

            string direction = GetSubString(ref line, 1);

            int    id1   = Int32.Parse(GetSubString(ref line, line.IndexOf(' ')));
            string type1 = GetSubString(ref line, 1);
            object obj1  = null;

            if (type1 == "N")
            {
                obj1 = gameController.scheme.GetNode(id1);
            }
            else
            {
                obj1 = gameController.scheme.GetElement(id1);
            }

            object obj2 = null;

            if (line != "")
            {
                int    id2   = Int32.Parse(GetSubString(ref line, line.IndexOf(' ')));
                string type2 = GetSubString(ref line, 1);
                if (type2 == "N")
                {
                    obj2 = gameController.scheme.GetNode(id2);
                }
                else
                {
                    obj2 = gameController.scheme.GetElement(id2);
                }
            }

            Wire wire = new Wire(id, startRow, startColumn);

            gameController.scheme.AddWireToObject(wire, obj1);
            gameController.scheme.AddWireToObject(wire, obj2);

            gameController.scheme.AddWire(wire);

            wire.GetImage().SetValue(Grid.RowProperty, startRow);
            wire.GetImage().SetValue(Grid.ColumnProperty, startColumn);
            wire.GetImage().SetValue(Panel.ZIndexProperty, 1);


            if (direction == "R")
            {
                wire.ChangeImageDirectionToLand();
                wire.GetImage().SetValue(Grid.ColumnSpanProperty, length);
            }
            else
            {
                wire.GetImage().SetValue(Grid.RowSpanProperty, length);
            }

            gameController.gameWindow.GameGrid.Children.Add(wire.GetImage());

            if (direction == "R")
            {
                double marginDistance  = gameController.gameWindow.GameGrid.ActualWidth / 70 / 2;
                wire.GetImage().Margin = new Thickness(marginDistance, 0, marginDistance, 0); //Попытка добавить marginProperty к ячейке, в которой записана картинка
            }
            else
            {
                double marginDistance  = gameController.gameWindow.GameGrid.ActualHeight / 50 / 2;
                wire.GetImage().Margin = new Thickness(0, marginDistance, 0, marginDistance); //Попытка добавить marginProperty к ячейке, в которой записана картинка
            }
        }