Пример #1
0
        private void GetDataTopicTri(string facId)
        {
            DataTable dtgridtri = GetDataTopTri(facId);

            GridDate.DataSource = dtgridtri;
            GridDate.DataBind();
        }
Пример #2
0
        private void GetDataTopicDual(string coId)
        {
            DataTable dtgridtri = GetDataTopDual(coId);

            GridDate.DataSource = dtgridtri;
            GridDate.DataBind();
        }
Пример #3
0
        private void GetDateTopic()
        {
            cCoId = Convert.ToInt32(txtCoId.Text);
            DataTable gridmarks = GetSearchDataTopic(cCoId);

            GridDate.DataSource = gridmarks;
            GridDate.DataBind();
        }
Пример #4
0
 /// <summary>
 /// 把格子加入危险区域
 /// </summary>
 /// <param name="grid">判定格子</param>
 /// <param name="isCreateBombInDir">是否在该方向创建炸弹</param>
 void AddGridToDangerousList(GridDate grid, ref List <GridDate> dangerousGridList, ref bool isCreateBombInDir)
 {
     // 如果该格子不能移动,不在该方向继续创建炸弹并退出
     if (!_map.IsPassGrid(grid))
     {
         isCreateBombInDir = false;
         return;
     }
     // 把该格子加入危险区域列表
     dangerousGridList.Add(grid);
 }
Пример #5
0
    /// <summary>
    /// 当距离格子大于5时,将障碍物加入列表,并移动到距离最近的格子
    /// </summary>
    void MoveObstacle()
    {
        //获取敌人当前格子
        Grid nowGrid = _map.GetGrid(transform.position);

        obstacleList.Clear();

        // 获取和原地图一致的地图记录障碍
        int[,] obstacleMap = _map.GetCopyMap();
        //将所有障碍物加入列表
        for (int obstacleRows = 0; obstacleRows < obstacleMap.GetLength(0); obstacleRows++)
        {
            for (int obstacleColumns = 0; obstacleColumns < obstacleMap.GetLength(1); obstacleColumns++)
            {
                if (obstacleMap [obstacleRows, obstacleColumns] == 3)
                {
                    obstacleList.Add(new GridDate(obstacleRows, obstacleColumns));
                }
            }
        }

        // 如果障碍物列表为空,退出
        if (obstacleList.Count == 0)
        {
            return;
        }

        //找出距离最近的格子
        GridDate latelyGrid = obstacleList [0];
        //算出列表第一个障碍的理论步数
        int theoreticalStep = nowGrid.CalcMoveCount(latelyGrid);

        //遍历列表中所有障碍,算出最小理论步数的格子,并获取此格子
        for (int obstacleListIndex = 1; obstacleListIndex < obstacleList.Count; obstacleListIndex++)
        {
            if (nowGrid.CalcMoveCount(obstacleList [obstacleListIndex]) < theoreticalStep)
            {
                theoreticalStep = nowGrid.CalcMoveCount(obstacleList [obstacleListIndex]);

                latelyGrid = obstacleList [obstacleListIndex];
            }

            /*	//将列表中不是敌人上下左右四个方向上的障碍删除
             * for(int i=obstacleList.Count;i>=0;i--){
             * if (nowGrid.CalcMoveCount (obstacleList[i]) > 3){
             *      obstacleList.Remove (obstacleList[i]);
             * }
             *
             * }*/
        }
        //声明最近的障碍路径,并存入列表
        List <GridDate> latelyGridList = new List <GridDate>();

        // 把障碍物暂时设为通路,方便寻路
        _map._Map [latelyGrid.Rows, latelyGrid.Columns] = 1;
        latelyGridList = FindingPath(nowGrid, latelyGrid);
        // 重新设为障碍物
        _map._Map [latelyGrid.Rows, latelyGrid.Columns] = 3;

        //  没有找到路径,退出
        if (latelyGridList.Count < 2)
        {
            return;
        }

        //遍历列表,删除障碍所在的格子
        latelyGridList.RemoveAt(latelyGridList.Count - 1);
        // 移动路径等于最小移动路径
        SetPathVarDefault();
        path = latelyGridList;
        //获取目的地位置
        Grid destination = latelyGridList [latelyGridList.Count - 1];

        //如果敌人到达目的位置,则开始放炸弹
        IsCanPutDownBomb(destination);

        // 打印移动路径
        //Debug.Log ("Obstacle");
        PrintPath(path);
    }
