private void CopyLocationValue(object sender, EventArgs e) { LocNode node = (LocNode)trvHierarchy.SelectedNode; Clipboard.Clear(); Clipboard.SetText(node.Location.Code); }
private void enqueueNodeBFS(Queue <LocNode> queue, LocNode node, int rowRel, int columnRel) { if (nodeExists(node.row + rowRel, node.column + columnRel) && !getNode(node.row + rowRel, node.column + columnRel).visited) { getNode(node.row + rowRel, node.column + columnRel).visited = true; getNode(node.row + rowRel, node.column + columnRel).cameFrom = node; queue.Enqueue(getNode(node.row + rowRel, node.column + columnRel)); } }
private void LocationNodeSelected(object sender, TreeViewEventArgs e) { tabLocation.SelectedIndex = 0; LocNode node = (LocNode)e.Node; Location loc = node.Location; txtLocation.Text = loc.Code; txtStatus.Text = ActionStatuses.ToString(loc.ActionStatus); ShowChangeableValue(loc.Description, txtDescriptionNew, txtDescriptionCurr); ShowChangeableValue(loc.Parent, txtParentNew, txtParentCurr); }
public Stack <LocNode> getPath(int _row, int _col) { LocNode node = walkGraph.BFS(row, column, _row, _col); Stack <LocNode> stack = new Stack <LocNode>(); while (node.row != row || node.column != column) { stack.Push(node); node = node.cameFrom; } stack.Push(node); return(stack); }
// Update is called once per frame void Update() { Debug.Log(gs); if (selectedSquare != null) { selectedSquare.SetColor(new Color(200, 200, 0, 100)); } switch (gs) { case gameState.MOVING: //when the game is moving units //does nothing break; case gameState.PLACING: //when the game is placing units if (path == null) { path = map.Players[turn].GetSelectedUnit().getPath(goalNode.row, goalNode.column); } if (map.Players[turn].GetSelectedUnit().transform.position.x != goalNode.x || map.Players[turn].GetSelectedUnit().transform.position.y != goalNode.y) { if (currentNode == null) { currentNode = path.Pop(); } map.Players[turn].GetSelectedUnit().moveToPoint(currentNode.x, currentNode.y); if (map.Players[turn].GetSelectedUnit().transform.position.x == currentNode.x && map.Players[turn].GetSelectedUnit().transform.position.y == currentNode.y) { currentNode = null; } } if (map.Players[turn].GetSelectedUnit().transform.position.x == goalNode.x && map.Players[turn].GetSelectedUnit().transform.position.y == goalNode.y) { map.Players[turn].GetSelectedUnit().placeUnit(goalNode.row, goalNode.column); map.Players[turn].GetSelectedUnit().active = false; path = null; currentNode = null; map.Players[turn].SelectedUnit(null); if (map.Players[turn].AllUnactive()) { NextTurn(); } GameMapping.map.ChangeSelected(null); map.gs = gameState.MOVING; } break; case gameState.ATTACKING: //when a unit is attacking another unit break; } }
public void setWalkRangeGrid() { walkGraph = new LocGraph(mvt, row, column); walkGraph.setDrawX(transform.position.x); walkGraph.setDrawY(transform.position.y); Queue <LocNode> queue = new Queue <LocNode>(); walkGraph.addNode(row, column, column, (GameMapping.map.unitMap.GetLength(0) - 1) - row, 0); queue.Enqueue(walkGraph.getNode(row, column)); int count = queue.Count; int idx = 0; while (idx < mvt) { while (count > 0) { LocNode node = queue.Dequeue(); count--; if (node.row - 1 >= 0 && !GameMapping.map.occupied[node.row - 1, node.column] && !walkGraph.nodeExists(node.row - 1, node.column)) { walkGraph.addNode(node.row - 1, node.column, node.x, node.y + 1, idx); queue.Enqueue(walkGraph.getNode(node.row - 1, node.column)); } if (node.column + 1 < GameMapping.map.occupied.GetLength(1) && !GameMapping.map.occupied[node.row, node.column + 1] && !walkGraph.nodeExists(node.row, node.column + 1)) { walkGraph.addNode(node.row, node.column + 1, node.x + 1, node.y, idx); queue.Enqueue(walkGraph.getNode(node.row, node.column + 1)); } if (node.row + 1 < GameMapping.map.occupied.GetLength(0) && !GameMapping.map.occupied[node.row + 1, node.column] && !walkGraph.nodeExists(node.row + 1, node.column)) { walkGraph.addNode(node.row + 1, node.column, node.x, node.y - 1, idx); queue.Enqueue(walkGraph.getNode(node.row + 1, node.column)); } if (node.column - 1 >= 0 && !GameMapping.map.occupied[node.row, node.column - 1] && !walkGraph.nodeExists(node.row, node.column - 1)) { walkGraph.addNode(node.row, node.column - 1, node.x - 1, node.y, idx); queue.Enqueue(walkGraph.getNode(node.row, node.column - 1)); } } count = queue.Count; idx++; } }
public void addNode(int row, int column, float x, float y, int val) { LocNode node = new LocNode(); node.row = row; node.column = column; node.x = x; node.y = y; node.val = val; int placedRow = (row - mapRow) + centerIdx; int placedColumn = (column - mapCol) + centerIdx; nodes[placedRow, placedColumn] = node; elementsExists[placedRow, placedColumn] = true; }
private bool FindLocation(LocNode node, string findText) { if (node.Location.Match(findText)) { trvHierarchy.SelectedNode = node; return(true); } foreach (LocNode child in node.Nodes) { if (FindLocation(child, findText)) { return(true); } } return(false); }
private void FindLocation() { if (trvHierarchy.Nodes.Count < 1) { return; } if (tstFindLocation.Text.Length < 1) { return; } LocNode startNode = (LocNode)trvHierarchy.SelectedNode; if (startNode == null) { startNode = (LocNode)trvHierarchy.Nodes[0]; } FindLocation(startNode, tstFindLocation.Text); }
public LocNode BFS(int startRow, int startCol, int row, int column) { Queue <LocNode> queue = new Queue <LocNode>(); queue.Enqueue(getNode(startRow, startCol)); while (queue.Count != 0) { LocNode node = queue.Dequeue(); if (node.row == row && node.column == column) { return(node); } for (int i = -1; i <= 1; i += 2) { enqueueNodeBFS(queue, node, i, 0); enqueueNodeBFS(queue, node, 0, i); } } return(null); }