コード例 #1
0
    private void OnEnable()
    {
        table.SetData(App.Package.ChessGame.ChessHistorySteps, true);
        table.ResetPosition();
        List <int> ids   = App.Package.ChessGame.ChessDataIds;
        int        my    = 0;
        int        enemy = 0;

        for (int i = 0; i < App.Package.ChessGame.ChessDataIds.Count; i++)
        {
            ChessHeroData chess = App.Package.ChessGame.GetChessHeroDataById(App.Package.ChessGame.ChessDataIds[i]);
            if (chess.state == ChessHeroState.Alive)
            {
                if (chess.group == ChessHeroGroup.Myself)
                {
                    my++;
                }
                else
                {
                    enemy++;
                }
            }
        }
        MyChessNum.text    = my.ToString();
        EnemyChessNum.text = enemy.ToString();
    }
コード例 #2
0
    ChessData ChessHeroDataToChessData(PlayerInfo playerInfo, ChessHeroData chessHero)
    {
        ChessData chessData = new ChessData();

        chessData.ChessRemoteId = chessHero.remoteId;
        chessData.Belong        = playerInfo.ZoneId + "/" + playerInfo.UserId;
        chessData.Group         = (int)chessHero.group;
        chessData.Point         = chessHero.point.ParseToRpc();
        return(chessData);
    }
コード例 #3
0
    public static bool ChessHeroCanMove(ChessHeroData heroData)
    {
        //地雷和军旗不能移动
        if (heroData.heroTypeId == 0 || heroData.heroTypeId == 11)
        {
            return(false);
        }
        return(IsStronghold(heroData.point) == false);//大本营不能走

        return(true);
    }
コード例 #4
0
 //单击训练模式
 public static ChessMoveResult ChessCanBeat(ChessHeroData heroS, ChessHeroData heroT) //1胜利,-1失败,0平局消失,2获胜结束,-2未知
 {
     if (heroT.heroTypeId == 12 || heroS.heroTypeId == -2)
     {
         return(ChessMoveResult.LOSE);
     }
     if (heroS.heroTypeId == 12 || heroT.heroTypeId == -2)
     {
         return(ChessMoveResult.WIN);
     }
     if (heroS.heroTypeId == -3 || heroT.heroTypeId == -3)
     {
         return(ChessMoveResult.TIE);
     }
     if (heroT.heroTypeId < 0)
     {
         return(ChessMoveResult.UNKNOW);                     //未知
     }
     if (heroT.heroTypeId == 1)
     {
         return(ChessMoveResult.TIE);                      //敌方炸弹
     }
     if (heroS.heroTypeId == 1)
     {
         return(ChessMoveResult.TIE); //我方炸弹
     }
     if (heroS.heroTypeId == 2)       //我方工兵
     {
         if (heroT.heroTypeId == 0)
         {
             return(ChessMoveResult.WIN);                      //敌方地雷
         }
     }
     if (heroT.heroTypeId == 0)
     {
         return(ChessMoveResult.LOSE);                      //敌方地雷
     }
     if (heroT.heroTypeId == 11)
     {
         return(ChessMoveResult.WIN);                       //敌方军旗
     }
     if (heroT.heroTypeId > heroS.heroTypeId)
     {
         return(ChessMoveResult.LOSE);
     }
     else if (heroT.heroTypeId < heroS.heroTypeId)
     {
         return(ChessMoveResult.WIN);
     }
     else
     {
         return(ChessMoveResult.TIE);
     }
 }
コード例 #5
0
 public void AddChessToMap(ChessHeroData chessData)
 {
     if (m_ChessData.ContainsKey(chessData.id))
     {
         m_ChessData[chessData.id] = chessData;
     }
     else
     {
         ChessDataIds.Add(chessData.id);
         m_ChessData.Add(chessData.id, chessData);
     }
 }
コード例 #6
0
 public static ChessHeroData HasChessHeroOnPathPoints(ChessPoint[] points)
 {
     for (int i = 1; i < points.Length - 1; i++)
     {
         ChessHeroData heroData = App.Package.ChessGame.GetChessHeroDataByPoint(points[i]);
         if (heroData != null && heroData.state == ChessHeroState.Alive)
         {
             Debugger.Error(points[i]);
             return(heroData);
         }
     }
     return(null);
 }
