예제 #1
0
파일: Map.cs 프로젝트: kidsang/ProjectJ
        private bool DoCalculateCantBlockCells(MapCell start, MapCell end, int depth, HashSet<int> visited, Dictionary<int, int> depths, Dictionary<int, int> lows, Dictionary<int, int> parents)
        {
            int startKey = start.Key;
            visited.Add(startKey);
            depths[startKey] = depth;
            lows[startKey] = depth;
            int childCount = 0;
            bool isCutPoint = false;
            bool reachedEnd = false;
            int parentKey;

            foreach (MapCell neighbour in start.Neighbours)
            {
                if (neighbour == null || neighbour.IsObstacle)
                    continue;

                int neighbourKey = neighbour.Key;
                if (!visited.Contains(neighbourKey))
                {
                    parents[neighbourKey] = startKey;
                    reachedEnd = DoCalculateCantBlockCells(neighbour, end, depth + 1, visited, depths, lows, parents);
                    childCount += 1;
                    if (lows[neighbourKey] >= depths[startKey])
                        isCutPoint = true;
                    lows[startKey] = Mathf.Min(lows[startKey], lows[neighbourKey]);
                }
                else
                {
                    parentKey = -1;
                    if (parents.ContainsKey(startKey))
                        parentKey = parents[startKey];
                    if (neighbourKey != parentKey)
                        lows[startKey] = Mathf.Min(lows[startKey], depths[neighbourKey]);
                }
            }

            reachedEnd = reachedEnd || (start == end);

            parentKey = -1;
            if (parents.ContainsKey(startKey))
                parentKey = parents[startKey];
            if (parentKey != -1 && isCutPoint || parentKey == -1 && childCount > 1)
            {
                if (reachedEnd)
                    cantBlockCells.Add(startKey);
            }

            return reachedEnd;
        }
예제 #2
0
파일: Map.cs 프로젝트: kidsang/ProjectJ
 public int GetDistance(MapCell cell1, MapCell cell2)
 {
     return GetDistance(cell1.X, cell1.Y, cell2.X, cell2.Y);
 }
예제 #3
0
 protected override void OnRefresh(params object[] args)
 {
     cell = (MapCell)args[0];
 }
예제 #4
0
 protected override void OnHide()
 {
     cell = null;
 }
예제 #5
0
파일: MapCell.cs 프로젝트: kidsang/ProjectJ
        internal void Init(Map map, short x, short y)
        {
            CellObject = gameObject;
            Map = map;
            Loader = map.Loader;

            this.X = x;
            this.Y = y;
            this.Z = (short)(-x - y);
            this.Key = MapUtils.MakeKey(x, y);

            CellObject.transform.localPosition = new Vector3(CenterX, CenterY);

            Neighbours = new MapCell[NumNeighbours];
            SceneEntities = new List<SceneEntity>();
            TowerEntities = new List<SceneEntity>();
        }
예제 #6
0
        void Update()
        {
            if (!mouseIn)
                return;

            EditorMap map = GameEditor.Instance.Map;
            if (!map)
                return;

            Vector3 currentMousePosition = Input.mousePosition;
            if (currentMousePosition == lastMousePosition)
                return;

            //if (lastOverMapcell != null)
            //{
            //    lastOverMapcell.ToWhite();
            //    lastOverMapcell.ShowNeighbours(false);
            //}

            Vector3 worldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            lastOverMapcell = map.GetCellByWorldXY(worldPoint);
            if (lastOverMapcell != null)
            {
                //lastOverMapcell.ToBlue();
                //lastOverMapcell.ShowNeighbours(true);

                if (preview != null)
                {
                    preview.transform.position = lastOverMapcell.Position;
                    preview.transform.Translate(0, 0, -10 - preview.transform.localPosition.z);
                }
            }

            lastMousePosition = currentMousePosition;

            EventManager.Instance.FireEvent(EditorEvent.SCENE_MOUSE_OVER_CELL_CHANGE);
        }