Beispiel #1
0
 void IPlayCard.OnPlayCard(PlayerId id, CardHand cardHand)
 {
     if (IsMyEvent(id))
     {
         Registry.RemoveUiCard(cardHand);
     }
 }
Beispiel #2
0
 private void Start()
 {
     playerHand = player.GetComponent <CardHand>();
     dealerHand = dealer.GetComponent <CardHand>();
     ShuffleCards();
     StartGame();
 }
        public void DrawCard(PlayerId playerId)
        {
            if (!Game.IsGameStarted)
            {
                return;
            }
            var hand     = GetPlayerHand(playerId);
            var handSize = hand.Cards.Count;

            if (handSize >= hand.MaxHandSize)
            {
                return;
            }

            var data                  = Game.Library.GetRandomData();
            var card                  = new CardHand(data);
            var actionPoints          = Parameters.Amounts.ActionPointsConsume;
            var inventory             = GetInventory(playerId);
            var hasEnoughActionPoints = inventory.GetAmount(Inventory.ActionPointItem) >= actionPoints;

            if (!hasEnoughActionPoints)
            {
                return;
            }

            inventory.RemoveItem(Inventory.ActionPointItem, actionPoints);
            hand.Add(card);
            OnDrawCard(playerId, card);
        }
    public bool CanDiscard(ECard card)
    {
        if (CardStolen.Find(c => c.Id == card.CardId) != null)
        {
            return(false);
        }

        List <CardLib.Model.Card> cardHand = CardHand;

        cardHand.Remove(CardHand.Find(c => c.Id == card.CardId));
        try
        {
            PhomLib.Models.MeldsAndRemainingCards summary = PhomLib.Utility.PhomLogicCenter.caculateExistingMelds(cardHand, CardStolen);
            foreach (CardLib.Model.Card c in CardStolen)
            {
                if (summary == null)
                {
                    return(false);
                }
                else if (summary.RemainingCards.Find(c1 => c1 != null && c1.Id == c.Id) != null)
                {
                    return(false);
                }
            }
            return(true);
        }
        catch { return(false); }
    }
Beispiel #5
0
        public void CreateCardFromPool(CardHand cardHand, PositionId positionId)
        {
            var poolPosition      = uiPool.GetPosition(positionId);
            var poolWorldPosition = poolPosition.transform.position;

            CreateUiCard(cardHand, poolWorldPosition);
        }
Beispiel #6
0
        private IEnumerable <CardHand> GetCardHandsToPass(Round round, IEnumerable <CardHand> cardHands)
        {
            var cardHandsToPass = new List <CardHand>();

            foreach (var cardHand in cardHands)
            {
                var playerFrom = cardHand.Owner;

                var gameState = this.CreateGameState(playerFrom, round);
                var agent     = this.agentLookup.GetAgent(playerFrom);

                var timer = this.timerService.StartNewPassTimer(playerFrom);

                var cardsToPass = new CardHand(
                    playerFrom,
                    agent.ChooseCardsToPass(gameState));

                timer.Stop();

                if (!IsPassLegal(cardHand, cardsToPass))
                {
                    // TODO: Handle illegal move
                    Log.IllegalPass(playerFrom, cardsToPass);
                    playerFrom.AgentHasMadeIllegalMove = true;
                }

                Log.Pass(playerFrom, cardsToPass);

                cardHandsToPass.Add(cardsToPass);
            }

            return(cardHandsToPass);
        }
Beispiel #7
0
    public void Hit()
    {
        CardHand jugador = player.GetComponent <CardHand>();
        CardHand banca   = dealer.GetComponent <CardHand>();

        /*TODO:
         * Si estamos en la mano inicial, debemos voltear la primera carta del dealer.
         */
        if (cardIndex.Equals(4))
        {
            banca.cards[0].GetComponent <SpriteRenderer>().sprite = banca.cards[0].GetComponent <CardModel>().front;
        }

        //Repartimos carta al jugador

        PushPlayer();

        /*TODO:
         * Comprobamos si el jugador ya ha perdido y mostramos mensaje
         */
        if (jugador.points > 21)
        {
            hitButton.interactable   = false;
            stickButton.interactable = false;
            finalMessage.text        = "El jugador a perdido";
            apuesta = 0;
            cantidadApostada.text = "Apusta: " + apuesta.ToString();
        }
    }
        public static CardHand Map(string[] strings)
        {
            if (strings.Length != Constants.NumberOfCardsInHand)
            {
                return(null);
            }

            var cardHand = new CardHand()
            {
                Cards = new List <Card>()
            };

            foreach (var cardString in strings)
            {
                var newCard = MapCardStringToCard(cardString);
                if (newCard != null && !CardHandContainsCard(cardHand, newCard))
                {
                    cardHand.Cards.Add(newCard);
                }
                else
                {
                    // No point continuing if not all cards can be read
                    break;
                }
            }

            return(cardHand.Cards.Count != Constants.NumberOfCardsInHand ? null : cardHand);
        }
    public void SetupCardHand()
    {
        GameObject cardHandGo = new GameObject();

        cardHandGo.AddComponent <CardHand>();
        _cardHand = cardHandGo.GetComponent <CardHand>();
    }
