コード例 #1
0
ファイル: BattleRoomCtr.cs プロジェクト: liuhaili/Chess
    public void PlayOutCard(Battle battle)
    {
        PlayerCtr playerCtr = BattleRoomCtr.Instance.GetPlayer(battle.CurrentSide.Order);
        CardCtr   cardCtr   = CardLibrary.FindCard(battle.CurrentSide.TakeOutCard.ID);

        cardCtr.transform.DOLocalMoveX(cardCtr.TargetLocalPosition.x, 0.3f);
        cardCtr.transform.DOLocalMoveY(cardCtr.TargetLocalPosition.y, 0.3f);

        string soundSex = PlayerPrefs.GetString("SoundSex");

        if (soundSex == "Man")
        {
            SoundManager.Instance.PlaySound("男声/" + battle.CurrentSide.TakeOutCard.ToString());
        }
        else
        {
            SoundManager.Instance.PlaySound("女声/" + battle.CurrentSide.TakeOutCard.ToString());
        }

        Sequence sequence = DOTween.Sequence();

        sequence.Append(cardCtr.transform.DOLocalMoveZ(cardCtr.TargetLocalPosition.z, 0.3f));
        sequence.AppendCallback(() =>
        {
            SoundManager.Instance.PlaySound("音效/出牌");
            SendCommand.NoticeOutCardBack();
        });
    }
コード例 #2
0
    public void InitCard(int num)
    {
        DesignTemplate.SetActive(false);
        //取第一张作为模板
        CardCtr cardCtr = BattleRoomCtr.Instance.CardLibrary.LibraryCards[0];
        //抓牌顺序是顺时针,所以放牌也是顺时针,从Player1开始
        //26张一堆
        float startX = DesignTemplate.transform.localPosition.x - DesignTemplate.transform.localScale.x * 0.5f;
        float startY = DesignTemplate.transform.localPosition.y;
        float startZ = DesignTemplate.transform.localPosition.z;


        for (int i = 0; i < num; i++)
        {
            GameObject mj = GameObject.Instantiate(cardCtr.gameObject);
            mj.transform.transform.parent = DesignTemplate.transform.parent;
            mj.transform.localEulerAngles = new Vector3(90, 0, 0);
            if (i % 2 == 0)
            {
                mj.transform.localPosition = new Vector3(startX + cardCtr.Size.x * 0.5f + (i / 2) * cardCtr.Size.x, startY, startZ);
            }
            else
            {
                mj.transform.localPosition = new Vector3(startX + cardCtr.Size.x * 0.5f + (i / 2) * cardCtr.Size.x, startY + cardCtr.Size.z, startZ);
            }

            CardList.Add(mj.GetComponent <CardCtr>());
        }
    }
コード例 #3
0
ファイル: CardLibraryCtr.cs プロジェクト: liuhaili/Chess
 private void Awake()
 {
     for (int i = 0; i < this.transform.childCount; i++)
     {
         CardCtr cardCtr = this.transform.GetChild(i).GetComponent <CardCtr>();
         LibraryCards.Add(cardCtr);
     }
 }
コード例 #4
0
ファイル: BattleRoomCtr.cs プロジェクト: liuhaili/Chess
    public void HideTing(CardCtr cardCtr)
    {
        Transform ting = cardCtr.transform.Find("ting");

        if (ting != null)
        {
            GameObject.Destroy(ting.gameObject);
        }
    }
コード例 #5
0
ファイル: BattleRoomCtr.cs プロジェクト: liuhaili/Chess
    public void PlayGetCard(Battle battle)
    {
        PlayerCtr playerCtr = BattleRoomCtr.Instance.GetPlayer(battle.CurrentSide.Order);
        CardCtr   newCard   = CardLibrary.FindCard(battle.CurrentSide.GetACard.ID);

        Sequence mySequence = DOTween.Sequence();

        mySequence.Append(newCard.transform.DOLocalMoveX(newCard.TargetLocalPosition.x + 0.005f, 0.3f));
        mySequence.Append(newCard.transform.DOLocalMoveY(newCard.TargetLocalPosition.y, 0.1f));
        mySequence.AppendCallback(() =>
        {
            SendCommand.TakeCardBack();
        });
    }
