Example #1
0
        //卡马腿,象腿用的
        private bool PosExitChess(int row, int col, bool YuJiExist)
        {
            //enemy卡
            SceneModule _sceneModule = (SceneModule)GameManager.GameManagerObj.GetComponent <GameManager>().GetModuleByName("SceneModule");

            if (_sceneModule.m_enemyList[row][col] != null)
            {
                return(true);
            }

            //player卡
            MapPos _pos = new MapPos();

            _sceneModule.GetPlayerPos(ref _pos);

            if (row == _pos.m_row && col == _pos.m_col)
            {
                return(true);
            }

            //虞姬卡
            if (YuJiExist && _sceneModule.YuJiPos.m_row == row && _sceneModule.YuJiPos.m_col == col)
            {
                return(true);
            }

            //拒马卡
            if (_sceneModule.m_mapData[row][col] == MapDataType.JUMATUI)
            {
                return(true);
            }


            return(false);
        }
Example #2
0
        //返回是否触发下回合攻击
        public bool ArrowTrigger()
        {
            if (m_status != ArrowStatus.WAIT)
            {
                return(false);
            }

            SceneModule _sceneModule = (SceneModule)GameManager.GameManagerObj.GetComponent <GameManager>().GetModuleByName("SceneModule");

            //触发的人是否在触发的位置上
            for (int _i = 0; _i < m_Trigger.Count; _i++)
            {
                if (m_Trigger[_i] == PlayerType.XIANGYU)
                {
                    MapPos pos = new MapPos();
                    _sceneModule.GetPlayerPos(ref pos);

                    for (int _j = 0; _j < m_TriggerArea.Count; _j++)
                    {
                        if (m_TriggerArea[_j].m_row == pos.m_row && m_TriggerArea[_j].m_col == pos.m_col)
                        {
                            //返回弓箭被触发,提示信息
                            SetType(ArrowStatus.ATTACK);
                            return(true);
                        }
                    }
                }
                else if (m_Trigger[_i] == PlayerType.YUJI && _sceneModule.UpdateYuJiPos())
                {
                    for (int _j = 0; _j < m_TriggerArea.Count; _j++)
                    {
                        if (m_TriggerArea[_j].m_row == _sceneModule.YuJiPos.m_row && m_TriggerArea[_j].m_col == _sceneModule.YuJiPos.m_col)
                        {
                            //返回弓箭被触发,提示信息
                            SetType(ArrowStatus.ATTACK);
                            return(true);
                        }
                    }
                }
                else
                {
                    //其他类型角色先不做
                }
            }

            return(false);
        }
Example #3
0
        //返回游戏是否结束,项羽1, 虞姬2, 游戏没结束0, 都死3
        public PlayerD ArrowAttack()
        {
            if (m_status != ArrowStatus.ATTACK)
            {
                SetType(ArrowStatus.ATTACK);
                return(0);
            }

            PlayerD     Ret          = 0;
            SceneModule _sceneModule = (SceneModule)GameManager.GameManagerObj.GetComponent <GameManager>().GetModuleByName("SceneModule");
            //消灭攻击位置的所有的人;不同棋子不会在一个位置
            MapPos pos = new MapPos();

            _sceneModule.GetPlayerPos(ref pos);
            bool YuJiExist = _sceneModule.UpdateYuJiPos();

            for (int _i = 0; _i < m_AttackArea.Count; _i++)
            {
                //敌人判断
                if (_sceneModule.m_enemyList[m_AttackArea[_i].m_row][m_AttackArea[_i].m_col] != null)
                {
                    //敌人被弓箭杀死的动画

                    //敌人死亡处理
                    _sceneModule.m_enemyList[m_AttackArea[_i].m_row][m_AttackArea[_i].m_col].DestroyObj();
                }

                //虞姬项羽判断
                if ((Ret != PlayerD.XIANGYU || Ret != PlayerD.ALL) && pos.m_row == m_AttackArea[_i].m_row && pos.m_col == m_AttackArea[_i].m_col)
                {
                    Ret = Ret == PlayerD.YUJI ? PlayerD.ALL : PlayerD.XIANGYU;
                }

                if ((Ret != PlayerD.YUJI || Ret != PlayerD.ALL) && YuJiExist && _sceneModule.YuJiPos.m_row == m_AttackArea[_i].m_row && _sceneModule.YuJiPos.m_col == m_AttackArea[_i].m_col)
                {
                    Ret = Ret == PlayerD.XIANGYU ? PlayerD.ALL : PlayerD.YUJI;
                }
            }

            SetType(ArrowStatus.WAIT);
            //删除这个arrow
            DestroyObj();
            return(Ret);
        }