コード例 #7
0
 public void OnChessFieldClick(object content)
 {
     Push("_chessHeroChoosed", -1);
     for (int i = 0; i < App.Package.ChessGame.ChessDataIds.Count; i++)
     {
         ChessHeroData    heroPre = App.Package.ChessGame.GetChessHeroDataById(App.Package.ChessGame.ChessDataIds[i]);
         UIWChessHeroItem uiChess = heroPre.gameObject.GetComponent <UIWChessHeroItem>();
         uiChess.willLose.SetActive(false);
         uiChess.willWin.SetActive(false);
         uiChess.willTie.SetActive(false);
     }
     App.Package.ChessGame.MyselfChooseChessId = -1;
 }
コード例 #8
0
 private void ChessMoveTo(ChessHeroData hero, ChessPoint point)
 {
     if (point.y / 6 > 0)
     {
         hero.gameObject.transform.parent = m_EnemyFied.transform;
     }
     else
     {
         hero.gameObject.transform.parent = m_MyselfFied.transform;
     }
     hero.point = point.Clone();
     hero.gameObject.transform.localScale    = Vector3.one;
     hero.gameObject.transform.localPosition = GetChessLocalPosition(hero.point);
 }
コード例 #9
0
    public HistoryStep BuildHistoryStep(int counter, ChessHeroData source, ChessPoint targetPoint, ChessDataPath path, int result)
    {
        ChessData s = new ChessData();

        s.ChessRemoteId = source.remoteId;
        s.Belong        = source.belong;
        s.ChessType     = source.realChessType;
        s.Point         = source.point.ParseToRpc();

        ChessData t = new ChessData();

        t.Point = targetPoint.ParseToRpc();
        return(BuildHistoryStep(counter, s, t, path, result));
    }
コード例 #10
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="chessData"></param>
    /// <param name="forceTrans">是否强制坐标转换</param>
    /// <returns></returns>
    ChessHeroData ChessDataToChessHeroData(ChessData chessData, bool forceTrans = false)
    {
        ChessHeroData chess = new ChessHeroData();

        chess.group         = App.Package.ChessGame.GetGroup(chessData.Belong);
        chess.heroTypeId    = chessData.ChessType;
        chess.realChessType = chess.heroTypeId;
        chess.remoteId      = chessData.ChessRemoteId;
        chess.point         = ChessPoint.ParseFromRpc(chessData.Point);
        chess.belong        = chessData.Belong;
        if (chess.group != ChessHeroGroup.Myself || forceTrans)
        {
            chess.point.x = 4 - chess.point.x;
            chess.point.y = 11 - chess.point.y;
        }
        return(chess);
    }
コード例 #11
0
 private void OnChessExchange(object content)
 {
     if (App.Package.ChessGame.CanDragChess)
     {
         Intent           intent  = (Intent)content;
         UIWChessHeroItem moveUI  = (UIWChessHeroItem)intent.Value("move");
         UIWChessHeroItem placeUI = (UIWChessHeroItem)intent.Value("place");
         ChessHeroData    move    = App.Package.ChessGame.GetChessHeroDataById(moveUI.chessId);
         ChessHeroData    place   = App.Package.ChessGame.GetChessHeroDataById(placeUI.chessId);
         if (move.group == ChessHeroGroup.Myself && place.group == ChessHeroGroup.Myself) //只有自己的才可以拖拽
         {
             if (move.heroTypeId == 1 && ChessAgainst.IsFirstRow(place.point))
             {
                 Common.UI.OpenTips("炸弹不可以放第一排哦!");
                 return;
             }
             if ((move.heroTypeId == 11 && !ChessAgainst.IsStronghold(place.point)) || (place.heroTypeId == 11 && !ChessAgainst.IsStronghold(move.point)))
             {
                 Common.UI.OpenTips("军旗只能在大本营中哦!");
                 return;
             }
             if ((move.heroTypeId == 0 && !ChessAgainst.IsAfterCamp(place.point)) || (place.heroTypeId == 0 && !ChessAgainst.IsAfterCamp(move.point)))
             {
                 Common.UI.OpenTips("地雷只能在后2排哦!");
                 return;
             }
             ChessPoint tpoint = move.point;
             ChessMoveTo(move, place.point);
             ChessMoveTo(place, tpoint);
         }
         else
         {
             Common.UI.OpenTips("不能互换敌方棋子");
         }
     }
     else
     {
         if (App.Package.ChessGame.IsReadyGame && !App.Package.ChessGame.IsGameStart)
         {
             Common.UI.OpenTips("已经准备就绪,无法调整棋子");
         }
     }
 }