Пример #6
0
    /// <summary>
    ///判断是否在危险区域
    /// </summary>
    public bool IsDangerousArea(Grid nowGrig)
    {
        // 清空危险区域,安全区域
        dangerousList.Clear();
        safeList.Clear();

        Bomb bomb;

        //获取所有炸弹脚本
        Bomb [] _bombnum = GameObject.FindObjectsOfType <Bomb> ();

        // 获取和原地图一致的地图记录危险区域
        _dangerousMap = _map.GetCopyMap();

        bool isCreateUpBomb, isCreateDownBomb, isCreateLeftBomb, isCreateRightBomb;

        //获取所有炸弹的危险格子加入危险列表
        for (int bombIndex = 0; bombIndex < _bombnum.Length; bombIndex++)
        {
            bomb = _bombnum [bombIndex];
            //地图更新
            //_map.GetGrid(bomb.transform.position);

            // 获取炸弹所在格子
            Grid bombGrid = _map.GetGrid(bomb.transform.position);
            // 炸弹格子上下左右可以设置为危险区域
            isCreateUpBomb = isCreateDownBomb = isCreateLeftBomb = isCreateRightBomb = true;
            //遍历威力,找出危险格子,并存入危险列表
            dangerousList.Add(new GridDate(bombGrid.Rows, bombGrid.Columns));
            for (int dangerIndex = 0; dangerIndex < bomb.j; dangerIndex++)
            {
                //炸弹上方的危险区域
                if (isCreateUpBomb)
                {
                    AddGridToDangerousList(new GridDate(bombGrid.Rows + dangerIndex, bombGrid.Columns),
                                           ref dangerousList, ref isCreateUpBomb);
                }

                //炸弹下方的危险区域
                if (isCreateDownBomb)
                {
                    AddGridToDangerousList(new GridDate(bombGrid.Rows - dangerIndex, bombGrid.Columns),
                                           ref dangerousList, ref isCreateDownBomb);
                }

                //炸弹右方的危险区域
                if (isCreateRightBomb)
                {
                    AddGridToDangerousList(new GridDate(bombGrid.Rows, bombGrid.Columns + dangerIndex),
                                           ref dangerousList, ref isCreateRightBomb);
                }

                //炸弹左方的危险区域
                if (isCreateLeftBomb)
                {
                    AddGridToDangerousList(new GridDate(bombGrid.Rows, bombGrid.Columns - dangerIndex),
                                           ref dangerousList, ref isCreateLeftBomb);
                }
            }
        }

        if (_bombnum.Length == 0)
        {
            return(false);
        }

        // 在地图上把危险区域标出来
        for (int i = 0; i < dangerousList.Count; i++)
        {
            _dangerousMap [dangerousList[i].Rows, dangerousList[i].Columns] = 99;
        }

        //  遍历整张地图,把安全区域加入列表
        for (int i = 0; i < _dangerousMap.GetLength(0); i++)
        {
            for (int j = 0; j < _dangerousMap.GetLength(1); j++)
            {
                if (_dangerousMap [i, j] == 1)
                {
                    safeList.Add(new GridDate(i, j));
                }
            }
        }

        /*
         * //将所有路的格子为危险格子的删掉
         * for (int pathListIndex = safeList.Count - 1; pathListIndex >= 0; pathListIndex--) {
         *      for (int dangerousListIndex = 0; dangerousListIndex < dangerousList.Count; dangerousListIndex++) {
         *              if (safeList [pathListIndex] == dangerousList [dangerousListIndex]) {
         *                      safeList.Remove (safeList [pathListIndex]);
         *              }
         *      }
         * }
         */
        //判断敌人是否在安全区域
        return(!GridDate.IsList(safeList, nowGrig.Rows, nowGrig.Columns));

        /*for (int direnSafe = 0; direnSafe < safeList.Count; direnSafe++) {
         *      //如果敌人在安全区域,返回为真否则进行躲避危险行为
         *      if (nowGrig.Rows == safeList [direnSafe].Rows && nowGrig.Columns == safeList [direnSafe].Columns) {
         *              return true;
         *      }
         *
         * }
         *
         * return false;*/
    }
