示例#1
0
    /// <summary>해당 id를 가진 플레이어에게 카드 추가 </summary>
    /// <param name="deckTag">카드를 가져올 덱</param>
    /// <param name="playerName">플레이어 이름</param>
    /// <param name="cardNum">카드 갯수</param>
    public void PlayerAddCardWithDeck(DeckTag deckTag, string playerId, int cardNum)
    {
        Observable.Interval(TimeSpan.FromSeconds(0.05f))
        .Take(cardNum)
        .Subscribe(_ =>
        {
            var player = Players.Find(p => p.PlayerId == playerId);

            if (player == null)
            {
                Debug.Log("Player not found : " + playerId);
                return;
            }

            var card = DeckSystem.GetInstance().GetTopCardWithDeck(deckTag);

            if (card == null)
            {
                return;
            }

            if (player.PlayerId == MyPlayerId)
            {
                CardAnimationSystem.GetInstance().ReverseAnimation(card, 0.5f);
            }

            player.AddPlayerCard(card);
        });
    }
示例#2
0
    public void PutCard(DeckTag putDeck, int playerCardIndex, bool isBack = false, float reverseTime = 0.5f)
    {
        var deck        = DeckSystem.GetInstance().GetDeck(putDeck);
        var putCardIdx  = PlayerCard[playerCardIndex].GetCardIndex();
        var putShapeIdx = PlayerCard[playerCardIndex].GetShapeIndex();

        PlayerCard[playerCardIndex].transform.DOMove(deck.GetPosition(), 0.5f);
        PlayerCard[playerCardIndex].transform.DORotate(deck.GetAngle(), 0.5f);

        if (isBack)
        {
            CardAnimationSystem.GetInstance().ReverseAnimation(
                PlayerCard[playerCardIndex], reverseTime);
        }

        deck.AddCard(PlayerCard[playerCardIndex]);

        //////////////////////////////////////
        /// TODO : 커플링으로 인해 분리해야함
        RuleSystem.GetInstance().AddAttackCardDamage(putCardIdx, putShapeIdx);
        AlertSystem.GetInstance().AddAlerts(putCardIdx, putShapeIdx);
        //////////////////////////////////////

        IsPutCard = true;

        PlayerCard.RemoveAt(playerCardIndex);

        RePosition();

        NetworkSystem.GetInstance().SendServer(string.Format("PUT-CARD:{0}:{1}", PlayerId, playerCardIndex));
    }
示例#3
0
    public IEnumerator ShareCard(DeckTag deck, int cardNum, float shareDelay)
    {
        WaitForSeconds delay = new WaitForSeconds(shareDelay);

        int tempTurn = TurnSystem.GetInstance().GetNowTurnPlayerIndex();

        if (tempTurn < 0)
        {
            tempTurn = 0;
        }

        for (int i = 0; i < Players.Count; i++)
        {
            for (int j = 0; j < cardNum; j++)
            {
                Card card = DeckSystem.GetInstance().GetTopCardWithDeck(deck);

                if (tempTurn + i >= Players.Count)
                {
                    tempTurn -= Players.Count;
                }

                Players[tempTurn + i].AddPlayerCard(card);

                yield return(delay);
            }
        }
    }
示例#4
0
    public void SelectCard_Ended(int playerIdx)
    {
        if (IsHoldCard == true)
        {
            IsHoldCard = false;

            var isPut     = PlayerSystem.GetInstance().Players[playerIdx].IsPutCard;
            var isCompare = RuleSystem.GetInstance().CompareCard(
                DeckSystem.GetInstance().GetTopCardPeekWithDeck(DeckTag.PUT_DECK),
                _myCardList[HoldCardNum],
                isPut);

            if (_myCardList[HoldCardNum].GetPosition().y < -SceneSystem.GetInstance().ScreenSize.y * 0.4f ||
                !isCompare)
            {
                PlayerSystem.GetInstance().Players[playerIdx].RePosition();
                PlayerSystem.GetInstance().Players[playerIdx].ReScale();
            }
            else
            {
                _myCardList[HoldCardNum].SetSortingOrder(HoldCardNum + 1);

                PlayerSystem.GetInstance().PlayerPutCard(DeckTag.PUT_DECK,
                                                         PlayerSystem.GetInstance().MyPlayerId,
                                                         HoldCardNum);

                RuleSystem.GetInstance().CheckSpecialCard(
                    _myCardList[HoldCardNum].GetCardIndex(),
                    isPut);
            }
        }
    }
示例#5
0
    public int RandomCard(string playerId, ref int cardIndex)
    {
        var player = PlayerSystem.GetInstance().GetPlayer(playerId);

        var cardIndexs = new List <int>();

        var card = DeckSystem.GetInstance().GetTopCardPeekWithDeck(DeckTag.PUT_DECK);

        for (int i = 0; i < player.PlayerCard.Count; i++)
        {
            if (RuleSystem.GetInstance().CompareCard(
                    card,
                    player.PlayerCard[i],
                    player.IsPutCard))
            {
                cardIndexs.Add(i);
            }
        }

        if (cardIndexs.Count <= 0)
        {
            Debug.Log("no card");
            return(-1);
        }

        var rand = new Random();

        var randIndex = rand.Next(0, cardIndexs.Count - 1);

        cardIndex = cardIndexs[randIndex];

        return(1);
    }
