예제 #1
0
        public void AddPathBlock(PathBlock pathBlock)
        {
            int value = 0;

            switch (pathBlock.GetType())
            {
                case PathBlockEnum.NORMAL:
                    value = 1;
                    break;
                case PathBlockEnum.SPAWN:
                    value = 2;
                    break;
                case PathBlockEnum.GOAL:
                    value = 3;
                    break;
                default:
                    break;
            }

            if (IsConnectedToOtherPathBlock(pathBlock)&&((pathBlock.IsSpawn()&&GetSpawn()==null)||(pathBlock.IsGoal()&&GetGoal()==null&&GetSpawn()!=null)||(pathBlock.IsNormal()&&GetGoal()==null)))
            {
                grid[(int)pathBlock.GetPosition().X, (int)pathBlock.GetPosition().Y] = value;
                path.Add(pathBlock);
                route.path.Add(pathBlock.GetPosition());
            }
        }
예제 #2
0
        private bool IsConnectedToOtherPathBlock(PathBlock pathBlock)
        {
            Vector2 pos = pathBlock.GetPosition();

            if (pathBlock.IsNormal())
            {
                Vector2 north = new Vector2(0, -1) + pos;
                Vector2 south = new Vector2(0, 1) + pos;
                Vector2 east = new Vector2(1, 0) + pos;
                Vector2 west = new Vector2(-1, 0) + pos;

                int n = 0;
                int s = 0;
                int e = 0;
                int w = 0;

                if (!IsOutOfGrid(north))
                    n = grid[((int)north.X), ((int)north.Y)];
                if (!IsOutOfGrid(south))
                    s = grid[((int)south.X), ((int)south.Y)];
                if (!IsOutOfGrid(east))
                    e = grid[((int)east.X), ((int)east.Y)];
                if (!IsOutOfGrid(west))
                    w = grid[((int)west.X), ((int)west.Y)];

                if ((n > 0 && n < 4) ||
                    (s > 0 && s < 4) ||
                    (e > 0 && e < 4) ||
                    (w > 0 && w < 4))
                {
                    return true;
                }

            }
            else
                return true;

            return false;
        }