Пример #7
0
    public List <GridDate> FindingPath(Grid now, Grid target)
    {
        _openList.Clear();
        _closeList.Clear();
        _isFindPath = false;
        path.Clear();

        GridDate nowData = new GridDate(now.Rows, now.Columns);

        /*_map.Rows = 2;
         * _map.Columns = 11;
         */

        //敌人初始位置
        //GridDate _direnGrid=new GridDate(_map.Rows,_map.Columns);

        _openList.Add(nowData);         //将初始位置加入到开启列表
        //获取初始格子
        //GridDate _mingrid=_openList[0];
        //获取玩家坐标
        //Vector2 pos2=GameObject.Find("Player").transform.position;
        bool isFindTarget = false;

        do
        {
            GridDate _mingrid = _openList[0];
            _mingrid._gCost = 0;

            //gridDate._hCost = (pos2.x - _mingrid.Rows) + (pos2.y - _mingrid.Columns);
            //遍历开启列表,获取权值最小的格子,如果列表中有玩家位置,则跳出
            //Debug.Log(_mingrid);
            for (int i = 0; i < _openList.Count; i++)
            {
                if (_openList[i]._fCost < _mingrid._fCost)
                {
                    _mingrid = _openList[i];
                }
                if (_openList[i].Rows == target.Rows && _openList[i].Columns == target.Columns)
                {
                    isFindTarget = true;

                    //List<GridDate> path = new List<GridDate>();

                    GridDate nowGrid = _openList[i];
                    path.Add(nowGrid);
                    do
                    {
                        nowGrid = nowGrid._writeGrid;
                        if (nowGrid == null)
                        {
                            break;
                        }
                        path.Insert(0, nowGrid);
                    }while(true);



                    string strPath = string.Empty;
                    for (int pathIndex = 0; pathIndex < path.Count; pathIndex++)
                    {
                        strPath += string.Format("{0}\n", path[pathIndex]);
                    }
                    //Debug.Log(strPath);


                    break;
                }
            }

            //在开启列表中删除此格子,并将格子加入关闭列表
            _openList.Remove(_mingrid);
            _closeList.Add(_mingrid);

            if (isFindTarget)
            {
                break;
            }
            //如果获取的最小权值的格子上一格可以移动并且没有在关闭列表中,添加到开启列表
            if (IsAIPassGrid(_mingrid.Rows + 1, _mingrid.Columns) &&
                !GridDate.IsList(_closeList, _mingrid.Rows + 1, _mingrid.Columns))
            {
                GridDate newUpGrid = new GridDate(_mingrid.Rows + 1, _mingrid.Columns);
                _openList.Add(newUpGrid);
                //记录前一个格子
                newUpGrid._writeGrid = _mingrid;
                //敌人移动步数+1
                newUpGrid._gCost = _mingrid._gCost + 1;
                //加入到open列表的格子距离玩家步数
                newUpGrid._hCost = newUpGrid.CalcMoveCount(target);
            }

            //Debug.Log(_openList.Count);

            //如果获取的最小权值的格子下一格可以移动并且没有在关闭列表中,添加到开启列表
            if (IsAIPassGrid(_mingrid.Rows - 1, _mingrid.Columns) &&
                !GridDate.IsList(_closeList, _mingrid.Rows - 1, _mingrid.Columns))
            {
                GridDate newDownGrid = new GridDate(_mingrid.Rows - 1, _mingrid.Columns);
                _openList.Add(newDownGrid);
                //记录前一个格子
                newDownGrid._writeGrid = _mingrid;
                //敌人移动步数+1
                newDownGrid._gCost = _mingrid._gCost + 1;
                //加入到open列表的格子距离玩家步数
                newDownGrid._hCost = newDownGrid.CalcMoveCount(target);
            }
            //如果获取的最小权值的格子左一格可以移动并且没有在关闭列表中,添加到开启列表
            if (IsAIPassGrid(_mingrid.Rows, _mingrid.Columns - 1) &&
                !GridDate.IsList(_closeList, _mingrid.Rows, _mingrid.Columns - 1))
            {
                GridDate newLeftGrid = new GridDate(_mingrid.Rows, _mingrid.Columns - 1);

                _openList.Add(newLeftGrid);
                //记录前一个格子
                newLeftGrid._writeGrid = _mingrid;
                //敌人移动步数+1
                newLeftGrid._gCost = _mingrid._gCost + 1;
                //加入到open列表的格子距离玩家步数
                newLeftGrid._hCost = newLeftGrid.CalcMoveCount(target);
            }
            //如果获取的最小权值的格子右一格可以移动并且没有在关闭列表中,添加到开启列表
            if (IsAIPassGrid(_mingrid.Rows, _mingrid.Columns + 1) &&
                !GridDate.IsList(_closeList, _mingrid.Rows, _mingrid.Columns + 1))
            {
                GridDate newRightGrid = new GridDate(_mingrid.Rows, _mingrid.Columns + 1);
                _openList.Add(newRightGrid);
                //记录前一个格子
                newRightGrid._writeGrid = _mingrid;
                //敌人移动步数+1
                newRightGrid._gCost = _mingrid._gCost + 1;
                //加入到open列表的格子距离玩家步数
                newRightGrid._hCost = newRightGrid.CalcMoveCount(target);
            }

            //Debug.LogFormat("_openList.Count:{0} _closeList.Count:{1}",
            //	_openList.Count, _closeList.Count);
        }while(_openList.Count > 0);
        return(path);
    }