Beispiel #10
0
    void StartGame()
    {
        for (int i = 0; i < 2; i++)
        {
            PushPlayer();
            PushDealer();

            /*TODO:
             * Si alguno de los dos obtiene Blackjack, termina el juego y mostramos mensaje
             */
            CardHand jugador = player.GetComponent <CardHand>();
            CardHand banca   = dealer.GetComponent <CardHand>();
            if (jugador.points.Equals(21))
            {
                hitButton.interactable   = false;
                stickButton.interactable = false;
                finalMessage.text        = "Gana el jugador";
                Cobrar();
            }

            if (banca.points.Equals(21))
            {
                hitButton.interactable   = false;
                stickButton.interactable = false;
                finalMessage.text        = "Gana la banca";
                apuesta = 0;
                cantidadApostada.text = "Apusta: " + apuesta.ToString();
            }
        }
    }
Beispiel #11
0
    private void Awake()
    {
        instance = this;
        if (card.Count <= 0)
        {
            return;
        }
        handCardView   = new CardView[card.Count];
        handCostOffset = new int[card.Count];
        for (int i = 0; i < card.Count; i++)
        {
            cardStartPos.Add(Vector4.zero);
            cardStartSize.Add(Vector2.zero);
            cardStartAngle.Add(0);
            canUse.Add(false);
            handCardView[i] = card[i].transform.Find("Card").GetComponent <CardView>();
            handLerp.Add(1);
        }

        if (card_glow.Count <= 0)
        {
            return;
        }
        glowImg = new Image[card_glow.Count];
        for (int i = 0; i < card_glow.Count; i++)
        {
            glowImg[i] = card_glow[i].GetComponent <Image>();
        }
    }
Beispiel #12
0
        void ICreateBoardElement.OnCreateBoardElement(SeatType id, CreatureElement creatureElement, Vector3Int cell,
                                                      CardHand card)
        {
            var data = creatureElement.Data;

            CreateElement(creatureElement, data, cell);
        }
Beispiel #13
0
    void StartGame()
    {
        /*TODO:
         * Si alguno de los dos obtiene Blackjack, termina el juego y mostramos mensaje
         */

        for (int i = 0; i < 2; i++)
        {
            PushPlayer();
            PushDealer();

            // Compruebo al player
            if (player.GetComponent <CardHand>().points == 21)
            {
                finalMessage.text = "BlackJack";
                desactivarBotones();
            }

            //El dealer es comprobado cuando gire su carta
            if (dealer.GetComponent <CardHand>().points == 21)
            {
                CardHand cardD = dealer.GetComponent <CardHand>();
                cardD.cards[0].GetComponent <CardModel>().ToggleFace(true);
                showFirstCard     = true;
                finalMessage.text = "BlackJack";
                desactivarBotones();
            }
        }
    }
Beispiel #14
0
    public void Stand()
    {
        CardHand jugador = player.GetComponent <CardHand>();
        CardHand banca   = dealer.GetComponent <CardHand>();

        if (cardIndex.Equals(4))
        {
            banca.cards[0].GetComponent <SpriteRenderer>().sprite = banca.cards[0].GetComponent <CardModel>().front;
        }

        while (banca.points <= 16)
        {
            PushDealer();
        }
        if (jugador.points > banca.points || banca.points > 21)
        {
            hitButton.interactable   = false;
            stickButton.interactable = false;
            finalMessage.text        = "HAS GANADO!!";
        }
        else
        {
            hitButton.interactable   = false;
            stickButton.interactable = false;
            finalMessage.text        = "HAS PERDIDO";
        }
    }
        public void CreateCreatureAt_Test()
        {
            var player = Game.TurnLogic.CurrentPlayer;

            _cardHand = new CardHand(_mockCardData);
            Game.PlayElementAt(player.Id, _cardHand, _v3IntPosition);
            Assert.IsTrue(EventReceived);
        }
 public void OnCreateBoardElement(PlayerId id, CreatureElement creatureElement, Vector3Int position,
                                  CardHand card)
 {
     EventReceived = true;
     Assert.IsTrue(creatureElement.Data == _mockCardData);
     Assert.IsTrue(position == _v3IntPosition);
     Assert.IsTrue(_cardHand == card);
 }
 void IReturnCard.OnReturnCard(SeatType id, CardHand cardHand, CardPool cardPool, PositionId positionId)
 {
     if (!IsMyEvent(id))
     {
         return;
     }
     Registry.RemoveCard(cardHand);
 }
 void IPickCard.OnPickCard(SeatType id, CardHand cardHand, PositionId positionId)
 {
     if (!IsMyEvent(id))
     {
         return;
     }
     Registry.CreateCardFromPool(cardHand, positionId);
 }
 private void Awake()
 {
     playerController = FindObjectOfType <PlayerController>();
     aiControl        = FindObjectOfType <AIControl>();
     cardHand         = FindObjectOfType <CardHand>();
     cardCreator      = FindObjectOfType <CardSelector>();
     powerCounter     = FindObjectOfType <PowerCounter>();
     winScreen        = FindObjectOfType <WinScreen>();
 }
