示例#1
0
        public void ResolveStyle(bool recursive = false)
        {
            markedStyleResolve          = false;
            markedStyleResolveRecursive = false;

            var inheritedChanges = ComputedStyle.HasInheritedChanges;


            var inlineStyles  = RuleHelpers.GetRuleDic(Style);
            var inlineLayouts = RuleHelpers.GetLayoutDic(Style);

            if (inlineLayouts != null)
            {
                foreach (var l in inlineLayouts)
                {
                    inlineStyles[l.prop.name] = l.value;
                }
            }

            List <RuleTreeNode <StyleData> > matchingRules;

            if (Tag == "_before")
            {
                matchingRules = Parent.BeforeRules;
            }
            else if (Tag == "_after")
            {
                matchingRules = Parent.AfterRules;
            }
            else
            {
                matchingRules = Context.StyleTree.GetMatchingRules(this).ToList();
            }

            var importantIndex = Math.Max(0, matchingRules.FindIndex(x => x.Specifity <= RuleHelpers.ImportantSpecifity));
            var cssStyles      = new List <Dictionary <string, object> > {
            };

            for (int i = 0; i < importantIndex; i++)
            {
                cssStyles.AddRange(matchingRules[i].Data?.Rules);
            }
            cssStyles.Add(inlineStyles);
            for (int i = importantIndex; i < matchingRules.Count; i++)
            {
                cssStyles.AddRange(matchingRules[i].Data?.Rules);
            }

            ComputedStyle.CssStyles = cssStyles;
            ApplyStyles();
            ApplyLayoutStyles();
            ComputedStyle.MarkChangesSeen();


            if (inheritedChanges || recursive)
            {
                BeforeRules = Context.StyleTree.GetMatchingBefore(this).ToList();
                //if (BeforeRules.Count > 0) AddBefore();
                //else RemoveBefore();
                BeforePseudo?.ResolveStyle();

                foreach (var child in Children)
                {
                    child.ResolveStyle(true);
                }

                AfterRules = Context.StyleTree.GetMatchingAfter(this).ToList();
                //if (AfterRules.Count > 0) AddAfter();
                //else RemoveAfter();
                AfterPseudo?.ResolveStyle();
            }
        }
