Example #1
0
    /// <summary>
    /// 玩家请求出牌
    /// </summary>
    private void onPlayerPlayCard()
    {
        List <Card> cardList = CharacterView.Player.FindSelectCard();
        CardType    cardType;

        Rulers.CanPop(cardList, out cardType);

        //!#@!#!@$!@#!@$!@%!@#
        //还需要根据上一次的出牌类型

        if (cardType != CardType.None)
        {
            //可以出牌
            PlayCardArgs e = new PlayCardArgs()
            {
                cardType      = cardType,
                characterType = CharacterType.Player,
                Length        = cardList.Count,
                Weight        = Tools.GetWeight(cardList, cardType)
            };
            dispatcher.Dispatch(CommandEvent.PlayCard, e);
        }
        else
        {
            UnityEngine.Debug.Log("请选择正确的牌");
        }
    }
Example #2
0
        private void button5_Click(object sender, EventArgs e)
        {
            this.DisablePlayerUI();
            var args = new PlayCardArgs(null, null, true, false);

            this.End(sender, args);
        }
Example #3
0
        private void RaisePlay(object sender, EventArgs e)
        {
            // TODO: delete this metod

            var box  = sender as PictureBox;
            var args = new PlayCardArgs(null, box.Image.Tag.ToString(), true, this.EndTurnButton.Enabled);

            this.PlayCardEvent(sender, args);

            if (args == null)
            {
                throw new NullReferenceException("Played card cannot be null");
            }
            this.AssignPicture(args.PlayedCard, this.GetField(args.PlayedCard), args.FaceUp);
        }
    public override void Execute()
    {
        PlayCardArgs e = evt.data as PlayCardArgs;

        //判断玩家出牌合不合法
        if (e.characterType == CharacterType.Player)
        {
            if (e.cardType == RoundModel.CardType && e.Weight > RoundModel.Weight)
            {
                dispatcher.Dispatch(ViewEvent.SUCCESSED_PLAY);
            }
            else if (e.cardType == CardType.Boom && RoundModel.CardType != CardType.Boom)
            {
                dispatcher.Dispatch(ViewEvent.SUCCESSED_PLAY);
            }
            else if (e.cardType == CardType.JokerBoom)
            {
                dispatcher.Dispatch(ViewEvent.SUCCESSED_PLAY);
            }
            else if (RoundModel.Biggest == CharacterType.Player)
            {
                dispatcher.Dispatch(ViewEvent.SUCCESSED_PLAY);
            }
            else
            {
                Debug.Log("不合法的出牌");
                return;
            }
        }

        //炸弹翻倍
        if (e.cardType == CardType.Boom || e.cardType == CardType.JokerBoom)
        {
            IntegrationModel.Multiples *= 2;
        }

        //保存回合信息
        RoundModel.Length   = e.Length;
        RoundModel.Weight   = e.Weight;
        RoundModel.CardType = e.cardType;
        RoundModel.Biggest  = e.characterType;

        //转换出牌
        RoundModel.Turn();
    }
    /// <summary>
    /// 玩家出牌的类型
    /// </summary>
    /// <param name="payload"></param>
    private void OnPlayerPlayCard()
    {
        List <Card> cardsList = characterView.m_player.FindCards();//获取被选中牌的集合
        CardType    pcardType;

        if (Rulers.CanPOp(cardsList, out pcardType))//判断能否出牌,并返回出牌的类型
        {
            //把数据封装,让外界处理选择牌能否出成功
            PlayCardArgs play = new PlayCardArgs()
            {
                characterType = CharacterType.Player,
                length        = cardsList.Count,
                weight        = ToolsManager.GetWeight(cardsList, pcardType),
                cardType      = pcardType
            };
            dispatcher.Dispatch(CommandEvent.PlayCard, play);//派发判断能否出牌成功的命令
        }
    }
Example #6
0
    public override void Execute()
    {
        PlayCardArgs e = evt.data as PlayCardArgs;

        if (e.CharacterType == CharacterType.Player)
        {
            if (e.CardType == RoundModel.CurrentType && e.Length == RoundModel.CurrentLength &&
                e.Weight > RoundModel.CurrentWeight)
            {
                dispatcher.Dispatch(ViewEvent.SuccessedPlay);
            }
            else if (e.CardType == CardType.Boom && RoundModel.CurrentType != CardType.Boom)
            {
                dispatcher.Dispatch(ViewEvent.SuccessedPlay);
            }
            else if (e.CardType == CardType.JokerBoom)
            {
                dispatcher.Dispatch(ViewEvent.SuccessedPlay);
            }
            else if (e.CharacterType == RoundModel.BiggestCharacter)
            {
                dispatcher.Dispatch(ViewEvent.SuccessedPlay);
            }
            else
            {
                UnityEngine.Debug.Log("重新选择");
                return;
            }
        }


        //更新数据
        RoundModel.BiggestCharacter = e.CharacterType;

        RoundModel.CurrentLength = e.Length;
        RoundModel.CurrentWeight = e.Weight;
        RoundModel.CurrentType   = e.CardType;


        //换人
        RoundModel.Turn();
    }