コード例 #12
0
    /// <summary>
    /// 初始化棋盘放置
    /// </summary>
    private void InitChessHero(ChessHeroGroup group)
    {
        TreeRoot             treeRoot       = GetComponent <TreeRoot>();
        List <ChessHeroData> chessHeroDatas = App.Package.ChessGame.GetChessHeroList(group);

        for (int i = 0; i < chessHeroDatas.Count; i++)
        {
            ChessHeroData heroData = chessHeroDatas[i];
            if (!ChessAgainst.IsBarrack(heroData.point))//不在军营里
            {
                GameObject       go            = Instantiate(m_ChessHero);
                UIWChessHeroItem chessHeroItem = go.GetComponent <UIWChessHeroItem>();
                chessHeroItem.heroData    = heroData;
                chessHeroItem.treeRoot    = treeRoot;
                chessHeroItem.chessHeroId = heroData.heroTypeId;
                treeRoot.Bind(chessHeroItem);//绑定到TreeRoot
                chessHeroItem.chessId = heroData.id;
                switch (group)
                {
                case ChessHeroGroup.Myself:
                    go.transform.parent      = m_MyselfFied.transform;
                    chessHeroItem.state      = ChessHeroState.Alive;
                    chessHeroItem.labelState = ChessHeroLabelState.Show;
                    break;

                case ChessHeroGroup.Enemy:
                    go.transform.parent      = m_EnemyFied.transform;
                    chessHeroItem.state      = ChessHeroState.Alive;
                    chessHeroItem.labelState = (heroData.heroTypeId >= 0)? ChessHeroLabelState.Show: ChessHeroLabelState.Hide;    //小于0为未知棋子,应该隐藏
                    break;
                }
                go.transform.localScale    = Vector3.one;
                go.transform.localPosition = GetChessLocalPosition(heroData.point);
                go.SetActive(true);
                heroData.gameObject = go;
            }
            else
            {
                Debugger.Error("初始化棋子位置错误!");
            }
        }
    }
コード例 #13
0
    public void AddChessFromData(List <ChessData> chessList)
    {
        PlayerInfo playerInfo = App.Package.Player.playerInfo;
        string     belong     = playerInfo.ZoneId + "/" + playerInfo.UserId;
        Dictionary <ChessHeroGroup, int> map = new Dictionary <ChessHeroGroup, int>();

        map.Add(ChessHeroGroup.Myself, 1);
        map.Add(ChessHeroGroup.Enemy, 1);
        int baseId = 0;

        for (int i = 0; i < chessList.Count; i++)
        {
            ChessData chess = chessList[i];
            Debugger.Warn(chess.Belong + ":" + chess.Point.X + "," + chess.Point.Y + "|" + chess.ChessType);
            ChessHeroData  heroData = new ChessHeroData();
            ChessHeroGroup group;
            baseId = GetBaseId(chess.Belong);
            group  = (ChessHeroGroup)(baseId / 100);
            switch (group)
            {
            case ChessHeroGroup.Myself:
                heroData.point = new ChessPoint(chess.Point.X, chess.Point.Y);
                break;

            case ChessHeroGroup.Enemy:    //敌人要翻转
                heroData.point = new ChessPoint(4 - chess.Point.X, 11 - chess.Point.Y);
                break;
            }

            heroData.heroTypeId    = chess.ChessType;
            heroData.realChessType = heroData.heroTypeId;
            heroData.id            = map[group] + baseId;
            heroData.remoteId      = chess.ChessRemoteId;
            heroData.state         = ChessHeroState.Alive;
            heroData.belong        = chess.Belong;
            heroData.group         = group;
            AddChessToMap(heroData);
            map[group]++;
        }
    }
コード例 #14
0
    /// <summary>
    /// 检测棋子摆放是否合法
    /// </summary>
    /// <param name="heros"></param>
    /// <returns></returns>
    public static bool ChessIsLegal(List <ChessHeroData> heros)
    {
        int[] heroNumbers = new int[ChessHeroNumber.Length];
        for (int i = 0; i < heros.Count; i++)
        {
            ChessHeroData item = heros[i];
            heroNumbers[item.heroTypeId]++;
            switch (item.heroTypeId)
            {
            case 0:    //地雷
                if (!IsAfterCamp(item.point))
                {
                    return(false);
                }
                break;

            case 11:    //军旗
                if (!IsStronghold(item.point))
                {
                    return(false);
                }
                break;

            case 1:    //炸弹
                if (IsFirstRow(item.point))
                {
                    return(false);
                }
                break;
            }
        }
        for (int i = 0; i < heroNumbers.Length; i++)
        {
            if (heroNumbers[i] > ChessHeroNumber[i])
            {
                return(false);
            }
        }
        return(true);
    }
