Beispiel #1
0
        private void FindPath(TCell desiredCell)
        {
            var treePath = new List <TCell>();

            treePath.Add(CurrentCell);
            if (desiredCell == CurrentCell)
            {
                return;
            }

            for (var i = 0; i < treePath.Count; i++)
            {
                var cell       = treePath[i];
                var neighbours = cell.Neighbours;

                if (cell == desiredCell)
                {
                    break;
                }
                foreach (var neighbour in neighbours)
                {
                    if (neighbour.Piece == null || neighbour == desiredCell)
                    {
                        neighbour.Parent = cell;
                        treePath.Add(neighbour);
                    }
                }
            }
            Path = new List <TCell>();
            var parentCell = desiredCell;

            while (parentCell != null)
            {
                Path.Add(parentCell);
                parentCell = parentCell.Parent;
            }

            Path.Reverse();

            foreach (var cell in treePath)
            {
                cell.Parent = null;
            }
        }
Beispiel #2
0
 public void MoveToCell(TCell cell)
 {
     ScrollPos = new PointF((float)cell.X / Game.Map.Width, (float)cell.Y / Game.Map.Height);
 }