Example #7
0
        private void RaisePlay(object sender, MouseEventArgs e)
        {
            // TODO: add a message box that ask for monster position or something like that

            bool left = e.Button == MouseButtons.Left;

            var box  = sender as PictureBox;
            var args = new PlayCardArgs(null, box.Image.Tag.ToString(), left, this.EndTurnButton.Enabled);

            this.PlayCardEvent(sender, args);

            if (args == null)
            {
                throw new NullReferenceException("Played card cannot be null");
            }

            box.Image = null;

            this.AssignPicture(args.PlayedCard, this.GetField(args.PlayedCard), left);
        }
Example #8
0
    /// <summary>
    /// 玩家出牌调用
    /// </summary>
    private void OnPlayerPlayCard()
    {
        //不能直接出牌,需要判断
        List <Card> cardList = CharacterView.PlayerController.FindSelected();
        CardType    cardType;

        if (Ruler.CanPop(cardList, out cardType))
        {
            PlayCardArgs e = new PlayCardArgs()
            {
                CardType      = cardType,
                CharacterType = CharacterType.Player,
                Length        = cardList.Count,
                Weight        = Tools.GetWeight(cardList, cardType)
            };
            UnityEngine.Debug.Log(cardType.ToString());
            dispatcher.Dispatch(CommandEvent.PlayCard, e);
        }
        else
        {
            Debug.Log("牌不对!");
        }
    }
    /// <summary>
    /// 电脑玩家出牌的方法
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    IEnumerator DePlay(ComputerSmartArgs obj)
    {
        yield return(new WaitForSeconds(2));

        bool can = false;

        switch (obj.currentCharacter)
        {
        case CharacterType.ComputerRight:
            //清空桌面
            characterView.m_Desk.ClearList(ShowPoint.ComputerRight);
            can = characterView.m_ComputerRight.SmartSelectCards(obj.cardType, obj.weight, obj.Length, CharacterType.ComputerRight == obj.isBiggest);
            //获取电脑玩家出牌的集合
            List <Card> Rightcards = characterView.m_ComputerRight.SelectedCard;
            //获取出牌的类型
            CardType RightcardType = characterView.m_ComputerRight.cardType;
            if (can)
            {
                //桌面添加出的牌
                foreach (var item in Rightcards)
                {
                    characterView.m_Desk.AddCard(item, false, ShowPoint.ComputerRight);
                }
                //封装玩家出牌后的传递数据
                PlayCardArgs play = new PlayCardArgs()
                {
                    cardType = RightcardType, length = Rightcards.Count, weight = ToolsManager.GetWeight(Rightcards, RightcardType), characterType = CharacterType.ComputerRight
                };

                //删除手牌
                //在调用SmartSelectCards方法时,出牌成功,就自动删除
                //出牌成功
                if (!characterView.m_ComputerRight.IHasCard)    //判断牌是否有剩余
                {
                    //游戏结束
                    Identity      p     = characterView.m_player.PlayerIdentity;
                    Identity      Left  = characterView.m_ComputerLeft.PlayerIdentity;
                    Identity      Right = characterView.m_ComputerRight.PlayerIdentity;
                    CharacterType gg    = CharacterType.Player;
                    if (p == Identity.Landlord)
                    {
                        gg = CharacterType.Player;
                    }
                    else if (Left == Identity.Landlord)
                    {
                        gg = CharacterType.ComputerLeft;
                    }
                    else if (Right == Identity.Landlord)
                    {
                        gg = CharacterType.ComputerRight;
                    }
                    GameOverArgs e = new GameOverArgs()
                    {
                        ComputerRigh = true,
                        ComputerLeft = Right == Left ? true : false,
                        PlayerWin    = p == Right ? true : false,
                        type         = gg,
                        isLand       = p == Identity.Landlord ? true : false
                    };
                    dispatcher.Dispatch(CommandEvent.GameOver, e);
                }
                else
                {
                    dispatcher.Dispatch(CommandEvent.PlayCard, play);    //下家出牌
                }
            }
            else
            {
                //不出牌
                dispatcher.Dispatch(CommandEvent.PassCard);
            }
            break;

        case CharacterType.ComputerLeft:
            //清空桌面
            characterView.m_Desk.ClearList(ShowPoint.ComputerLeft);
            can = characterView.m_ComputerLeft.SmartSelectCards(obj.cardType, obj.weight, obj.Length, CharacterType.ComputerLeft == obj.isBiggest);
            //获取电脑玩家出牌的集合
            List <Card> cards = characterView.m_ComputerLeft.SelectedCard;
            //获取出牌的类型
            CardType cardType = characterView.m_ComputerLeft.cardType;
            if (can)
            {
                //桌面添加出的牌
                foreach (var item in cards)
                {
                    characterView.m_Desk.AddCard(item, false, ShowPoint.ComputerLeft);
                }
                //封装玩家出牌后的传递数据
                PlayCardArgs play = new PlayCardArgs()
                {
                    cardType = cardType, length = cards.Count, weight = ToolsManager.GetWeight(cards, cardType), characterType = CharacterType.ComputerLeft
                };

                //删除手牌
                //在调用SmartSelectCards方法时,出牌成功,就自动删除
                //出牌成功
                if (!characterView.m_ComputerLeft.IHasCard)    //判断牌是否有剩余
                {
                    //游戏结束
                    Identity      p     = characterView.m_player.PlayerIdentity;
                    Identity      Left  = characterView.m_ComputerLeft.PlayerIdentity;
                    Identity      Right = characterView.m_ComputerRight.PlayerIdentity;
                    CharacterType gg    = CharacterType.Player;
                    if (p == Identity.Landlord)
                    {
                        gg = CharacterType.Player;
                    }
                    else if (Left == Identity.Landlord)
                    {
                        gg = CharacterType.ComputerLeft;
                    }
                    else if (Right == Identity.Landlord)
                    {
                        gg = CharacterType.ComputerRight;
                    }
                    GameOverArgs e = new GameOverArgs()
                    {
                        ComputerLeft = true,
                        ComputerRigh = Right == Left ? true : false,
                        PlayerWin    = p == Left ? true : false,
                        type         = gg,
                        isLand       = p == Identity.Landlord ? true : false
                    };
                    dispatcher.Dispatch(CommandEvent.GameOver, e);    //派发游戏结束命令
                }
                else
                {
                    dispatcher.Dispatch(CommandEvent.PlayCard, play);   //下家出牌
                }
            }
            else
            {
                //不出牌
                dispatcher.Dispatch(CommandEvent.PassCard);
            }
            break;

        default:
            break;
        }
        // characterView.m_ComputerLeft.SmartSelectCards();
    }