コード例 #15
0
    IEnumerator TweenMoveChess(ChessHeroData heroChoosed, ChessPoint moveToPoint, ChessMoveResult result, ChessMoveData moveData)
    {
        m_MyChessIsMoving = true;

        //if((ChessMoveResult.CANNOT_MOVE == result && moveData.crashType > 0) || (ChessMoveResult.CAN_MOVE == result && moveData.crashType == 0))
        //{
        Push("_cleanArrow");
        m_lastPath = moveData.points;
        float dur = 0.2f / moveData.points.Length;

        for (int i = 1; i < moveData.points.Length; i++)
        {
            ShowChessMoveTo(heroChoosed.point, moveData.points[i]);
            ChessMoveTo(heroChoosed, moveData.points[i]);
            yield return(new WaitForSeconds(dur));
        }
        //加入历史走子
        App.Package.ChessGame.ChessHistorySteps.Insert(0,
                                                       App.Package.ChessGame.BuildHistoryStep(
                                                           App.Package.ChessGame.GameRoundCounter,
                                                           heroChoosed,
                                                           moveToPoint,
                                                           App.Package.ChessGame.BuildChessDataPathFromPoints(moveData.points),
                                                           (int)result
                                                           )
                                                       );
        Push("_updateHistory");

        heroChoosed.point = moveToPoint;
        m_MyChessIsMoving = false;
        NextGameRound();
        //}

        /*else
         * {
         *  ChessDataHasProblem();
         * }*/
    }
コード例 #16
0
    void RequestToMove(ChessHeroData heroChoosed, ChessPoint moveToPoint, ChessHeroData hero, ChessMoveData moveData)
    {
        m_MyChessIsMoving = true;
        MoveChessRequest request = new MoveChessRequest();

        request.Source = ChessHeroDataToChessData(App.Package.Player.playerInfo, heroChoosed);
        if (hero != null)
        {
            request.Target = ChessHeroDataToChessData(App.Package.ChessGame.EnemyPlayerList[0], hero);//多人的时候要修改
        }
        else
        {
            request.Target       = new ChessData();
            request.Target.Point = moveToPoint.ParseToRpc();
        }
        App.Manager.Network.Request("MoveChess", request, delegate(IMessage responseData) {
            MoveChessResponse response = (MoveChessResponse)responseData;
            int result = response.ChessMoveResult;
            //强制回合同步
            App.Package.ChessGame.GameRoundCounter = response.Counter - 1;

            if (response.Counter == App.Package.ChessGame.GameRoundCounter + 1)
            {
                if (hero == null)
                {
                    StartCoroutine(TweenMoveChess(heroChoosed, moveToPoint, (ChessMoveResult)result, moveData));
                }
                else
                {
                    StartCoroutine(TweenMoveChessAndBeat(heroChoosed, hero, (ChessMoveResult)result, moveData));
                }
            }
            else
            {
                ChessDataHasProblem();
            }
        }, true, false, false);
    }