示例#6
0
    public IEnumerator StartScene()
    {
        yield return(new WaitForSeconds(1));

        DeckSystem.GetInstance().AllMoveCardDecktoDeck(DeckTag.ANIMATION_RIGHT_DECK, DeckTag.DRAW_DECK, 0, 0.05f, 0.5f);
        yield return(new WaitForSeconds(5));

        StartCoroutine(SetTurnDirection());
    }
示例#7
0
        private void CreatePlayerDeck(int startingDeckSize)
        {
            Debug.Log("Create Player Deck");
            // first establish the group of cards to create the deck with
            List <SampleCard> startingDeckCards = new List <SampleCard>();

            // create the starting cards and add to the group
            for (int i = 0; i < startingDeckSize; i++)
            {
                SampleCard newCard = CreateCard("Card" + i, i);
                startingDeckCards.Add(newCard);
            }
            // now establish our deck with our starting card group
            _playerDeckSystem = new DeckSystem <SampleCard>(startingDeckCards);
            Debug.Log("Deck Draw Pile: " + _playerDeckSystem.DrawPile.Count);
        }
示例#8
0
    public IEnumerator Test()
    {
        yield return(new WaitForSeconds(2));

        PlayerSystem.GetInstance().AddPlayer(PlayerTag.PLAYER_BOTTOM, "test", false);

        TurnSystem.GetInstance().SetFirstTurn("test");


        yield return(new WaitForSeconds(2));

        DeckSystem.GetInstance().AllMoveCardDecktoDeck(
            DeckTag.ANIMATION_RIGHT_DECK,
            DeckTag.DRAW_DECK,
            3,
            0.05F,
            3);
    }
示例#9
0
    public IEnumerator StartGame()
    {
        StartCoroutine(PlayerSystem.GetInstance().ShareCard(DeckTag.DRAW_DECK, 12, 0.1f));

        yield return(new WaitForSeconds(PlayerSystem.GetInstance().Players.Count * 1));

        DeckSystem.GetInstance().MoveCardDecktoDeck(DeckTag.DRAW_DECK, DeckTag.PUT_DECK, 1, 1, 0, 0.5f);

        yield return(new WaitForSeconds(1));

        PlayerSystem.GetInstance().PlayerCardReverse(PlayerSystem.GetInstance().GetMyPlayerIndex(), 0.5f);

        yield return(new WaitForSeconds(1));

        IsStartGame = true;

        TurnSystem.GetInstance().SetFirstTurn("1");
        TurnSystem.GetInstance().StartTurn();
    }
示例#10
0
    public IEnumerator SetTurnDirection()
    {
        DeckSystem.GetInstance().ShuffleDeck(DeckTag.DRAW_DECK, 1000);

        //StartCoroutine(PlayerSystem.GetInstance().ShareCard(1, 0));
        //
        //yield return new WaitForSeconds(3);
        //
        //TurnSystem.GetInstance().DecideFirstTurn();
        //
        //PlayerSystem.GetInstance().AllPlayerCardReverse(0.5f);
        //
        //yield return new WaitForSeconds(2);
        //
        //PlayerSystem.GetInstance().AllPlayerCardMoveDeck(DeckTag.DRAW_DECK, true, 0.5f);
        //
        //yield return new WaitForSeconds(2);

        yield return(StartCoroutine(GameManager.GetInstance().StartGame()));
    }
示例#11
0
    /// <summary>deck1의 카드가 부족할 때 deck2의 카드로 채우고 섞음 </summary>
    /// <param name="deck1"></param>
    /// <param name="deck2"></param>
    public void FillDecktoDeckofAttack(DeckTag deck1, DeckTag deck2)
    {
        var nowTurn = TurnSystem.GetInstance().GetNowTurnPlayerIndex();
        var isPut   = PlayerSystem.GetInstance().Players[nowTurn].IsPutCard;
        var damage  = RuleSystem.GetInstance().GetAttackDamage(isPut);

        var deck2Count = DeckSystem.GetInstance().GetCardCountWithDeck(deck2);

        Action addCardAction = () =>
        {
            DeckSystem.GetInstance().ShuffleDeck(DeckTag.DRAW_DECK, 1000);
            NextTurn(nowTurn, damage);
        };


        if (damage > deck2Count)
        {
            var count = DeckSystem.GetInstance().GetCardCountWithDeck(deck1);

            if (count + deck2Count <= damage)
            {
                return;
            }

            Debug.Log("move put -> draw : " + count);

            DeckSystem.GetInstance().MoveCardDecktoDeck(
                deck1,
                deck2,
                0,
                0,
                count - 1,
                0,
                0.2f,
                addCardAction);
        }
        else
        {
            NextTurn(nowTurn, damage);
        }
    }