Example #10
0
    /// <summary>
    /// 电脑出牌
    /// </summary>
    /// <param name="e"></param>
    /// <returns></returns>
    IEnumerator Delay(ComputerSmartArgs e)
    {
        bool can = false;

        yield return(new WaitForSeconds(1f));

        switch (e.CharacterType)
        {
        case CharacterType.ComputerRight:
            //清空桌面
            CharacterView.DeskController.Clear(ShowPoint.ComputerRight);

            can = CharacterView.ComputerRightController.SmartSelectCards(e.CardType, e.Weight, e.Length,
                                                                         e.IsBiggest == CharacterType.ComputerRight);
            //UnityEngine.Debug.Log(e.IsBiggest.ToString());
            //UnityEngine.Debug.Log("CRight"+can);
            if (can)
            {
                List <Card> cardList = CharacterView.ComputerRightController.SelectCards;
                CardType    CurrType = CharacterView.ComputerRightController.CurrentType;
                //添加牌到桌面
                foreach (var card in cardList)
                {
                    CharacterView.DeskController.AddCard(card, false, ShowPoint.ComputerRight);
                }
                PlayCardArgs ee = new PlayCardArgs()
                {
                    CardType      = CurrType,
                    Length        = cardList.Count,
                    CharacterType = CharacterType.ComputerRight,
                    Weight        = Tools.GetWeight(cardList, CurrType)
                };
                //判断胜负
                if (!CharacterView.ComputerRightController.HasCard)
                {
                    Identity     r   = CharacterView.ComputerRightController.Identity;
                    Identity     l   = CharacterView.ComputerLeftController.Identity;
                    Identity     p   = CharacterView.PlayerController.Identity;
                    GameOverArgs eee = new GameOverArgs()
                    {
                        ComputerRightWin = true,
                        ComputerLeftWin  = l == r?true:false,
                        PlayWin          = p == r?true:false,
                        isLandlord       = p == Identity.Landlord
                    };
                    dispatcher.Dispatch(CommandEvent.GameOver);
                }
                else
                {
                    dispatcher.Dispatch(CommandEvent.PlayCard, ee);
                }
            }
            else
            {
                dispatcher.Dispatch(CommandEvent.PassCard);
            }

            break;

        case CharacterType.ComputerLeft:
            //清空桌面
            CharacterView.DeskController.Clear(ShowPoint.ComputerLeft);

            can = CharacterView.ComputerLeftController.SmartSelectCards(e.CardType, e.Weight, e.Length,
                                                                        e.IsBiggest == CharacterType.ComputerLeft);
            //UnityEngine.Debug.Log("cOMPUTER LEFT    "+can);
            //UnityEngine.Debug.Log(e.IsBiggest.ToString());
            if (can)
            {
                List <Card> cardList = CharacterView.ComputerLeftController.SelectCards;
                CardType    CurrType = CharacterView.ComputerLeftController.CurrentType;
                //添加牌到桌面
                foreach (var card in cardList)
                {
                    CharacterView.DeskController.AddCard(card, false, ShowPoint.ComputerLeft);
                }
                PlayCardArgs ee = new PlayCardArgs()
                {
                    CardType      = CurrType,
                    Length        = cardList.Count,
                    CharacterType = CharacterType.ComputerLeft,
                    Weight        = Tools.GetWeight(cardList, CurrType)
                };
                //判断胜负
                if (!CharacterView.ComputerLeftController.HasCard)
                {
                    Identity     r   = CharacterView.ComputerRightController.Identity;
                    Identity     l   = CharacterView.ComputerLeftController.Identity;
                    Identity     p   = CharacterView.PlayerController.Identity;
                    GameOverArgs eee = new GameOverArgs()
                    {
                        ComputerLeftWin  = true,
                        ComputerRightWin = r == l?true:false,
                        PlayWin          = p == l?true:false,
                        isLandlord       = p == Identity.Landlord
                    };
                    dispatcher.Dispatch(CommandEvent.GameOver);
                }
                else
                {
                    dispatcher.Dispatch(CommandEvent.PlayCard, ee);
                }
            }
            else
            {
                dispatcher.Dispatch(CommandEvent.PassCard);
            }

            break;
        }
    }