コード例 #17
0
    IEnumerator TweenMoveChessAndBeat(ChessHeroData heroChoosed, ChessHeroData hero, ChessMoveResult resultR, ChessMoveData moveData)
    {
        m_MyChessIsMoving = true;
        if ((resultR == ChessMoveResult.CANNOT_MOVE && moveData.crashType <= 0) || (resultR == ChessMoveResult.CAN_MOVE && moveData.crashType > 0))
        {
            ChessDataHasProblem();
        }
        else
        {
            if (moveData.crashType > 0)
            {
                App.Package.ChessGame.MyselfChooseChessId = hero.id;
                Debugger.Warn("ChessHeroItem Cant MoveTo " + hero.point.ToString() + " : " + moveData.crashType);
                m_MyChessIsMoving = false;
            }
            else
            {
                Push("_cleanArrow");
                m_lastPath = moveData.points;
                ChessMoveResult result = resultR;//ChessAgainst.ChessCanBeat(heroChoosed, hero);
                float           dur    = 0.4f / moveData.points.Length;
                for (int i = 1; i < moveData.points.Length - 1; i++)
                {
                    ShowChessMoveTo(heroChoosed.point, moveData.points[i]);
                    ChessMoveTo(heroChoosed, moveData.points[i]);
                    yield return(new WaitForSeconds(dur));
                }
                //加入历史走子
                App.Package.ChessGame.ChessHistorySteps.Insert(0,
                                                               App.Package.ChessGame.BuildHistoryStep(
                                                                   App.Package.ChessGame.GameRoundCounter,
                                                                   heroChoosed,
                                                                   hero,
                                                                   App.Package.ChessGame.BuildChessDataPathFromPoints(moveData.points),
                                                                   (int)result
                                                                   )
                                                               );
                Push("_updateHistory");
                switch (result)
                {
                case ChessMoveResult.LOSE:
                    heroChoosed.state = ChessHeroState.Died;
                    heroChoosed.gameObject.SetActive(false);
                    break;

                case ChessMoveResult.TIE:
                    heroChoosed.state = ChessHeroState.Died;
                    heroChoosed.gameObject.SetActive(false);
                    hero.state = ChessHeroState.Died;
                    hero.gameObject.SetActive(false);
                    break;

                case ChessMoveResult.WIN:
                    hero.state = ChessHeroState.Died;
                    hero.gameObject.SetActive(false);
                    break;
                }
                ShowChessMoveTo(heroChoosed.point, moveData.points[moveData.points.Length - 1]);
                ChessMoveTo(heroChoosed, moveData.points[moveData.points.Length - 1]);
                if (result > 0)
                {
                    //UIWChessHeroItem uiChess = heroChoosed.gameObject.GetComponent<UIWChessHeroItem>();
                    //uiChess.isChoosed = true;
                    //uiChess.UpdateView();
                }
                else
                {
                    //App.Package.ChessGame.MyselfChooseChessId = -1;
                }
                int  cid = -1;
                bool resultS;
                if (heroChoosed.group == ChessHeroGroup.Myself)
                {
                    cid     = heroChoosed.realChessType;
                    resultS = result == ChessMoveResult.WIN;
                    if (cid > 0 && cid < 11 && cid != 1)
                    {
                        m_roundOver.SetState(cid, resultS);
                    }
                }
                else
                {
                    cid     = hero.realChessType;
                    resultS = result == ChessMoveResult.WIN;
                    if (cid > 0 && cid < 11 && cid != 1)
                    {
                        switch (result)
                        {
                        case ChessMoveResult.WIN:
                        case ChessMoveResult.TIE:
                            m_roundOver.SetState(cid, false);
                            break;

                        case ChessMoveResult.LOSE:
                            m_roundOver.SetState(cid, true);
                            break;
                        }
                    }
                }

                App.Package.ChessGame.MyselfChooseChessId = heroChoosed.id;
                Push("_chessHeroChoosed", heroChoosed.id);
                m_MyChessIsMoving = false;
                NextGameRound();
            }
        }
    }
