Ejemplo n.º 1
0
 public void OrganizeHandCards(List <ICard> cards, Position pos)
 {
     try
     {
         var          suits       = cards.GroupBy(a => a.Suit).OrderByDescending(a => a.First().Suit);
         List <ICard> sortedCards = new List <ICard>();
         foreach (var suit in suits)
         {
             sortedCards.AddRange(suit.OrderByDescending(a => a.Rank));
         }
         var i            = 0;
         var handPosition = RuleHelpers.GetHandPosition(pos);
         foreach (var card in sortedCards)
         {
             var mover = card.Movable;
             mover.Orient(-handPosition);
             var fraction  = i * 1f / Math.Max(cards.Count - 1, 1);
             var tiltAngle = Mathf.Lerp(-_handTilt, _handTilt, fraction);
             mover.Tilt(tiltAngle);
             mover.MoveTo(handPosition * _handDistance
                          + RelativeRight(-handPosition) * Mathf.Lerp(-_handWidth * .5f, _handWidth * .5f, fraction)
                          + new Vector3(0, 0, .1f * fraction)
                          + handPosition * Math.Abs(tiltAngle) * .002f, 0, .5f);
             mover.Flip(_areMine ? FlipState.FaceUp : FlipState.FaceDown);
             i++;
         }
     }
     catch (Exception e)
     {
         DebugConsole.Log(e.ToString(), "red");
     }
 }
Ejemplo n.º 2
0
        private void RpcPutCardOnTable(int id)
        {
            var card = HandCards.Single(a => a.ID == id);

            _playedCards.Add(card);
            _organizer.OrganizeHandCards(HandCards.Except(_playedCards).ToList(), Position);
            card.Movable.MoveTo(RuleHelpers.GetHandPosition(Position) * .1f, 0, .3f);
            card.Movable.Flip(FlipState.FaceUp);
        }
Ejemplo n.º 3
0
        private void RpcTakeWonCards(int[] ids)
        {
            var cards = FindObjectsOfType <MBCard>().Where(a => ids.Contains(a.ID));

            foreach (var mbCard in cards)
            {
                mbCard.Movable.MoveTo(RuleHelpers.GetHandPosition(Position) * 1, 1, 2, () => mbCard.Movable.Flip(FlipState.FaceDown));
            }
        }
Ejemplo n.º 4
0
        private void Start()
        {
            Id   = (int)netId.Value;
            Name = "Player " + Id;
            if (OnPlayerJoined != null)
            {
                OnPlayerJoined(this);
            }

            _organizer = new CardOrganizer(isLocalPlayer, 10, .5f, .45f, 0);

            BidGui.OnBidSubmitted += bid =>
            {
                if (!_isMyTurnToBid || !isLocalPlayer)
                {
                    return;
                }
                CmdBid(bid);
                _isMyTurnToBid = false;
                FindObjectOfType <BidGui>().Hide();
            };

            SeatManager.OnClickedSit += pos =>
            {
                if (isLocalPlayer)
                {
                    IsSeated  = true;
                    _position = (int)pos;
                    CmdSit(pos);
                    Camera.main.transform.rotation = Quaternion.LookRotation(Vector3.forward, -RuleHelpers.GetHandPosition(pos));
                }
            };
            FourPlayerGameManager.OnScoreUpdate += (i, score) =>
            {
                RpcGotScores(i, score);
            };
            Interactable.OnCardEvent += (type, card) =>
            {
                if (!_isMyPlayTurn || !isLocalPlayer || _playedCards.Contains(card))
                {
                    return;
                }
                switch (type)
                {
                case Interactable.CardEventType.MouseOver:
                    if (RuleHelpers.IsValidPlay(card, HandCards.Except(_playedCards).ToList(), _currentRoundInfo))
                    {
                        card.Movable.Grow();
                    }
                    break;

                case Interactable.CardEventType.MouseExit:
                    card.Movable.Shrink();
                    break;

                case Interactable.CardEventType.MouseDown:
                    if (RuleHelpers.IsValidPlay(card, HandCards.Except(_playedCards).ToList(), _currentRoundInfo))
                    {
                        _isMyPlayTurn = false;
                        CmdPickedCard(card.ID);
                    }
                    else
                    {
                        DebugConsole.Log(card + " is not a valid play");
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            };
        }