示例#2
0
        public void Tick()
        {
            if (IsHandFinished())
            {
                return;
            }

            if (!_biddingPrompted)
            {
                DebugConsole.Log("prompting bids from simplehand...");
                _biddingPrompted = true;
                _bidManager      = _bidManagerFactory.GetBidManager(_players, _startPlayerId, (ints =>
                {
                    if (ints.All(a => a.Value == 0))
                    {
                        DebugConsole.Log("Everyone passed, re-dealing and bidding.");
                        _biddingPrompted = false;
                        DealCards();
                    }
                    else
                    {
                        _bids = ints;
                        _startPlayerId = _bids.Single(b => b.Value == _bids.Values.Max()).Key;
                        DebugConsole.Log(_players.Single(a => a.Id == _startPlayerId).Name + " held the bid");
                        _currentRound = _roundFactory.GetFirstRoundInHand(_players, _startPlayerId);
                    }
                }));
            }

            if (_bids == null)
            {
                _bidManager.Tick();
                return;
            }

            if (_currentRound.IsRoundFinished())
            {
                _numRoundsPlayed++;
                DebugConsole.Log("round " + _numRoundsPlayed + " finished");
                TallyScores(_currentRound);
                if (IsHandFinished())
                {
                    var t1prior = _previousTeamScores[1];
                    var t2prior = _previousTeamScores[2];

                    var t1ThisHand = _teamScores[1];
                    var t2ThisHand = _teamScores[2];
                    Debug.LogFormat("t1 prior: {0}, t2 prior: {1}", t1prior, t2prior);
                    Debug.LogFormat("t1 this Hand: {0}, t2 this Hand: {1}", t1ThisHand, t2ThisHand);

                    var heldBid        = _bids.Values.Max();
                    var bidHoldingTeam = RuleHelpers.GetTeam(_players.Single(a => a.Id == _bids.Single(b => b.Value == heldBid).Key));
                    Debug.LogFormat("team {0} held the bid at {1}", bidHoldingTeam, heldBid);
                    var holdersScoreThisHand = _teamScores[bidHoldingTeam];
                    if (holdersScoreThisHand < heldBid)
                    {
                        Debug.LogFormat("Penalizing team {0} (bid holders) for not making their bid of {1}.  They made {2}", bidHoldingTeam, heldBid, holdersScoreThisHand);
                        var beforePenalty = _previousTeamScores[bidHoldingTeam];
                        _teamScores[bidHoldingTeam] = _previousTeamScores[bidHoldingTeam] - heldBid;
                        var afterPenalty = _teamScores[bidHoldingTeam];
                        Debug.LogFormat("subtracted {0} points from team {1}", beforePenalty - afterPenalty, bidHoldingTeam);
                    }
                    else
                    {
                        Debug.LogFormat("Awarding points to team {0} (bid holders) for making their bid of {1}.  They made {2}", bidHoldingTeam, heldBid, holdersScoreThisHand);
                        _teamScores[bidHoldingTeam] += _previousTeamScores[bidHoldingTeam];
                    }

                    var nonBidHOldingTeam = bidHoldingTeam == 1 ? 2 : 1;
                    var anyoneFromNonBidHoldingTeamBid =
                        _bids.Any(
                            a =>
                            RuleHelpers.GetTeam(_players.Single(b => b.Id == a.Key)) != bidHoldingTeam &&
                            a.Value > 0);
                    if (anyoneFromNonBidHoldingTeamBid || _previousTeamScores[nonBidHOldingTeam] < 150)
                    {
                        _teamScores[nonBidHOldingTeam] += _previousTeamScores[nonBidHOldingTeam];
                    }
                    else
                    {
                        _teamScores[nonBidHOldingTeam] = _previousTeamScores[nonBidHOldingTeam];
                    }
                    return;
                }
                if (_numRoundsPlayed == 1)
                {
                    TrumpSuit = _currentRound.GetPlayedSuit();
                }
                _currentRound = _roundFactory.GetNewRound(_players, _currentRound.GetWinner().Id, TrumpSuit);
            }
            _currentRound.Tick();
        }
示例#3
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();
                }
            };
        }
示例#4
0
        void Update()
        {
            if (_isGameWon)
            {
                return;
            }

            if (!_playersSeated)
            {
                return;
            }

            if (_currentHand == null)
            {
                DebugConsole.Log("Starting new hand...");
                _currentHand = _handFactory.GetNewHand(_players, _players.GetFrom(_players.Single(a => a.Id == _firstPlayerToBid), _numHandsPlayed).Id, team1CumulativeScore, team2CumulativeScore);
            }

            if (_currentHand.IsHandFinished())
            {
                if (!loggedFinish)
                {
                    finishTime   = Time.time;
                    loggedFinish = true;
                }
            }
            if (loggedFinish && Time.time - finishTime > 5)
            {
                loggedFinish = false;
                _numHandsPlayed++;
                team1CumulativeScore = _currentHand.GetPointsForTeam(1);
                team2CumulativeScore = _currentHand.GetPointsForTeam(2);
                if (OnScoreUpdate != null)
                {
                    OnScoreUpdate(team1CumulativeScore, team2CumulativeScore);
                }
                if (team1CumulativeScore >= 200 || team2CumulativeScore >= 200)
                {
                    _isGameWon = true;
                    if (team1CumulativeScore >= 200 && team2CumulativeScore >= 200)
                    {
                        _winner = RuleHelpers.GetTeam(_currentHand.GetBidHolder());
                    }
                    else
                    {
                        _winner = team1CumulativeScore > team2CumulativeScore ? 1 : 2;
                    }
                    DebugConsole.Log(_winner + " won");
                }
                else
                {
                    _currentHand = null;
                }
                if (_isGameWon)
                {
                    _onFinished(_winner);
                }
                return;
            }
            _currentHand.Tick();
        }