Example #4
0
        public void Trigger()
        {
            SceneModule _sceneModule = (SceneModule)GameManager.GameManagerObj.GetComponent <GameManager>().GetModuleByName("SceneModule");
            MapPos      pos          = new MapPos();

            _sceneModule.GetPlayerPos(ref pos);
            //´¥·¢
            for (int _i = 0; _i < m_Trigger.Count; _i++)
            {
                if (m_Trigger[_i] == PlayerType.XIANGYU && pos.m_row == m_RockPos.m_row && pos.m_col == m_RockPos.m_col)
                {
                    //¹¥»÷
                    Attack();
                }
                else if (m_Trigger[_i] == PlayerType.YUJI && _sceneModule.UpdateYuJiPos())
                {
                    if (_sceneModule.YuJiPos.m_row == m_RockPos.m_row && _sceneModule.YuJiPos.m_col == m_RockPos.m_col)
                    {
                        //¹¥»÷
                        Attack();
                    }
                }
            }
        }
Example #5
0
        //敌人能否走的时候加入判断虞姬是否卡住了
        //敌人吃的时候,吃虞姬项羽优先级一样高,但是靠近虞姬
        //1 吃主子, 2吃副子, 0都没被吃
        public int GetEnemyNextPos(bool YuJiExist)
        {
            SceneModule _sceneModule = (SceneModule)GameManager.GameManagerObj.GetComponent <GameManager>().GetModuleByName("SceneModule");
            //判断,是否是可走的点
            int _mapRow = _sceneModule.m_config.SceneConfigList[GameManager.SceneConfigId].MapRow;
            int _mapCol = _sceneModule.m_config.SceneConfigList[GameManager.SceneConfigId].MapCol;

            int DistancePlayer = -1;
            //当前距离最近的点
            int minrow = 0;
            int mincol = 0;

            //可能要走的位置
            int temprow;
            int tempcol;

            MapPos _pos = new MapPos();

            _sceneModule.GetPlayerPos(ref _pos);

            //主棋子
            int PRow = -1;
            int PCol = -1;

            //副棋子:有虞姬时候的项羽
            int SecondRow = -1;
            int SecondCol = -1;

            int RetValue = 0;

            if (YuJiExist)
            {
                PRow = _sceneModule.YuJiPos.m_row;
                PCol = _sceneModule.YuJiPos.m_col;

                SecondRow = _pos.m_row;
                SecondCol = _pos.m_col;
            }
            else
            {
                //主player的位置
                PRow = _pos.m_row;
                PCol = _pos.m_col;
            }


            //enemy当前的位置
            int playerRow = m_EnemyPosNew.m_row;
            int playerCol = m_EnemyPosNew.m_col;

            switch (EnemyType)
            {
            //马
            case (int)ChessType.MA:
                if (playerRow >= 1)
                {
                    if (playerCol >= 2)
                    {
                        if ((_sceneModule.m_mapData[playerRow - 1][playerCol - 2] != MapDataType.NONE &&
                             _sceneModule.m_mapData[playerRow - 1][playerCol - 2] != MapDataType.JUMATUI) &&
                            (_sceneModule.m_mapData[playerRow][playerCol] == MapDataType.GAOTAI ||
                             (_sceneModule.m_mapData[playerRow][playerCol - 1] != MapDataType.GAOTAI)))
                        {
                            if (PosExitChess(playerRow, playerCol - 1, YuJiExist) == false)
                            {
                                temprow = playerRow - 1;
                                tempcol = playerCol - 2;

                                //能否吃副子
                                if (YuJiExist && temprow == SecondRow && tempcol == SecondCol)
                                {
                                    RetValue       = 2;
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                    break;
                                }
                                else if (DistancePlayer == -1)
                                {
                                    //找一个最近的点
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                                else if (DistancePlayer > (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol))
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                            }
                        }
                    }
                    if (playerCol + 2 < _mapCol)
                    {
                        if ((_sceneModule.m_mapData[playerRow - 1][playerCol + 2] != MapDataType.NONE &&
                             _sceneModule.m_mapData[playerRow - 1][playerCol + 2] != MapDataType.JUMATUI) &&
                            (_sceneModule.m_mapData[playerRow][playerCol] == MapDataType.GAOTAI ||
                             (_sceneModule.m_mapData[playerRow][playerCol + 1] != MapDataType.GAOTAI)))
                        {
                            if (PosExitChess(playerRow, playerCol + 1, YuJiExist) == false)
                            {
                                temprow = playerRow - 1;
                                tempcol = playerCol + 2;
                                //找一个最近的点
                                //能否吃副子
                                if (YuJiExist && temprow == SecondRow && tempcol == SecondCol)
                                {
                                    RetValue       = 2;
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                    break;
                                }
                                else if (DistancePlayer == -1)
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                                else if (DistancePlayer > (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol))
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                            }
                        }
                    }
                }
                if (playerRow >= 2)
                {
                    if (playerCol >= 1)
                    {
                        if ((_sceneModule.m_mapData[playerRow - 2][playerCol - 1] != MapDataType.NONE &&
                             _sceneModule.m_mapData[playerRow - 2][playerCol - 1] != MapDataType.JUMATUI) &&
                            (_sceneModule.m_mapData[playerRow][playerCol] == MapDataType.GAOTAI ||
                             (_sceneModule.m_mapData[playerRow - 1][playerCol] != MapDataType.GAOTAI)))
                        {
                            if (PosExitChess(playerRow - 1, playerCol, YuJiExist) == false)
                            {
                                temprow = playerRow - 2;
                                tempcol = playerCol - 1;
                                //找一个最近的点
                                //能否吃副子
                                if (YuJiExist && temprow == SecondRow && tempcol == SecondCol)
                                {
                                    RetValue       = 2;
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                    break;
                                }
                                else if (DistancePlayer == -1)
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                                else if (DistancePlayer > (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol))
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                            }
                        }
                    }
                    if (playerCol + 1 < _mapCol)
                    {
                        if ((_sceneModule.m_mapData[playerRow - 2][playerCol + 1] != MapDataType.NONE &&
                             _sceneModule.m_mapData[playerRow - 2][playerCol + 1] != MapDataType.JUMATUI) &&
                            (_sceneModule.m_mapData[playerRow][playerCol] == MapDataType.GAOTAI ||
                             (_sceneModule.m_mapData[playerRow - 1][playerCol] != MapDataType.GAOTAI)))
                        {
                            if (PosExitChess(playerRow - 1, playerCol, YuJiExist) == false)
                            {
                                temprow = playerRow - 2;
                                tempcol = playerCol + 1;
                                //找一个最近的点
                                //能否吃副子
                                if (YuJiExist && temprow == SecondRow && tempcol == SecondCol)
                                {
                                    RetValue       = 2;
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                    break;
                                }
                                else if (DistancePlayer == -1)
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                                else if (DistancePlayer > (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol))
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                            }
                        }
                    }
                }
                if (playerRow + 1 < _mapRow)
                {
                    if (playerCol >= 2)
                    {
                        if ((_sceneModule.m_mapData[playerRow + 1][playerCol - 2] != MapDataType.NONE &&
                             _sceneModule.m_mapData[playerRow + 1][playerCol - 2] != MapDataType.JUMATUI) &&
                            (_sceneModule.m_mapData[playerRow][playerCol] == MapDataType.GAOTAI ||
                             (_sceneModule.m_mapData[playerRow][playerCol - 1] != MapDataType.GAOTAI)))
                        {
                            if (PosExitChess(playerRow, playerCol - 1, YuJiExist) == false)
                            {
                                temprow = playerRow + 1;
                                tempcol = playerCol - 2;
                                //找一个最近的点
                                //能否吃副子
                                if (YuJiExist && temprow == SecondRow && tempcol == SecondCol)
                                {
                                    RetValue       = 2;
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                    break;
                                }
                                else if (DistancePlayer == -1)
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                                else if (DistancePlayer > (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol))
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                            }
                        }
                    }
                    if (playerCol + 2 < _mapCol)
                    {
                        if ((_sceneModule.m_mapData[playerRow + 1][playerCol + 2] != MapDataType.NONE &&
                             _sceneModule.m_mapData[playerRow + 1][playerCol + 2] != MapDataType.JUMATUI) &&
                            (_sceneModule.m_mapData[playerRow][playerCol] == MapDataType.GAOTAI ||
                             (_sceneModule.m_mapData[playerRow][playerCol + 1] != MapDataType.GAOTAI)))
                        {
                            if (PosExitChess(playerRow, playerCol + 1, YuJiExist) == false)
                            {
                                temprow = playerRow + 1;
                                tempcol = playerCol + 2;
                                //找一个最近的点
                                //能否吃副子
                                if (YuJiExist && temprow == SecondRow && tempcol == SecondCol)
                                {
                                    RetValue       = 2;
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                    break;
                                }
                                else if (DistancePlayer == -1)
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                                else if (DistancePlayer > (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol))
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                            }
                        }
                    }
                }
                if (playerRow + 2 < _mapRow)
                {
                    if (playerCol >= 1)
                    {
                        if ((_sceneModule.m_mapData[playerRow + 2][playerCol - 1] != MapDataType.NONE &&
                             _sceneModule.m_mapData[playerRow + 2][playerCol - 1] != MapDataType.JUMATUI) &&
                            (_sceneModule.m_mapData[playerRow][playerCol] == MapDataType.GAOTAI ||
                             (_sceneModule.m_mapData[playerRow + 1][playerCol] != MapDataType.GAOTAI)))
                        {
                            if (PosExitChess(playerRow + 1, playerCol, YuJiExist) == false)
                            {
                                temprow = playerRow + 2;
                                tempcol = playerCol - 1;
                                //找一个最近的点
                                //能否吃副子
                                if (YuJiExist && temprow == SecondRow && tempcol == SecondCol)
                                {
                                    RetValue       = 2;
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                    break;
                                }
                                else if (DistancePlayer == -1)
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                                else if (DistancePlayer > (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol))
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                            }
                        }
                    }
                    if (playerCol + 1 < _mapCol)
                    {
                        if ((_sceneModule.m_mapData[playerRow + 2][playerCol + 1] != MapDataType.NONE &&
                             _sceneModule.m_mapData[playerRow + 2][playerCol + 1] != MapDataType.JUMATUI) &&
                            (_sceneModule.m_mapData[playerRow][playerCol] == MapDataType.GAOTAI ||
                             (_sceneModule.m_mapData[playerRow + 1][playerCol] != MapDataType.GAOTAI)))
                        {
                            if (PosExitChess(playerRow + 1, playerCol, YuJiExist) == false)
                            {
                                temprow = playerRow + 2;
                                tempcol = playerCol + 1;
                                //找一个最近的点
                                //能否吃副子
                                if (YuJiExist && temprow == SecondRow && tempcol == SecondCol)
                                {
                                    RetValue       = 2;
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                    break;
                                }
                                else if (DistancePlayer == -1)
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                                else if (DistancePlayer > (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol))
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                            }
                        }
                    }
                }
                break;

            case (int)ChessType.XIANG:
                if (playerRow >= 2)
                {
                    if (playerCol >= 2)
                    {
                        if ((_sceneModule.m_mapData[playerRow - 2][playerCol - 2] != MapDataType.NONE &&
                             _sceneModule.m_mapData[playerRow - 2][playerCol - 2] != MapDataType.JUMATUI) &&
                            (_sceneModule.m_mapData[playerRow][playerCol] == MapDataType.GAOTAI ||
                             (_sceneModule.m_mapData[playerRow - 1][playerCol - 1] != MapDataType.GAOTAI)))
                        {
                            if (PosExitChess(playerRow - 1, playerCol - 1, YuJiExist) == false)
                            {
                                temprow = playerRow - 2;
                                tempcol = playerCol - 2;
                                //找一个最近的点
                                //能否吃副子
                                if (YuJiExist && temprow == SecondRow && tempcol == SecondCol)
                                {
                                    RetValue       = 2;
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                    break;
                                }
                                else if (DistancePlayer == -1)
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                                else if (DistancePlayer > (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol))
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                            }
                        }
                    }
                    if (playerCol + 2 < _mapCol)
                    {
                        if ((_sceneModule.m_mapData[playerRow - 2][playerCol + 2] != MapDataType.NONE &&
                             _sceneModule.m_mapData[playerRow - 2][playerCol + 2] != MapDataType.JUMATUI) &&
                            (_sceneModule.m_mapData[playerRow][playerCol] == MapDataType.GAOTAI ||
                             (_sceneModule.m_mapData[playerRow - 1][playerCol + 1] != MapDataType.GAOTAI)))
                        {
                            if (PosExitChess(playerRow - 1, playerCol + 1, YuJiExist) == false)
                            {
                                temprow = playerRow - 2;
                                tempcol = playerCol + 2;
                                //找一个最近的点
                                //能否吃副子
                                if (YuJiExist && temprow == SecondRow && tempcol == SecondCol)
                                {
                                    RetValue       = 2;
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                    break;
                                }
                                else if (DistancePlayer == -1)
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                                else if (DistancePlayer > (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol))
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                            }
                        }
                    }
                }
                if (playerRow + 2 < _mapRow)
                {
                    if (playerCol >= 2)
                    {
                        if ((_sceneModule.m_mapData[playerRow + 2][playerCol - 2] != MapDataType.NONE &&
                             _sceneModule.m_mapData[playerRow + 2][playerCol - 2] != MapDataType.JUMATUI) &&
                            (_sceneModule.m_mapData[playerRow][playerCol] == MapDataType.GAOTAI ||
                             (_sceneModule.m_mapData[playerRow + 1][playerCol - 1] != MapDataType.GAOTAI)))
                        {
                            if (PosExitChess(playerRow + 1, playerCol - 1, YuJiExist) == false)
                            {
                                temprow = playerRow + 2;
                                tempcol = playerCol - 2;
                                //找一个最近的点
                                //能否吃副子
                                if (YuJiExist && temprow == SecondRow && tempcol == SecondCol)
                                {
                                    RetValue       = 2;
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                    break;
                                }
                                else if (DistancePlayer == -1)
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                                else if (DistancePlayer > (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol))
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                            }
                        }
                    }
                    if (playerCol + 2 < _mapCol)
                    {
                        if ((_sceneModule.m_mapData[playerRow + 2][playerCol + 2] != MapDataType.NONE &&
                             _sceneModule.m_mapData[playerRow + 2][playerCol + 2] != MapDataType.JUMATUI) &&
                            (_sceneModule.m_mapData[playerRow][playerCol] == MapDataType.GAOTAI ||
                             (_sceneModule.m_mapData[playerRow + 1][playerCol + 1] != MapDataType.GAOTAI)))
                        {
                            if (PosExitChess(playerRow + 1, playerCol + 1, YuJiExist) == false)
                            {
                                temprow = playerRow + 2;
                                tempcol = playerCol + 2;
                                //找一个最近的点
                                //能否吃副子
                                if (YuJiExist && temprow == SecondRow && tempcol == SecondCol)
                                {
                                    RetValue       = 2;
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                    break;
                                }
                                else if (DistancePlayer == -1)
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                                else if (DistancePlayer > (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol))
                                {
                                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                                    minrow         = temprow;
                                    mincol         = tempcol;
                                }
                            }
                        }
                    }
                }
                break;

            case (int)ChessType.SHI:
                if (playerRow >= 1 && _sceneModule.m_mapData[playerRow - 1][playerCol] != MapDataType.GAOTAI && _sceneModule.m_mapData[playerRow - 1][playerCol] != MapDataType.JUMATUI && _sceneModule.m_mapData[playerRow - 1][playerCol] != MapDataType.NONE && _sceneModule.m_enemyList[playerRow - 1][playerCol] == null)
                {
                    temprow = playerRow - 1;
                    tempcol = playerCol;
                    //找一个最近的点
                    //能否吃副子
                    if (YuJiExist && temprow == SecondRow && tempcol == SecondCol)
                    {
                        RetValue       = 2;
                        DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                        minrow         = temprow;
                        mincol         = tempcol;
                        break;
                    }
                    else if (DistancePlayer == -1)
                    {
                        DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                        minrow         = temprow;
                        mincol         = tempcol;
                    }
                    else if (DistancePlayer > (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol))
                    {
                        DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                        minrow         = temprow;
                        mincol         = tempcol;
                    }
                }

                if (playerRow + 1 < _mapRow && _sceneModule.m_mapData[playerRow + 1][playerCol] != MapDataType.GAOTAI && _sceneModule.m_mapData[playerRow + 1][playerCol] != MapDataType.JUMATUI && _sceneModule.m_mapData[playerRow + 1][playerCol] != MapDataType.NONE && _sceneModule.m_enemyList[playerRow + 1][playerCol] == null)
                {
                    temprow = playerRow + 1;
                    tempcol = playerCol;
                    //找一个最近的点
                    //能否吃副子
                    if (YuJiExist && temprow == SecondRow && tempcol == SecondCol)
                    {
                        RetValue       = 2;
                        DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                        minrow         = temprow;
                        mincol         = tempcol;
                        break;
                    }
                    else if (DistancePlayer == -1)
                    {
                        DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                        minrow         = temprow;
                        mincol         = tempcol;
                    }
                    else if (DistancePlayer > (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol))
                    {
                        DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                        minrow         = temprow;
                        mincol         = tempcol;
                    }
                }

                if (playerCol >= 1 && _sceneModule.m_mapData[playerRow][playerCol - 1] != MapDataType.GAOTAI && _sceneModule.m_mapData[playerRow][playerCol - 1] != MapDataType.JUMATUI && _sceneModule.m_mapData[playerRow][playerCol - 1] != MapDataType.NONE && _sceneModule.m_enemyList[playerRow][playerCol - 1] == null)
                {
                    temprow = playerRow;
                    tempcol = playerCol - 1;
                    //找一个最近的点
                    //能否吃副子
                    if (YuJiExist && temprow == SecondRow && tempcol == SecondCol)
                    {
                        RetValue       = 2;
                        DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                        minrow         = temprow;
                        mincol         = tempcol;
                        break;
                    }
                    else if (DistancePlayer == -1)
                    {
                        DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                        minrow         = temprow;
                        mincol         = tempcol;
                    }
                    else if (DistancePlayer > (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol))
                    {
                        DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                        minrow         = temprow;
                        mincol         = tempcol;
                    }
                }

                if (playerCol + 1 < _mapCol && _sceneModule.m_mapData[playerRow][playerCol + 1] != MapDataType.GAOTAI && _sceneModule.m_mapData[playerRow][playerCol + 1] != MapDataType.JUMATUI && _sceneModule.m_mapData[playerRow][playerCol + 1] != MapDataType.NONE && _sceneModule.m_enemyList[playerRow][playerCol + 1] == null)
                {
                    temprow = playerRow;
                    tempcol = playerCol + 1;
                    //找一个最近的点
                    //能否吃副子
                    if (YuJiExist && temprow == SecondRow && tempcol == SecondCol)
                    {
                        RetValue       = 2;
                        DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                        minrow         = temprow;
                        mincol         = tempcol;
                        break;
                    }
                    else if (DistancePlayer == -1)
                    {
                        DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                        minrow         = temprow;
                        mincol         = tempcol;
                    }
                    else if (DistancePlayer > (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol))
                    {
                        DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                        minrow         = temprow;
                        mincol         = tempcol;
                    }
                }



                break;

            case (int)ChessType.JU:
                //可走的边界点
                JuUse TempJu1 = new JuUse(m_EnemyPosNew.m_row, 0, -1);
                JuUse TempJu2 = new JuUse(m_EnemyPosNew.m_row, _mapRow - 1, 1);
                JuUse TempJu3 = new JuUse(m_EnemyPosNew.m_col, 0, -1);
                JuUse TempJu4 = new JuUse(m_EnemyPosNew.m_col, _mapCol - 1, 1);

                List <JuUse> Pos = new List <JuUse>();
                Pos.Add(TempJu1);
                Pos.Add(TempJu2);
                Pos.Add(TempJu3);
                Pos.Add(TempJu4);
                //根据敌方棋子和地形判断row,col的最值,把4种情况合一起了
                for (int _i = 0; _i < Pos.Count; _i++)
                {
                    JuUse temp = Pos[_i];
                    for (temp.m_BeginPos += temp.m_Change; temp.m_BeginPos *temp.m_Change <= temp.m_BroundPos; temp.m_BeginPos += temp.m_Change)
                    {
                        //row变,col不变的情况
                        if (_i < 2 && (_sceneModule.m_enemyList[temp.m_BeginPos][m_EnemyPosNew.m_col] != null || _sceneModule.m_mapData[temp.m_BeginPos][m_EnemyPosNew.m_col] != _sceneModule.m_mapData[m_EnemyPosNew.m_row][m_EnemyPosNew.m_col]))
                        {
                            //被地图或者敌人阻挡的情况,改变row
                            temp.m_BeginPos -= temp.m_Change;
                            break;
                        }
                        //col变,row不变的情况
                        if (_i >= 2 && (_sceneModule.m_enemyList[m_EnemyPosNew.m_row][temp.m_BeginPos] != null || _sceneModule.m_mapData[m_EnemyPosNew.m_row][temp.m_BeginPos] != _sceneModule.m_mapData[m_EnemyPosNew.m_row][m_EnemyPosNew.m_col]))
                        {
                            //被地图或者敌人阻挡的情况,改变col
                            temp.m_BeginPos -= temp.m_Change;
                            break;
                        }
                    }
                    //边界可以走的情况
                    if (temp.m_BeginPos * temp.m_Change > temp.m_BroundPos)
                    {
                        temp.m_BeginPos = temp.m_BroundPos;
                    }
                    Pos[_i] = temp;
                }

                //虞姬存在能吃副子的情况,col方向能走或者  row方向能走
                if (YuJiExist && ((SecondRow == m_EnemyPosNew.m_row && SecondCol >= Pos[2].m_BeginPos && SecondCol <= Pos[3].m_BeginPos) || (SecondCol == m_EnemyPosNew.m_col && SecondRow >= Pos[0].m_BeginPos && SecondRow <= Pos[1].m_BeginPos)))
                {
                    temprow        = SecondRow;
                    tempcol        = SecondCol;
                    RetValue       = 2;
                    DistancePlayer = 0;
                    minrow         = temprow;
                    mincol         = tempcol;
                    break;
                }
                else
                {
                    //不吃副子的情况找一个和主子最近的位置
                    //1 改变row的情况下找一个最近的
                    temprow = PRow;
                    tempcol = m_EnemyPosNew.m_col;
                    if (temprow >= m_EnemyPosNew.m_row)
                    {
                        temprow = temprow > Pos[1].m_BeginPos ? Pos[1].m_BeginPos : temprow;
                    }
                    else
                    {
                        temprow = temprow < Pos[0].m_BeginPos ? Pos[0].m_BeginPos : temprow;
                    }
                    DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                    minrow         = temprow;
                    mincol         = tempcol;
                    //2 改变col的情况下找一个最近的
                    temprow = m_EnemyPosNew.m_row;
                    tempcol = PCol;
                    if (tempcol >= m_EnemyPosNew.m_col)
                    {
                        tempcol = tempcol > Pos[3].m_BeginPos ? Pos[3].m_BeginPos : tempcol;
                    }
                    else
                    {
                        tempcol = tempcol < Pos[2].m_BeginPos ? Pos[2].m_BeginPos : tempcol;
                    }

                    if (DistancePlayer > (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol))
                    {
                        DistancePlayer = (PRow - temprow) * (PRow - temprow) + (tempcol - PCol) * (tempcol - PCol);
                        minrow         = temprow;
                        mincol         = tempcol;
                    }
                }

                break;
            }

            //Debug.Log(string.Format("minx:{0}, miny:{1}",minrow, mincol));
            if (DistancePlayer == -1)
            {
                //没有点可以走
                MovePos(m_EnemyPosNew.m_row, m_EnemyPosNew.m_col);
            }
            else
            {
                _sceneModule.m_enemyList[minrow][mincol] = _sceneModule.m_enemyList[m_EnemyPosNew.m_row][m_EnemyPosNew.m_col];
                _sceneModule.m_enemyList[m_EnemyPosNew.m_row][m_EnemyPosNew.m_col] = null;
                MovePos(minrow, mincol);
                EnemyMove(minrow, mincol);
                PosIsChange = 1;
                if (RetValue == 2)
                {
                    return(2);
                }
                else if (DistancePlayer == 0)
                {
                    return(1);
                }
            }

            return(0);
        }
Example #6
0
        private void DoOneStep()
        {
            if (m_curStep == m_routePosList.Count)
            {
                m_curRoundStep = 0;
                EventManager.SendEvent(HLEventId.NPC_END_MOVE, null);
            }
            SceneModule _sceneModule = (SceneModule)GameManager.GameManagerObj.GetComponent <GameManager>().GetModuleByName("SceneModule");

            if (m_curRoundStep < m_stepPerRound - 1)
            {
                MapPos _playPos = new MapPos();
                _sceneModule.GetPlayerPos(ref _playPos);
                int _col = m_routePosList[m_curStep].m_col;
                int _row = m_routePosList[m_curStep].m_row;
                if (_row == m_playerPos.m_row && _col == m_playerPos.m_col)
                {
                    ++m_curRoundStep;
                    ++m_curStep;
                    DoOneStep();
                }
                else if ((_col != _playPos.m_col || _row != _playPos.m_row) && _sceneModule.m_enemyList[_row][_col] == null && _sceneModule.Data[_row][_col] != MapDataType.NONE)
                {
                    _sceneModule.m_npcList[_row][_col] = _sceneModule.m_npcList[m_playerPos.m_row][m_playerPos.m_col];
                    _sceneModule.m_npcList[m_playerPos.m_row][m_playerPos.m_col] = null;
                    m_playerPos.m_row = _row;
                    m_playerPos.m_col = _col;
                    Sequence _sequence = DOTween.Sequence();
                    _sequence.Append(transform.DOMove(new Vector3(_row * DiffX, 0f, _col * DiffZ), 0.5f));
                    _sequence.onComplete += DoOneStep;
                    _sequence.SetAutoKill(true);
                    ++m_curRoundStep;
                    ++m_curStep;
                }
                else
                {
                    m_curRoundStep = 0;
                    EventManager.SendEvent(HLEventId.NPC_END_MOVE, null);
                }
            }
            else
            {
                MapPos _playPos = new MapPos();
                _sceneModule.GetPlayerPos(ref _playPos);
                int _col = m_routePosList[m_curStep].m_col;
                int _row = m_routePosList[m_curStep].m_row;
                if (_row == m_playerPos.m_row && _col == m_playerPos.m_col)
                {
                    m_curRoundStep = 0;
                    ++m_curStep;
                    EventManager.SendEvent(HLEventId.NPC_END_MOVE, null);
                }
                else if ((_col != _playPos.m_col || _row != _playPos.m_row) && _sceneModule.m_enemyList[_row][_col] == null && _sceneModule.Data[_row][_col] != MapDataType.NONE)
                {
                    _sceneModule.m_npcList[_row][_col] = _sceneModule.m_npcList[m_playerPos.m_row][m_playerPos.m_col];
                    _sceneModule.m_npcList[m_playerPos.m_row][m_playerPos.m_col] = null;
                    m_playerPos.m_row = _row;
                    m_playerPos.m_col = _col;
                    m_curRoundStep    = 0;
                    Sequence _sequence = DOTween.Sequence();
                    _sequence.Append(transform.DOMove(new Vector3(_row * DiffX, 0f, _col * DiffZ), 0.5f));
                    _sequence.SetAutoKill(true);
                    _sequence.onComplete += NpcEndMoveCallBack;
                    ++m_curStep;
                }
                else
                {
                    m_curRoundStep = 0;
                    EventManager.SendEvent(HLEventId.NPC_END_MOVE, null);
                }
            }
        }