コード例 #6
0
ファイル: CardListCtr.cs プロジェクト: liuhaili/Chess
 public void AutoSettleCards()
 {
     CardList = CardList.OrderByDescending(c => c.IsFront ? 1 : 0).ThenBy(c => c.CardType).ThenBy(c => c.Num).ToList();
     for (int i = 0; i < CardList.Count; i++)
     {
         CardCtr cardCtr = CardList[i];
         if (cardCtr.IsFront)
         {
             cardCtr.SetUp(false);
         }
         //重新计算位置
         cardCtr.TargetLocalPosition = new Vector3(StartPosition.x + cardCtr.Size.x * 0.5f + i * cardCtr.Size.x, StartPosition.y, StartPosition.z);
     }
 }
コード例 #7
0
ファイル: CardListCtr.cs プロジェクト: liuhaili/Chess
    public void AddHandCard(CardCtr card, bool initPosition)
    {
        int num = CardList.Count;

        card.transform.parent    = DesignTemplate.transform.parent;
        card.TargetLocalPosition = new Vector3(StartPosition.x + card.Size.x * 0.5f + num * card.Size.x, StartPosition.y, StartPosition.z);
        if (initPosition)
        {
            //初始化一个位置
            card.transform.localPosition = new Vector3(1, StartPosition.y + card.Size.y, StartPosition.z);
        }
        card.SetUpright();
        CardList.Add(card);
    }
コード例 #8
0
ファイル: CardListCtr.cs プロジェクト: liuhaili/Chess
    public void AddOutCard(CardCtr card)
    {
        int num = CardList.Count;

        card.transform.parent = DesignTemplate.transform.parent;
        card.SetUp(true);
        CardList.Add(card);
        BattleRoomCtr.Instance.HideTing(card);
        for (int i = 0; i < CardList.Count; i++)
        {
            CardCtr cardCtr = CardList[i];
            //重新计算位置
            cardCtr.TargetLocalPosition = new Vector3(StartPosition.x + cardCtr.Size.x * 0.5f + i * cardCtr.Size.x, StartPosition.y, StartPosition.z);
        }
    }
コード例 #9
0
ファイル: CardLibraryCtr.cs プロジェクト: liuhaili/Chess
    public CardCtr GetOrCreateCard(int id, CardType cardType, int num)
    {
        if (AllShowCards.ContainsKey(id))
        {
            CardCtr oldCardCtr = AllShowCards[id];
            oldCardCtr.IsNew = false;
            return(oldCardCtr);
        }
        CardCtr cardCtr = GetCard(cardType, num);

        cardCtr.ID    = id;
        cardCtr.IsNew = true;
        AllShowCards.Add(cardCtr.ID, cardCtr);
        return(cardCtr);
    }
コード例 #10
0
ファイル: CardLibraryCtr.cs プロジェクト: liuhaili/Chess
    private CardCtr GetCard(CardType cardType, int num)
    {
        for (int i = 0; i < LibraryCards.Count; i++)
        {
            CardCtr cardCtr = LibraryCards[i];
            ////测试 TODO
            //cardCtr.CardType = cardType;
            //cardCtr.Num = num;

            if (cardCtr.CardType == cardType && cardCtr.Num == num)
            {
                LibraryCards.Remove(cardCtr);
                return(cardCtr);
            }
        }
        return(null);
    }
コード例 #11
0
    public void AddCardToOutCards(CardCtr card)
    {
        int outCards1Count = this.OutCards1.ListCards().Count;
        int outCards2Count = this.OutCards2.ListCards().Count;

        card.IsFront = true;
        if (outCards1Count < 4)
        {
            OutCards1.AddOutCard(card);
        }
        else if (outCards2Count < 5)
        {
            OutCards2.AddOutCard(card);
        }
        else
        {
            OutCards3.AddOutCard(card);
        }
    }
コード例 #12
0
ファイル: BattleRoomCtr.cs プロジェクト: liuhaili/Chess
    public void ShowTing(CardCtr cardCtr)
    {
        Transform ting = cardCtr.transform.Find("ting");

        if (ting != null)
        {
            cardCtr.gameObject.SetActive(true);
        }
        else
        {
            GameObject tingObj = new GameObject();
            tingObj.name                       = "ting";
            tingObj.transform.parent           = cardCtr.gameObject.transform;
            tingObj.transform.localPosition    = new Vector3(0, 0.0334f, 0.0118f);
            tingObj.transform.localEulerAngles = new Vector3(0, 180, 0);
            tingObj.transform.localScale       = new Vector3(0.05f, 0.05f, 0.05f);
            SpriteRenderer sprite = tingObj.AddComponent <SpriteRenderer>();
            sprite.sprite = TingSprite;
        }
    }