Пример #8
0
    /// <summary>
    ///AI移动
    /// </summary>
    public void Move()
    {
        if (!_isFindPath || path == null || path.Count == 0)
        {
            return;
        }

        //Debug.LogFormat ("movePath:{0} {1}", _pathIndex, path.Count);
        // 如果移动到最后一个格子,清空路径
        if (_pathIndex >= path.Count)
        {
            _pathIndex  = 0;
            _isFindPath = false;
            path.Clear();

            if (_isRunAIAcition)
            {
                AiAction();
            }
            Debug.Log("清空路径");
            return;
        }

        // 获取当前目标格子
        GridDate target = path[_pathIndex];
        // 获取当前角色所在格子
        Grid now = _map.GetGrid(transform.position);

        if (_pathIndex > 0)
        {
            now = path[_pathIndex - 1];
        }

        // 获取目标格子坐标
        Vector2 targetPos = _map.GetGridPos(target);

        //Debug.LogFormat ("{0}->{1}", now, target);
        //Debug.LogFormat ("{0}->{1}", transform.position, targetPos);

        // 如果是初始移动,把玩家移到格子中间
        if (_pathIndex == 0)
        {
            // 如果就在当前格子,把角色移动到当前格子
            if (path.Count == 1)
            {
                // 如果y值相等,x方向移动
                if (Mathf.Approximately(targetPos.y, transform.position.y))
                {
                    // 如果x方向也相等,退出
                    if (Mathf.Approximately(targetPos.x, transform.position.x))
                    {
                        _pathIndex++;

                        if (_isRunAIAcition)
                        {
                            AiAction();
                        }
                        return;
                    }
                    // x不相等,往x方向移动
                    if (targetPos.x > transform.position.x)
                    {
                        // 目标点在当前点右边,往右移动
                        transform.Translate(_spd * Time.deltaTime, 0, 0);
                        //Debug.LogFormat ("you {0} {1}", transform.position.x, targetPos.x);
                        if (transform.position.x >= targetPos.x)
                        {
                            transform.position = new Vector2(targetPos.x, transform.position.y);
                            _pathIndex++;

                            if (_isRunAIAcition)
                            {
                                AiAction();
                            }
                        }
                    }
                    else
                    {
                        // 目标点在当前点左边,往左移动
                        transform.Translate(-_spd * Time.deltaTime, 0, 0);
                        //Debug.LogFormat ("zuo {0} {1}", transform.position.x, targetPos.x);
                        if (transform.position.x <= targetPos.x)
                        {
                            transform.position = new Vector2(targetPos.x, transform.position.y);
                            _pathIndex++;

                            if (_isRunAIAcition)
                            {
                                AiAction();
                            }
                        }
                    }
                }
                if (transform.position.y > targetPos.y)
                {
                    // 向xia移动
                    transform.Translate(0, -_spd * Time.deltaTime, 0);
                    if (transform.position.y <= targetPos.y)
                    {
                        transform.position = new Vector2(transform.position.x, targetPos.y);
                    }
                }
                else
                {
                    // 向shang移动
                    transform.Translate(0, _spd * Time.deltaTime, 0);
                    if (transform.position.y >= targetPos.y)
                    {
                        transform.position = new Vector2(transform.position.x, targetPos.y);
                    }
                }
                // 如果y值不相等,y方向移动
                return;
            }
            GridDate next = path[_pathIndex + 1];
            // 如果即将横向移动,竖向移到格子中间
            if (now.Rows == next.Rows)
            {
                if (transform.position.y > targetPos.y)
                {
                    // 向xia移动
                    transform.Translate(0, -_spd * Time.deltaTime, 0);
                    //Debug.LogFormat ("xia {0} {1}", transform.position.y, targetPos.y);
                    if (transform.position.y <= targetPos.y)
                    {
                        transform.position = new Vector2(transform.position.x, targetPos.y);
                        // 如果移动到目的地,准备移到下个格子
                        _pathIndex++;
                        //Debug.Log ("移动到目的地");

                        if (_isRunAIAcition)
                        {
                            AiAction();
                        }
                    }
                }
                else
                {
                    // 向shang移动
                    transform.Translate(0, _spd * Time.deltaTime, 0);
                    //Debug.LogFormat ("shang {0} {1}", transform.position.y, targetPos.y);
                    if (transform.position.y >= targetPos.y)
                    {
                        transform.position = new Vector2(transform.position.x, targetPos.y);
                        // 如果移动到目的地,准备移到下个格子
                        _pathIndex++;

                        if (_isRunAIAcition)
                        {
                            AiAction();
                        }
                    }
                }
            }
            else
            {
                // 如果即将竖向移动,横向移到格子中间
                if (transform.position.x < targetPos.x)
                {
                    // 向右移动
                    transform.Translate(_spd * Time.deltaTime, 0, 0);
                    //Debug.LogFormat ("you {0} {1}", transform.position.x, targetPos.x);
                    if (transform.position.x >= targetPos.x)
                    {
                        transform.position = new Vector2(targetPos.x, transform.position.y);
                        // 如果移动到目的地,准备移到下个格子
                        _pathIndex++;

                        if (_isRunAIAcition)
                        {
                            AiAction();
                        }
                    }
                }
                else
                {
                    // 向左移动
                    transform.Translate(-_spd * Time.deltaTime, 0, 0);
                    //Debug.LogFormat ("zuo {0} {1}", transform.position.x, targetPos.x);
                    if (transform.position.x <= targetPos.x)
                    {
                        transform.position = new Vector2(targetPos.x, transform.position.y);
                        // 如果移动到目的地,准备移到下个格子
                        _pathIndex++;

                        if (_isRunAIAcition)
                        {
                            AiAction();
                        }
                    }
                }
            }
            return;
        }

        // 朝目标格子移动
        if (now.Rows == target.Rows)
        {
            // 行数相等,水平方向移动
            if (transform.position.x < targetPos.x)
            {
                // 向右移动
                transform.Translate(_spd * Time.deltaTime, 0, 0);
                //Debug.LogFormat ("you {0} {1}", transform.position.x, targetPos.x);
                if (transform.position.x >= targetPos.x)
                {
                    transform.position = new Vector2(targetPos.x, transform.position.y);
                    // 如果移动到目的地,准备移到下个格子
                    _pathIndex++;

                    if (_isRunAIAcition)
                    {
                        AiAction();
                    }
                }
            }
            else
            {
                // 向左移动
                transform.Translate(-_spd * Time.deltaTime, 0, 0);
                //Debug.LogFormat ("zuo {0} {1}", transform.position.x, targetPos.x);
                if (transform.position.x <= targetPos.x)
                {
                    transform.position = new Vector2(targetPos.x, transform.position.y);
                    // 如果移动到目的地,准备移到下个格子
                    _pathIndex++;

                    if (_isRunAIAcition)
                    {
                        AiAction();
                    }
                }
            }
        }
        else
        {
            // 列数相等,竖直方向移动
            if (transform.position.y > targetPos.y)
            {
                // 向xia移动
                transform.Translate(0, -_spd * Time.deltaTime, 0);
                //Debug.LogFormat ("xia {0} {1}", transform.position.y, targetPos.y);
                if (transform.position.y <= targetPos.y)
                {
                    transform.position = new Vector2(transform.position.x, targetPos.y);
                    // 如果移动到目的地,准备移到下个格子
                    _pathIndex++;
                    //Debug.Log ("移动到目的地");

                    if (_isRunAIAcition)
                    {
                        AiAction();
                    }
                }
            }
            else
            {
                // 向shang移动
                transform.Translate(0, _spd * Time.deltaTime, 0);
                //Debug.LogFormat ("shang {0} {1}", transform.position.y, targetPos.y);
                if (transform.position.y >= targetPos.y)
                {
                    transform.position = new Vector2(transform.position.x, targetPos.y);
                    // 如果移动到目的地,准备移到下个格子
                    _pathIndex++;

                    if (_isRunAIAcition)
                    {
                        AiAction();
                    }
                }
            }
        }

        return;
    }