private void TallyScores(IRound round) { var winner = round.GetWinner(); var team = RuleHelpers.GetTeam(winner); _teamScores[team] += round.GetWinnersPoints(); }
void RpcGotScores(int team1Score, int team2Score) { if (!isLocalPlayer) { return; } FindObjectOfType <ScoreDisplay>().UpdateScores(team1Score, team2Score, RuleHelpers.GetTeam(this)); }
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(); }
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(); }