コード例 #13
0
ファイル: BattleRoomCtr.cs プロジェクト: liuhaili/Chess
    /// <summary>
    /// 同步数据,玩家在网络不好,或是断线重连时会直接显示当前数据
    /// </summary>
    /// <param name="battle"></param>
    public void SynchronousData(Battle battle)
    {
        SendCommand.BattleCode = battle.Code;
        //if (battle.CratorID == SendCommand.UserID)
        //{
        //    BattleUI.BtnJSRoom.gameObject.SetActive(true);
        //}
        //else
        //{
        //    BattleUI.BtnJSRoom.gameObject.SetActive(false);
        //}
        if (battle.Step != BattleCommand.CreateBattleBack &&
            (int)battle.Step > (int)BattleCommand.RollDice)
        {
            IsBattleing = true;
        }
        BattleUI.MatchLoading.gameObject.SetActive(false);
        BattleUI.EnableOperation();

        //同步玩家信息
        OneSide mySide = battle.Sides.FirstOrDefault(c => c.AccountID == SendCommand.UserID);

        if (mySide == null)
        {
            return;
        }
        if (GlobalVariable.IsBattleRecordPlay && battle.CurrentSide != null)
        {
            mySide = battle.CurrentSide;
        }
        SetCurrentPlayer(mySide.Order);
        int orderOffset = mySide.Order - 1;

        BattleUI.BattleCode.text   = battle.Code;
        BattleUI.LeaveCardNum.text = battle.LibraryCardNum.ToString();

        if (ZhuoXinRenderer != null && battle.CurrentSide != null)
        {
            if (battle.CurrentSide.Order == 1)
            {
                ZhuoXinRenderer.sharedMaterial.SetTexture("_MainTex", MJZhuoTextureN);
            }
            else if (battle.CurrentSide.Order == 2)
            {
                ZhuoXinRenderer.sharedMaterial.SetTexture("_MainTex", MJZhuoTextureX);
            }
            else if (battle.CurrentSide.Order == 3)
            {
                ZhuoXinRenderer.sharedMaterial.SetTexture("_MainTex", MJZhuoTextureB);
            }
            else if (battle.CurrentSide.Order == 4)
            {
                ZhuoXinRenderer.sharedMaterial.SetTexture("_MainTex", MJZhuoTextureD);
            }
        }

        foreach (var p in BattleUI.PlayerUIList)
        {
            int newOrder = p.Order + orderOffset;
            if (newOrder > 4)
            {
                newOrder = newOrder % 4;
            }
            OneSide side = battle.Sides.FirstOrDefault(c => c.Order == newOrder);
            if (side != null)
            {
                p.Show(side.NickName, side.Face, side.TotalScore, side.Vip, System.Convert.ToInt32(side.AccountID), battle);
            }
            else
            {
                p.gameObject.SetActive(false);
            }
            if (IsBattleing)
            {
                p.GoOut.gameObject.SetActive(false);
            }
        }
        //同步卡牌信息
        foreach (var p in PlayerList)
        {
            if (battle.Sides == null)
            {
                continue;
            }
            OneSide oneSide = battle.Sides.FirstOrDefault(c => c.Order == p.Order);
            if (oneSide == null)
            {
                continue;
            }
            p.UserID = oneSide.AccountID;
            //同步手牌区
            foreach (var c in oneSide.Cards)
            {
                CardCtr cardCtr = p.HandCards.GetCard(c.ID);
                if (cardCtr == null)
                {
                    CardCtr newCard = CardLibrary.GetOrCreateCard(c.ID, c.Type, c.Num);
                    newCard.IsFront   = c.IsFront;
                    newCard.PlayerCtr = p;
                    p.AddCardToHandCards(newCard, newCard.IsNew);
                }
                else
                {
                    cardCtr.IsFront = c.IsFront;
                }
            }
            List <CardCtr> handCards = new List <CardCtr>(p.HandCards.ListCards());
            foreach (var cc in handCards)
            {
                if (!oneSide.Cards.Any(c => c.ID == cc.ID))
                {
                    p.HandCards.RemoveCard(cc);
                }
            }
            //同步出牌区
            foreach (var c in oneSide.OutCards)
            {
                CardCtr cardCtr = p.OutCards1.GetCard(c.ID);
                if (cardCtr == null)
                {
                    cardCtr = p.OutCards2.GetCard(c.ID);
                }
                if (cardCtr == null)
                {
                    cardCtr = p.OutCards3.GetCard(c.ID);
                }
                if (cardCtr == null)
                {
                    CardCtr newCard = CardLibrary.GetOrCreateCard(c.ID, c.Type, c.Num);
                    p.AddCardToOutCards(newCard);
                }
                else
                {
                    cardCtr.IsFront = c.IsFront;
                }
            }
            List <CardCtr> outCards = new List <CardCtr>(p.OutCards1.ListCards());
            outCards.AddRange(p.OutCards2.ListCards());
            outCards.AddRange(p.OutCards3.ListCards());
            foreach (var cc in outCards)
            {
                if (!oneSide.OutCards.Any(c => c.ID == cc.ID))
                {
                    p.OutCards1.RemoveCard(cc);
                    p.OutCards2.RemoveCard(cc);
                }
            }
        }
        //获取听牌列表
        List <Card> listenCards = ChessHelper.CanListenCardList(mySide.Cards);
        PlayerCtr   myPlayerCtr = PlayerList.FirstOrDefault(c => c.UserID == mySide.AccountID);

        foreach (var c in myPlayerCtr.HandCards.CardList)
        {
            if (IsCanOutCard && listenCards.Any(b => b.ID == c.ID))
            {
                ShowTing(c);
            }
            else
            {
                HideTing(c);
            }
        }
        //重新计算位置
        if ((battle.Step != BattleCommand.TakeCard && battle.Step != BattleCommand.HandOutCard) || GlobalVariable.IsBattleRecordPlay)
        {
            foreach (var p in PlayerList)
            {
                p.HandCards.AutoSettleCards();
            }
        }
        //排除可能要播动画的,其它的直接设置位置
        if (battle.Step == BattleCommand.Licensing)
        {
        }
        else if (battle.Step == BattleCommand.TakeCard)
        {
            foreach (var c in CardLibrary.ListAllShowCards())
            {
                if (c.ID == battle.CurrentSide.GetACard.ID)
                {
                    continue;
                }
                c.transform.localPosition = c.TargetLocalPosition;
            }
        }
        else if (battle.Step == BattleCommand.HandOutCard)
        {
            foreach (var c in CardLibrary.ListAllShowCards())
            {
                if (battle.CurrentSide.GetACard != null && c.ID == battle.CurrentSide.GetACard.ID)
                {
                    continue;
                }
                c.transform.localPosition = c.TargetLocalPosition;
            }
        }
        else if (battle.Step == BattleCommand.NoticeOutCard)
        {
            foreach (var c in CardLibrary.ListAllShowCards())
            {
                if (c.ID == battle.CurrentSide.TakeOutCard.ID)
                {
                    continue;
                }
                c.transform.localPosition = c.TargetLocalPosition;
            }
        }
        else if (battle.Step == BattleCommand.NoticeTouchCard)
        {
            foreach (var c in CardLibrary.ListAllShowCards())
            {
                if (battle.CurrentSide.TakeOutCard == null)
                {
                    continue;
                }
                if (c.IsFront && c.CardType == battle.CurrentSide.TakeOutCard.Type && c.Num == battle.CurrentSide.TakeOutCard.Num)
                {
                    continue;
                }
                c.transform.localPosition = c.TargetLocalPosition;
            }
        }
        else
        {
            foreach (var c in CardLibrary.ListAllShowCards())
            {
                c.transform.localPosition = c.TargetLocalPosition;
            }
        }
    }
コード例 #14
0
ファイル: CardListCtr.cs プロジェクト: liuhaili/Chess
 public void RemoveCard(CardCtr card)
 {
     CardList.RemoveAll(c => c.ID == card.ID);
 }
コード例 #15
0
 public void AddCardToHandCards(CardCtr card, bool initPosition)
 {
     HandCards.AddHandCard(card, initPosition);
 }