Example #11
0
    /// <summary>
    /// 延迟出牌
    /// </summary>
    IEnumerator DelayOneSecond(ComputerSmartArgs e)
    {
        yield return(new WaitForSeconds(1f));

        bool can = false;

        switch (e.CharacterType)
        {
        case CharacterType.ComputerRight:
            can = CharacterView.ComputerRight.ComputerSmartPlayCard(e.CardType, e.Weight, e.Length, e.Biggest == CharacterType.ComputerRight);
            //出牌的检测
            if (can)
            {
                List <Card> cardList =
                    CharacterView.ComputerRight.SelectCards;
                CardType cardType = CharacterView.ComputerRight.CurrType;

                //添加牌到桌面
                CharacterView.Desk.Clear();
                foreach (Card card in cardList)
                {
                    CharacterView.AddCard(CharacterType.Desk, card, false);
                }

                //可以出牌
                PlayCardArgs ee = new PlayCardArgs()
                {
                    cardType      = cardType,
                    characterType = CharacterType.ComputerRight,
                    Length        = cardList.Count,
                    Weight        = Tools.GetWeight(cardList, cardType)
                };

                if (!CharacterView.ComputerRight.HasCard)
                {
                    Identity     r   = CharacterView.ComputerRight.Identity;
                    Identity     l   = CharacterView.ComputerLeft.Identity;
                    Identity     p   = CharacterView.Player.Identity;
                    GameOverArgs eee = new GameOverArgs()
                    {
                        ComputerRightWin = true,
                        ComputerLeftWin  = l == r ? true : false,
                        PlayerWin        = p == r ? true : false
                    };
                    dispatcher.Dispatch(CommandEvent.GameOver, eee);
                }
                else
                {
                    dispatcher.Dispatch(CommandEvent.PlayCard, ee);
                }
            }
            else
            {
                dispatcher.Dispatch(CommandEvent.PassCard);
            }
            break;

        case CharacterType.ComputerLeft:
            can = CharacterView.ComputerLeft.ComputerSmartPlayCard(e.CardType, e.Weight, e.Length, e.Biggest == CharacterType.ComputerLeft);
            //出牌的检测
            if (can)
            {
                List <Card> cardList =
                    CharacterView.ComputerLeft.SelectCards;
                CardType cardType = CharacterView.ComputerLeft.CurrType;

                //添加牌到桌面
                CharacterView.Desk.Clear();
                foreach (Card card in cardList)
                {
                    CharacterView.AddCard(CharacterType.Desk, card, false);
                }

                //可以出牌
                PlayCardArgs ee = new PlayCardArgs()
                {
                    cardType      = cardType,
                    characterType = CharacterType.ComputerLeft,
                    Length        = cardList.Count,
                    Weight        = Tools.GetWeight(cardList, cardType)
                };

                if (!CharacterView.ComputerLeft.HasCard)
                {
                    Identity     r   = CharacterView.ComputerRight.Identity;
                    Identity     l   = CharacterView.ComputerLeft.Identity;
                    Identity     p   = CharacterView.Player.Identity;
                    GameOverArgs eee = new GameOverArgs()
                    {
                        ComputerLeftWin  = true,
                        ComputerRightWin = r == l ? true : false,
                        PlayerWin        = p == l ? true : false
                    };
                    dispatcher.Dispatch(CommandEvent.GameOver, eee);
                }
                else
                {
                    dispatcher.Dispatch(CommandEvent.PlayCard, ee);
                }
            }
            else
            {
                dispatcher.Dispatch(CommandEvent.PassCard);
            }
            break;

        default:
            break;
        }
    }
    public override void Execute()
    {
        PlayCardArgs args = (PlayCardArgs)evt.data;



        if (args.characterType == CharacterType.Player)
        {
            if (args.cardType == round.CurrentCardType && args.length == round.CurrentLength &&
                args.weight > round.CurrentWeight)//同类型牌,玩家是否大于上家
            {
                dispatcher.Dispatch(ViewEvent.SuccessedPlayCard);
            }
            else if (args.cardType == CardType.Boom && round.CurrentCardType != CardType.Boom)//玩家是炸弹,而上家不是炸弹
            {
                dispatcher.Dispatch(ViewEvent.SuccessedPlayCard);
            }
            else if (args.cardType == CardType.JokerBoom)//玩家出牌王炸
            {
                dispatcher.Dispatch(ViewEvent.SuccessedPlayCard);
            }
            else if (args.characterType == round.BiggestCharacter)//玩家就是最大的牌,可以自由出牌
            {
                dispatcher.Dispatch(ViewEvent.SuccessedPlayCard);
            }
            else
            {
                UnityEngine.Debug.Log("请重新选择");
                return;
            }
        }
        //音效
        if (args.characterType != round.BiggestCharacter &&
            args.cardType != CardType.Single &&
            args.cardType != CardType.Double
            )
        {
            Sound.Instance.PlayEffect(Consts.PlayCard[UnityEngine.Random.Range(0, 3)]);//音效
        }
        else
        {
            //播放对应牌型的音效
            switch (args.cardType)
            {
            case CardType.None:
                break;

            case CardType.Single:
                Sound.Instance.PlayEffect(Consts.Single[args.weight]);
                break;

            case CardType.Double:
                Sound.Instance.PlayEffect(Consts.Double[args.weight / 2]);
                break;

            case CardType.Straight:
                Sound.Instance.PlayEffect(Consts.Straight);
                break;

            case CardType.DoubleStraight:
                Sound.Instance.PlayEffect(Consts.DoubleStraight);
                break;

            case CardType.TripleStraight:
                Sound.Instance.PlayEffect(Consts.TripleStraight);
                break;

            case CardType.Three:
                Sound.Instance.PlayEffect(Consts.Three);
                break;

            case CardType.ThreeAndOne:
                Sound.Instance.PlayEffect(Consts.ThreeAndOne);
                break;

            case CardType.ThreeAndTwo:
                Sound.Instance.PlayEffect(Consts.ThreeAndTwo);
                break;

            case CardType.Boom:
                Sound.Instance.PlayEffect(Consts.Boom);
                break;

            case CardType.JokerBoom:
                Sound.Instance.PlayEffect(Consts.JokerBoom);
                break;

            default:
                break;
            }
        }

        //玩家出牌成功更新当前的数据
        round.BiggestCharacter = args.characterType;
        round.CurrentCharacter = args.characterType;
        round.CurrentWeight    = args.weight;
        round.CurrentCardType  = args.cardType;
        round.CurrentLength    = args.length;

        //炸弹或王炸,积分翻倍
        if (args.cardType == CardType.Boom)
        {
            model.m_Mulitiple *= 2;
        }
        else if (args.cardType == CardType.JokerBoom)
        {
            model.m_Mulitiple *= 4;
        }

        //切换到下家出牌

        round.Turn();
    }