示例#1
0
 public void Add(int bitsMatchId, string rosterId, DateTime date, int turn, MatchSerie matchSerie)
 {
     foreach (MatchTable matchTable in new[] { matchSerie.Table1, matchSerie.Table2, matchSerie.Table3, matchSerie.Table4 })
     {
         PlayerResult firstPlayerResult = new(
             bitsMatchId,
             rosterId,
             date,
             turn,
             matchSerie.SerieNumber,
             matchTable.TableNumber,
             matchTable.Game1.Player,
             matchTable.Score,
             matchTable.Game1.Pins);
         _ = PlayerResults.Add(firstPlayerResult);
         PlayerResult secondPlayerResult = new(
             bitsMatchId,
             rosterId,
             date,
             turn,
             matchSerie.SerieNumber,
             matchTable.TableNumber,
             matchTable.Game2.Player,
             matchTable.Score,
             matchTable.Game2.Pins);
         _ = PlayerResults.Add(secondPlayerResult);
     }
 }
示例#2
0
    private void VerifyPlayers(MatchSerie matchSerie)
    {
        do
        {
            if (rosterPlayers !.Contains(matchSerie.Table1.Game1.Player) == false)
            {
                break;
            }

            if (rosterPlayers.Contains(matchSerie.Table1.Game2.Player) == false)
            {
                break;
            }

            if (rosterPlayers.Contains(matchSerie.Table2.Game1.Player) == false)
            {
                break;
            }

            if (rosterPlayers.Contains(matchSerie.Table2.Game2.Player) == false)
            {
                break;
            }

            if (rosterPlayers.Contains(matchSerie.Table3.Game1.Player) == false)
            {
                break;
            }

            if (rosterPlayers.Contains(matchSerie.Table3.Game2.Player) == false)
            {
                break;
            }

            if (rosterPlayers.Contains(matchSerie.Table4.Game1.Player) == false)
            {
                break;
            }

            if (rosterPlayers.Contains(matchSerie.Table4.Game2.Player) == false)
            {
                break;
            }

            return;
        }while (false);

        throw new MatchException("Can only register players from roster");
    }
示例#3
0
    public SeriesScores(
        MatchSerie matchSerie,
        ResultSeriesReadModel.Serie opponentSerie,
        int cumulativeScore,
        int cumulativeOpponentScore)
    {
        int teamScore     = 0;
        int opponentScore = 0;

        if (matchSerie.TeamTotal > opponentSerie.TeamTotal)
        {
            teamScore = 1;
        }
        else if (matchSerie.TeamTotal < opponentSerie.TeamTotal)
        {
            opponentScore = 1;
        }

        TeamScoreDelta = matchSerie.Table1.Score
                         + matchSerie.Table2.Score
                         + matchSerie.Table3.Score
                         + matchSerie.Table4.Score
                         + teamScore;
        TeamScoreTotal     = TeamScoreDelta + cumulativeScore;
        OpponentScoreDelta = opponentSerie.Tables.Sum(x => x.Score) + opponentScore;
        OpponentScoreTotal = OpponentScoreDelta + cumulativeOpponentScore;
        SerieNumber        = matchSerie.SerieNumber;
        TeamPins           = matchSerie.TeamTotal;
        OpponentPins       = opponentSerie.TeamTotal;
        MatchResult        = TeamPins > OpponentPins
            ? MatchResultType.Win
            : (TeamPins < OpponentPins
                ? MatchResultType.Loss
                : MatchResultType.Draw);
        PlayerResults = new[]
        {
            matchSerie.Table1,
            matchSerie.Table2,
            matchSerie.Table3,
            matchSerie.Table4
        }
        .SelectMany(x => new[]
        {
            new PlayerResult(x.Game1.Player, x.Game1.Pins, x.Score),
            new PlayerResult(x.Game2.Player, x.Game2.Pins, x.Score)
        })
        .ToArray();
    }
示例#4
0
    private SeriesScores[] GetSeriesScores()
    {
        // calculate series scores
        List <SeriesScores> seriesScores = new();
        int cumulativeScore         = 0;
        int cumulativeOpponentScore = 0;

        for (int i = 0; i < matchSeries.Length; i++)
        {
            MatchSerie matchSerie = matchSeries[i];
            ResultSeriesReadModel.Serie opponentSerie = opponentSeries[i];
            SeriesScores seriesScore = new(matchSerie, opponentSerie, cumulativeScore, cumulativeOpponentScore);
            seriesScores.Add(seriesScore);
            cumulativeScore         = seriesScore.TeamScoreTotal;
            cumulativeOpponentScore = seriesScore.OpponentScoreTotal;
        }

        return(seriesScores.ToArray());
    }
示例#5
0
    public void Handle(SerieRegistered e, string aggregateId)
    {
        string id = ResultSeriesReadModel.IdFromBitsMatchId(e.BitsMatchId, e.RosterId);
        ResultSeriesReadModel results = DocumentSession.Load <ResultSeriesReadModel>(id);

        MatchSerie       matchSerie = e.MatchSerie;
        HashSet <string> playerIds  = new()
        {
            matchSerie.Table1.Game1.Player,
            matchSerie.Table1.Game2.Player,
            matchSerie.Table2.Game1.Player,
            matchSerie.Table2.Game2.Player,
            matchSerie.Table3.Game1.Player,
            matchSerie.Table3.Game2.Player,
            matchSerie.Table4.Game1.Player,
            matchSerie.Table4.Game2.Player
        };

        Dictionary <string, Player> players = DocumentSession.Load <Player>(playerIds).ToDictionary(x => x.Id);

        ResultSeriesReadModel.Table table1 = CreateTable(players, matchSerie.Table1);
        ResultSeriesReadModel.Table table2 = CreateTable(players, matchSerie.Table2);
        ResultSeriesReadModel.Table table3 = CreateTable(players, matchSerie.Table3);
        ResultSeriesReadModel.Table table4 = CreateTable(players, matchSerie.Table4);

        results.Series.Add(new ResultSeriesReadModel.Serie
        {
            Tables = new List <ResultSeriesReadModel.Table>
            {
                table1,
                table2,
                table3,
                table4
            }
        });
    }
示例#6
0
 public SerieRegistered(MatchSerie matchSerie, int bitsMatchId, string rosterId)
 {
     MatchSerie  = matchSerie ?? throw new ArgumentNullException(nameof(matchSerie));
     BitsMatchId = bitsMatchId;
     RosterId    = rosterId ?? throw new ArgumentNullException(nameof(rosterId));
 }
示例#7
0
 public SerieRegistered(MatchSerie matchSerie, int bitsMatchId)
 {
     if (matchSerie == null) throw new ArgumentNullException("matchSerie");
     MatchSerie = matchSerie;
     BitsMatchId = bitsMatchId;
 }