示例#12
0
    /// <summary>플레이어 카드가 룰의 Max 카드를 넘었을 때 </summary>
    /// <returns>플레이어가 패배했다면 true, 아니라면 false</returns>
    public bool CheckDefeatPlayer()
    {
        var nowTurn         = TurnSystem.GetInstance().GetNowTurnPlayerIndex();
        var isPut           = PlayerSystem.GetInstance().Players[nowTurn].IsPutCard;
        var damage          = RuleSystem.GetInstance().GetAttackDamage(isPut);
        var playerCardCount = PlayerSystem.GetInstance().GetPlayerCardCount(nowTurn);
        var playerId        = PlayerSystem.GetInstance().GetPlayerId(nowTurn);
        var isReverse       = PlayerSystem.GetInstance().MyPlayerId == playerId ? true : false;

        if (damage + playerCardCount > RuleSystem.GetInstance().PlayerMaxCard)
        {
            PlayerSystem.GetInstance().PlayerCardMoveDeck(DeckTag.DRAW_DECK, nowTurn, isReverse, 0.1f);
            DeckSystem.GetInstance().ShuffleDeck(DeckTag.DRAW_DECK, 1000);

            TurnSystem.GetInstance().NextTurn();
            PlayerSystem.GetInstance().RemovePlayer(playerId);
            TurnSystem.GetInstance().RemoveTurnPlayer(playerId);

            EndAttackTurn();
            return(true);
        }

        return(false);
    }
示例#13
0
    public void FillDecktoDeckofDraw(DeckTag deck1, DeckTag deck2, int damage)
    {
        Action addCardAction = () =>
        {
            DeckSystem.GetInstance().ShuffleDeck(DeckTag.DRAW_DECK, 1000);
        };

        var count = DeckSystem.GetInstance().GetCardCountWithDeck(deck1);

        if (damage > count)
        {
            Debug.Log("move put -> draw : " + count);

            DeckSystem.GetInstance().MoveCardDecktoDeck(
                deck1,
                deck2,
                0,
                0,
                count - 1,
                0,
                0.2f,
                addCardAction);
        }
    }
示例#14
0
    void Start()
    {
        GameManager.GetInstance().FadeOutWhiteImg(0.5f);

        CardSystem.GetInstance().AddAllCard();
        CardSystem.GetInstance().SetCardActive(true);

        CardSystem.GetInstance().AllCardMoveDeck(DeckSystem.GetInstance().GetDeck(DeckTag.ANIMATION_RIGHT_DECK));

        AiSystem.GetInstance().SetupOneCardAi();

        if (PlayerSystem.GetInstance().Players.Count <= 0)
        {
            PlayerSystem.GetInstance().MyPlayerId = "1";
            PlayerSystem.GetInstance().AddPlayer(PlayerTag.PLAYER_BOTTOM, "1", false);
            PlayerSystem.GetInstance().AddPlayer(PlayerTag.PLAYER_LEFT_DOWN, "3", true);
            PlayerSystem.GetInstance().AddPlayer(PlayerTag.PLAYER_TOP, "2", true);
            PlayerSystem.GetInstance().AddPlayer(PlayerTag.PLAYER_RIGHT_UP, "4", true);

            TurnSystem.GetInstance().AddTurnPlayer("1");
            TurnSystem.GetInstance().AddTurnPlayer("2");
            TurnSystem.GetInstance().AddTurnPlayer("3");
            TurnSystem.GetInstance().AddTurnPlayer("4");


            //NetworkSystem.GetInstance().SendServer("FIND-ROOM:" + "1");
        }

        StartCoroutine(StartScene());

        this.UpdateAsObservable()
        .Subscribe(_ =>
        {
            if (!GameManager.GetInstance().IsStartGame)
            {
                return;
            }

            var nowId = TurnSystem.GetInstance().PlayerNowTurn.Value;

            if (nowId == PlayerSystem.GetInstance().MyPlayerId)
            {
                InputSystem.GetInstance().TouchUpdate();
            }
        });

        TurnSystem.GetInstance().PlayerNowTurn.Subscribe(name =>
        {
            if (name == "")
            {
                return;
            }

            if (PlayerSystem.GetInstance().GetPlayer(name).IsAi)
            {
                AiSystem.GetInstance().IsStartAi.Value = true;
            }

            if (name == PlayerSystem.GetInstance().MyPlayerId)
            {
                OnTurnEndBtn();
            }
        });

        TurnSystem.GetInstance().IsFinishTurn.Subscribe(finish =>
        {
            if (!GameManager.GetInstance().IsStartGame)
            {
                return;
            }

            if (finish)
            {
                Observable.Timer(TimeSpan.FromSeconds(1))
                .Subscribe(_ =>
                {
                    if (GameManager.GetInstance().CheckDefeatPlayer())
                    {
                        return;
                    }

                    if (GameManager.GetInstance().CheckWinPlayer())
                    {
                        return;
                    }

                    GameManager.GetInstance().FillDecktoDeckofAttack(DeckTag.PUT_DECK, DeckTag.DRAW_DECK);
                });
            }
        });
    }