Exemple #1
0
    /*public ChessHeroGroup GetChessGroupById(int id)
     * {
     *  if (id < 100) return ChessHeroGroup.Myself;
     *  if (id>=100 && id < 200) return ChessHeroGroup.Enemy;
     *  return ChessHeroGroup.Enemy;
     * }*/

    public List <ChessHeroData> GetChessHeroList(ChessHeroGroup group)
    {
        List <ChessHeroData> list = new List <ChessHeroData>();

        foreach (var item in m_ChessData)
        {
            switch (group)
            {
            case ChessHeroGroup.Myself:
                if (item.Value.id < 100)
                {
                    list.Add(item.Value);
                }
                break;

            case ChessHeroGroup.Enemy:
                if (item.Value.id >= 100 && item.Value.id < 200)
                {
                    list.Add(item.Value);
                }
                break;
            }
        }
        return(list);
    }
Exemple #2
0
    public string GetChessStringData(ChessHeroGroup group)
    {
        int[,] mapPosition = new int[5, 12];
        foreach (var item in m_ChessData)
        {
            if (item.Value.group == group)
            {
                mapPosition[item.Value.point.x, item.Value.point.y] = item.Value.heroTypeId + 1;
            }
        }
        string re = "";

        for (int i = 0; i < mapPosition.GetLength(1); i++)
        {
            for (int j = 0; j < mapPosition.GetLength(0); j++)
            {
                if (j > 0)
                {
                    re += ",";
                }
                if (mapPosition[j, i] > 0)
                {
                    re += (mapPosition[j, i] - 1).ToString();
                }
            }
            re += ";";
        }
        return(re);
    }
    void UpdatePlayer(ChessHeroGroup group)
    {
        switch (group)
        {
        case ChessHeroGroup.Myself: {
            m_MyselfState.UpdateState(App.Package.Player.playerInfo);
            break;
        }

        case ChessHeroGroup.Enemy: {
            m_EnemyState.UpdateState(App.Package.ChessGame.EnemyPlayerList[0]);
            break;
        }
        }
    }
Exemple #4
0
    public List <ChessData> GetChessData(ChessHeroGroup group)
    {
        List <ChessData> list = new List <ChessData>();

        foreach (var item in m_ChessData)
        {
            if (item.Value.group == group)
            {
                ChessData chess = new ChessData();
                chess.ChessRemoteId = item.Value.remoteId;
                chess.Group         = (int)item.Value.group;
                chess.Point         = item.Value.point.ParseToRpc();
                chess.ChessType     = item.Value.heroTypeId;
                list.Add(chess);
            }
        }

        return(list);
    }
    /// <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("初始化棋子位置错误!");
            }
        }
    }
Exemple #6
0
    public List <ChessData> ParseChessDataFromString(string data, string belong)
    {
        List <ChessData> chessList = new List <ChessData>();
        int            baseId      = GetBaseId(belong);
        int            offsetY     = 0;
        ChessHeroGroup group       = (ChessHeroGroup)(baseId / 100);

        string[] rows = data.Split(';');
        for (int i = 0; i < rows.Length && i < 6; i++)
        {
            string[] chessTypeIds = rows[i].Split(',');
            for (int j = 0; j < chessTypeIds.Length; j++)
            {
                string id = chessTypeIds[j];
                if (id != "")
                {
                    int type     = -1;
                    int remoteId = 0;
                    if (id.IndexOf("|") > -1)
                    {
                        string[] ids = id.Split('|');
                        type     = int.Parse(ids[0]);
                        remoteId = int.Parse(ids[1]);
                    }
                    else
                    {
                        type = int.Parse(id);
                    }
                    ChessData heroData = new ChessData();
                    heroData.ChessType     = type;
                    heroData.ChessRemoteId = remoteId;
                    heroData.Group         = (int)group;
                    heroData.Belong        = belong;
                    heroData.Point         = new Com.Violet.Rpc.ChessPoint();
                    heroData.Point.X       = j;
                    heroData.Point.Y       = offsetY + i;
                    chessList.Add(heroData);
                }
            }
        }
        return(chessList);
    }
    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长按拖动可以交换棋子!");
            }
        }
    }