コード例 #18
0
    private void OnChessHeroClick(object content)//吃子移动
    {
        if (App.Package.ChessGame.IsGameStart)
        {
            if (!App.Package.ChessGame.IsMyRound)
            {
                Common.UI.OpenTips("敌方回合,无法行动");
                return;
            }
            if (m_MyChessIsMoving)
            {
                return;                   //正在移动
            }
            Intent         intent = (Intent)content;
            int            id     = (int)intent.Value("id");
            GameObject     go     = (GameObject)intent.Value("gameObject");
            ChessHeroData  hero   = App.Package.ChessGame.GetChessHeroDataById(id);
            ChessHeroGroup group  = hero.group;
            Push("_chessHeroChoosed", id);

            //明棋模式提醒
            if (group == ChessHeroGroup.Myself)
            {
                for (int i = 0; i < App.Package.ChessGame.ChessDataIds.Count; i++)
                {
                    int           chessId = App.Package.ChessGame.ChessDataIds[i];
                    ChessHeroData heroPre = App.Package.ChessGame.GetChessHeroDataById(chessId);
                    if (heroPre.group == ChessHeroGroup.Myself)
                    {
                        continue;
                    }

                    UIWChessHeroItem uiChess = heroPre.gameObject.GetComponent <UIWChessHeroItem>();
                    uiChess.willLose.SetActive(false);
                    uiChess.willWin.SetActive(false);
                    uiChess.willTie.SetActive(false);
                    if (heroPre.heroTypeId > -1 && ChessAgainst.ChessHeroCanMove(hero))
                    {
                        ChessMoveResult result = ChessAgainst.ChessCanBeat(hero, heroPre);

                        switch (result)
                        {
                        case ChessMoveResult.LOSE:
                            uiChess.willLose.SetActive(true);
                            break;

                        case ChessMoveResult.TIE:
                            uiChess.willTie.SetActive(true);
                            break;

                        case ChessMoveResult.WIN:
                            uiChess.willWin.SetActive(true);
                            break;
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < App.Package.ChessGame.ChessDataIds.Count; i++)
                {
                    int           chessId = App.Package.ChessGame.ChessDataIds[i];
                    ChessHeroData heroPre = App.Package.ChessGame.GetChessHeroDataById(chessId);
                    if (heroPre.group == ChessHeroGroup.Myself)
                    {
                        continue;
                    }

                    UIWChessHeroItem uiChess = heroPre.gameObject.GetComponent <UIWChessHeroItem>();
                    uiChess.willLose.SetActive(false);
                    uiChess.willWin.SetActive(false);
                    uiChess.willTie.SetActive(false);
                }
            }


            if (App.Package.ChessGame.MyselfChooseChessId > -1)
            {
                ChessHeroData heroChoosed = App.Package.ChessGame.GetChessHeroDataById(App.Package.ChessGame.MyselfChooseChessId);
                if (heroChoosed.group == ChessHeroGroup.Myself && group != ChessHeroGroup.Myself) //之前有选择自己,当前非己方的棋
                {
                    if (App.Package.ChessGame.IsGameStart)                                        //游戏开始了之后才能走并吃子
                    {
                        if (ChessAgainst.IsBarrack(hero.point) && hero.point.y > 5)               //敌方的军营
                        {
                            Common.UI.OpenTips("敌军在行营里,不要浪啊~");
                        }
                        else
                        {
                            if (ChessAgainst.IsStronghold(heroChoosed.point))
                            {
                                Common.UI.OpenTips("大本营的棋子无法移动!");
                            }
                            else
                            {
                                ChessMoveData moveData = ChessAgainst.ChessHeroCanMoveTo(heroChoosed, hero.point);
                                if (moveData.crashType > 0)
                                {
                                    if (moveData.crashType == 1)
                                    {
                                        switch (moveData.crashHero.heroTypeId)
                                        {
                                        case 0:
                                            Common.UI.OpenTips("地雷无法移动!");
                                            break;

                                        case 11:
                                            Common.UI.OpenTips("军旗无法移动!");
                                            break;

                                        default:
                                            Common.UI.OpenTips("嗷!走不过去啊!");
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        Common.UI.OpenTips("嗷!走不过去啊!");
                                    }
                                }
                                else
                                {
                                    RequestToMove(heroChoosed, hero.point, hero, moveData);
                                }
                            }
                        }
                    }
                }
            }
            App.Package.ChessGame.MyselfChooseChessId = id;
        }
        else
        {
            if (App.Package.ChessGame.IsReadyGame)
            {
                Common.UI.OpenTips("比赛还没开始哦,不要心急");
            }
            else
            {
                Common.UI.OpenTips("赶紧布兵吧!你还没有准备呢\n长按拖动可以交换棋子!");
            }
        }
    }
コード例 #19
0
    private void OnChessClick(object content)  //移动
    {
        if (App.Package.ChessGame.IsGameStart) //游戏开始了之后才能走
        {
            if (!App.Package.ChessGame.IsMyRound)
            {
                Common.UI.OpenTips("敌方回合,无法行动");
                return;
            }
            if (m_MyChessIsMoving)
            {
                return;                   //正在移动
            }
            Intent     intent = (Intent)content;
            ChessPoint point  = (ChessPoint)intent.Value("point");
            GameObject go     = (GameObject)intent.Value("gameObject");
            //Debugger.Warn("ChessItem Click:" + id +"|"+ App.Package.ChessGame.MyselfChooseChessId + "|" +App.Package.ChessGame.GetFieldRoadStationByPoint(point).type);
            if (App.Package.ChessGame.MyselfChooseChessId > -1)
            {
                ChessHeroData heroChoosed = App.Package.ChessGame.GetChessHeroDataById(App.Package.ChessGame.MyselfChooseChessId);
                if (heroChoosed.group == ChessHeroGroup.Myself)
                {
                    if (ChessAgainst.IsStronghold(heroChoosed.point))
                    {
                        Common.UI.OpenTips("大本营的棋子无法移动!");
                    }
                    else
                    {
                        ChessMoveData moveData = ChessAgainst.ChessHeroCanMoveTo(heroChoosed, point);
                        if (moveData.crashType > 0)
                        {
                            if (moveData.crashType == 1)
                            {
                                switch (moveData.crashHero.heroTypeId)
                                {
                                case 0:
                                    Common.UI.OpenTips("地雷无法移动!");
                                    break;

                                case 11:
                                    Common.UI.OpenTips("军旗无法移动!");
                                    break;

                                default:
                                    Common.UI.OpenTips("嗷!走不过去啊!");
                                    break;
                                }
                            }
                            else
                            {
                                Common.UI.OpenTips("嗷!走不过去啊!");
                            }
                        }
                        else
                        {
                            RequestToMove(heroChoosed, point, null, moveData);
                        }
                    }
                }
            }
        }
        else
        {
            if (App.Package.ChessGame.IsReadyGame)
            {
                Common.UI.OpenTips("比赛还没开始哦,不要心急");
            }
            else
            {
                Common.UI.OpenTips("赶紧布兵吧!你还没有准备呢\n长按拖动可以交换棋子!");
            }
        }
    }
コード例 #20
0
 public void RemoveChessHero(ChessHeroData chessHero)
 {
     m_ChessData.Remove(chessHero.id);
     ChessDataIds.Remove(chessHero.id);
     GameObject.Destroy(chessHero.gameObject);
 }
コード例 #21
0
    /// <summary>
    /// 走子情况
    /// </summary>
    void OnReceiveChessMove(object data)
    {
        ChessMovePush   push       = (ChessMovePush)data;
        ChessData       source     = push.Source;
        ChessData       target     = push.Target;
        ChessMoveResult result     = (ChessMoveResult)push.ChessMoveResult;
        ChessHeroData   sourceReal = App.Package.ChessGame.GetChessHeroDataByRemoteId(source.ChessRemoteId);

        //强制回合同步
        App.Package.ChessGame.GameRoundCounter = push.Counter - 1;
        if (target != null)
        {
            ChessHeroData targetReal = App.Package.ChessGame.GetChessHeroDataByRemoteId(target.ChessRemoteId);

            if (sourceReal == null || (targetReal == null && result != ChessMoveResult.CAN_MOVE && result != ChessMoveResult.CANNOT_MOVE) || push.Counter != App.Package.ChessGame.GameRoundCounter + 1)
            {
                ChessDataHasProblem();
                return;
            }
            ChessHeroData fake = ChessDataToChessHeroData(target, true);
            if (targetReal != null)
            {
                fake = targetReal;
            }
            ChessMoveData moveData = ChessAgainst.ChessHeroCanMoveTo(sourceReal, fake.point);
            switch (result)
            {
            case ChessMoveResult.LOSE:
                fake.heroTypeId = 12;
                StartCoroutine(TweenMoveChessAndBeat(sourceReal, fake, result, moveData));
                break;

            case ChessMoveResult.WIN:
                fake.heroTypeId = -2;
                StartCoroutine(TweenMoveChessAndBeat(sourceReal, fake, result, moveData));
                break;

            case ChessMoveResult.TIE:
                fake.heroTypeId = -3;
                StartCoroutine(TweenMoveChessAndBeat(sourceReal, fake, result, moveData));
                break;

            case ChessMoveResult.CAN_MOVE:
                StartCoroutine(TweenMoveChess(sourceReal, fake.point, result, moveData));
                break;

            case ChessMoveResult.CANNOT_MOVE:
                break;
            }
        }
        else
        {
            NextGameRound();
            if (source.Belong == App.Package.Player.GetBelong())
            {
                Common.UI.OpenTips("超时跳过");
            }
            else
            {
                Common.UI.OpenTips("敌方超时跳过");
            }
            Debugger.Error("skip");
        }
    }
コード例 #22
0
    public static ChessMoveData ChessHeroCanMoveTo(ChessHeroData heroData, ChessPoint point)
    {
        ChessMoveData    moveData     = new ChessMoveData();
        FieldRoadStation roadStationS = App.Package.ChessGame.GetFieldRoadStationByPoint(heroData.point);
        FieldRoadStation roadStationT = App.Package.ChessGame.GetFieldRoadStationByPoint(point);

        if (ChessHeroCanMove(heroData))//检测棋子本身,地雷、军旗不能走
        {
            //检测目的地是否禁止

            /*for(int i = 0; i < roadStationT.forbidChessHeros.Length; i++)
             * {
             *  if(heroData.heroTypeId == roadStationT.forbidChessHeros[i])
             *  {
             *      moveData.crashType = 2;
             *      moveData.crashHero = heroData;
             *      return moveData;
             *  }
             * }*/

            ///
            for (int i = 0; i < roadStationS.connectedPointIds.Length; i++)
            {
                FieldRoadStation roadStation = App.Package.ChessGame.GetFieldRoadStationById(roadStationS.connectedPointIds[i]);
                if (roadStation == roadStationT)
                {
                    moveData.crashType = 0;
                    moveData.points    = new ChessPoint[] { roadStationS.point, roadStationT.point };
                    return(moveData);
                }
            }
            if (roadStationS.type == FieldRoadStationType.Rail && roadStationT.type == FieldRoadStationType.Rail)
            {
                if (heroData.heroTypeId == 2)//工兵行走
                {
                    List <FieldRoadPath> paths        = new List <FieldRoadPath>();
                    List <int>           usedStations = new List <int>();
                    usedStations.Add(roadStationS.id);
                    FieldRoadPath pathStart = new FieldRoadPath();
                    pathStart.pathStations.Add(roadStationS.id);
                    paths.Add(pathStart);
                    LookForRailWayPath(roadStationT, paths, usedStations, 1, 32);
                    for (int i = 0; i < paths.Count; i++)
                    {
                        FieldRoadPath path = paths[i];
                        if (path.pathStations[path.pathStations.Count - 1] != roadStationT.id)
                        {
                            continue;
                        }
                        ChessPoint[]  points    = path.ToChessPoints();
                        ChessHeroData crashHero = HasChessHeroOnPathPoints(points);
                        if (crashHero == null)
                        {
                            moveData.crashType = 0;
                            moveData.crashHero = null;
                            moveData.points    = points;
                            return(moveData);
                        }
                        else
                        {
                            moveData.crashHero = heroData;
                        }
                    }
                    moveData.crashType = 3;
                    moveData.crashHero = heroData;
                    return(moveData);
                }
                else if (roadStationS.point.x == roadStationT.point.x)//这里要特别注意
                {
                    ChessPoint[] points = new ChessPoint[Mathf.Abs(roadStationS.point.y - roadStationT.point.y) + 1];
                    int          d      = (roadStationS.point.y < roadStationT.point.y) ? 1 : -1;
                    points[0] = roadStationS.point;
                    for (int i = 1; i < points.Length; i++)
                    {
                        points[i] = new ChessPoint(roadStationS.point.x, roadStationS.point.y + d * i);
                        if (!IsConnected(points[i - 1], points[i]) || !IsRailWay(points[i - 1], points[i]))//要判断是否相连啊,且都是铁路
                        {
                            moveData.crashType = 2;
                            return(moveData);
                        }
                    }
                    ChessHeroData crashHero = HasChessHeroOnPathPoints(points);
                    if (crashHero == null)
                    {
                        moveData.crashType = 0;
                        moveData.points    = points;
                    }
                    else
                    {
                        moveData.crashType = 3;
                        moveData.crashHero = crashHero;
                    }
                    return(moveData);
                }
                else if (roadStationS.point.y == roadStationT.point.y)
                {
                    ChessPoint[] points = new ChessPoint[Mathf.Abs(roadStationS.point.x - roadStationT.point.x) + 1];
                    int          d      = (roadStationS.point.x < roadStationT.point.x) ? 1 : -1;
                    points[0] = roadStationS.point;
                    for (int i = 1; i < points.Length; i++)
                    {
                        points[i] = new ChessPoint(roadStationS.point.x + d * i, roadStationS.point.y);
                        if (!IsConnected(points[i - 1], points[i]) || !IsRailWay(points[i - 1], points[i]))//要判断是否相连啊,且都是铁路
                        {
                            moveData.crashType = 2;
                            return(moveData);
                        }
                    }
                    ChessHeroData crashHero = HasChessHeroOnPathPoints(points);
                    if (crashHero == null)
                    {
                        moveData.crashType = 0;
                        moveData.points    = points;
                    }
                    else
                    {
                        moveData.crashType = 3;
                        moveData.crashHero = crashHero;
                    }
                    return(moveData);
                }
                else
                {
                    //不能走直角
                }
            }
        }
        moveData.crashType = 1;
        moveData.crashHero = heroData;
        return(moveData);
    }