public override void OnOpen(Intent intent)
    {
        base.OnOpen(intent);
        Debugger.Log("MainPanel Open");
        string ip = PlayerPrefs.GetString("hostIp");

        if (ip != "")
        {
            ipInput.value = ip;
        }
        FieldRoadStation s1 = new FieldRoadStation()
        {
            type  = FieldRoadStationType.Rail,
            point = new ChessPoint(1, 5),
        };
        FieldRoadStation s2 = new FieldRoadStation()
        {
            type  = FieldRoadStationType.Barrack,
            point = new ChessPoint(1, 6),
        };

        Debugger.Warn(ChessAgainst.IsBarrack(new ChessPoint(1, 7)));
        Debugger.Warn(ChessAgainst.InRailArea(new ChessPoint(0, 7)));
        Debugger.Warn(ChessAgainst.InRailArea(new ChessPoint(1, 6)));
        Debugger.Warn(ChessAgainst.InRailArea(new ChessPoint(1, 10)));
        Debugger.Warn(ChessAgainst.InRailArea(new ChessPoint(4, 6)));
        //App.Manager.UI.ReplaceView("UIGamePanel");
        //OnSetIp();
    }
 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("已经准备就绪,无法调整棋子");
         }
     }
 }
    /// <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("初始化棋子位置错误!");
            }
        }
    }
Example #4
0
    /// <summary>
    /// 初始化战场的道路连接数据
    /// </summary>
    public void InitFieldMap()
    {
        m_MapRoadStations.Clear();
        for (int i = 0; i < 12; i++)
        {
            for (int j = 0; j < 5; j++)
            {
                FieldRoadStation roadStation = new FieldRoadStation();
                roadStation.point = new ChessPoint(j, i);
                if (ChessAgainst.InRailArea(roadStation.point))
                {
                    roadStation.type = FieldRoadStationType.Rail;
                }
                else if (ChessAgainst.IsBarrack(roadStation.point))
                {
                    roadStation.type = FieldRoadStationType.Barrack;
                }
                roadStation.id = m_MapRoadStations.Count;
                m_MapRoadStations.Add(roadStation);
            }
        }
        List <int> connetedIds = new List <int>();

        for (int i = 0; i < m_MapRoadStations.Count; i++)
        {
            connetedIds.Clear();
            for (int j = 0; j < m_MapRoadStations.Count; j++)
            {
                if (i != j)
                {
                    if (ChessAgainst.IsConnected(m_MapRoadStations[i], m_MapRoadStations[j]))
                    {
                        connetedIds.Add(j);
                        //Debugger.Warn(m_MapRoadStations[i].point.ToString()+" => "+ m_MapRoadStations[j].point.ToString());
                    }
                }
            }
            m_MapRoadStations[i].connectedPointIds = connetedIds.ToArray();
        }
    }
    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长按拖动可以交换棋子!");
            }
        }
    }
    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长按拖动可以交换棋子!");
            }
        }
    }
    /// <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");
        }
    }