Beispiel #20
0
        void IDrawCard.OnDrawCard(PlayerId id, CardHand cardHand)
        {
            if (!IsMyEvent(id))
            {
                return;
            }

            Registry.CreateCardFromLibrary(cardHand);
        }
Beispiel #21
0
        public void CardList_IsCount5_Return5()
        {
            int      maxCardsInHand = 5;
            CardHand cardHand       = new CardHand();

            var result = cardHand.CardList.Count;

            Assert.AreEqual(result, maxCardsInHand);
        }
        void ICreateBoardElement.OnCreateBoardElement(SeatType id, CreatureElement creatureElement, Vector3Int position,
                                                      CardHand card)
        {
            if (!IsMyEvent(id))
            {
                return;
            }

            Registry.RemoveCard(card);
        }
Beispiel #23
0
        protected CardGameModelData(int playerNum, int activePlayer)
            : base(playerNum, activePlayer)
        {
            Hands = new CardHand <TCard> [playerNum];

            for (int i = 0; i < playerNum; i++)
            {
                Hands[i] = new CardHand <TCard>();
            }
        }
Beispiel #24
0
 public CardHand AddPlayer(ulong userid)
 {
     if (!_hands.ContainsKey(userid))
     {
         CardHand hand = new CardHand();
         _hands.Add(userid, hand);
         return(hand);
     }
     return(null);
 }
Beispiel #25
0
        private void FillHand(CardHand hand)
        {
            for (int i = 0; i < _random.Next(4, 6); i++)
            {
                Card card = _gameFactory.CreateCard(
                    GetRandomCardTypeId(),
                    hand.transform);

                hand.Add(card);
            }
        }
Beispiel #26
0
 private static Dictionary <CardRank, int> GroupCardsByRank(CardHand cardHand)
 {
     return(cardHand.Cards
            .GroupBy(card => card.Rank)
            .Select(cardGroup => new
     {
         Key = cardGroup.Key,
         Val = cardGroup.Count()
     })
            .ToDictionary(kvp => kvp.Key, kvp => kvp.Val));
 }
Beispiel #27
0
        void CreateUiCard(CardHand card, Vector3 position)
        {
            var uiCard        = Pooler.Get <IUiCard>(cardPrefab);
            var cardTransform = uiCard.transform;

            cardTransform.SetParent(CardHandSelector.transform);
            cardTransform.position = position;
            uiCard.SetAndUpdateView(card.Data, id, this);
            uiCard.Initialize();
            CardHandSelector.AddCard(uiCard);
            _registry.Add(uiCard, card);
        }
Beispiel #28
0
        public void PlayCardAt(PlayerId playerId, CardHand card, Vector3Int position)
        {
            if (!Game.IsGameStarted)
            {
                return;
            }
            if (!Game.IsTurnInProgress)
            {
                return;
            }
            if (!Game.TurnLogic.IsMyTurn(playerId))
            {
                return;
            }

            var hand = GetPlayerHand(playerId);

            if (!hand.Has(card))
            {
                return;
            }
            var cost          = card.Cost;
            var inventory     = GetInventory(playerId);
            var hasEnoughGold = inventory.GetAmount(Inventory.GoldItem) >= cost;

            if (!hasEnoughGold)
            {
                return;
            }
            var actionPoints          = Parameters.Amounts.ActionPointsConsume;
            var hasEnoughActionPoints = inventory.GetAmount(Inventory.ActionPointItem) >= actionPoints;

            if (!hasEnoughActionPoints)
            {
                return;
            }

            var isPositionBusy = Game.Board.GetPosition(position).HasData;

            if (isPositionBusy)
            {
                return;
            }

            inventory.RemoveItem(Inventory.ActionPointItem, actionPoints);
            inventory.RemoveItem(Inventory.GoldItem, cost);
            hand.Remove(card);
            var creature = new CreatureElement(card.Data, playerId);

            Game.Board.AddDataAt(creature, position);
            OnCreateCreature(playerId, creature, position, card);
        }
Beispiel #29
0
 // Use this for initialization
 void Start()
 {
     cameraRaycaster = FindObjectOfType <CameraRaycaster>();
     cameraRaycaster.layerChangeObservers += CardShowUse;
     cardHand     = FindObjectOfType <CardHand>();
     powerCounter = FindObjectOfType <PowerCounter>();
     //Spawner[] spawners = FindObjectsOfType<Spawner>();
     //foreach (Spawner spawner in spawners)
     //{
     //    if (spawner.cardType == CardType.Player) { playerSpawner = spawner; }
     //}
     mageSpawner = FindObjectOfType <Mage>();
 }
Beispiel #30
0
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else if (Instance != this)
     {
         Destroy(gameObject);
         return;
     }
     lineRenderer.SetPosition(0, transform.position + Vector3.up);
 }
 public void Setup()
 {
     testHand = new CardHand();
 }