private static IDocumentPaginatorSource RenderFlowDocumentTemplate(Round round)
        {
            string rawXamlText = GetRoundXamlString(round);

            //Use the XAML reader to create a FlowDocument from the XAML string.
            FlowDocument document = XamlReader.Load(new XmlTextReader(new StringReader(rawXamlText))) as FlowDocument;
            return document;
        }
Ejemplo n.º 2
0
        public void AddRound(Round round)
        {
            round.Number = this.rounds.Count + 1;
            this.rounds.Add(round);

            int lp = 1;
            foreach (Game game in round.Games)
            {
                allGames.Remove(game);
                game.Number = lp++;

                game.DiceSystem(this);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generuje losowo pierwszą rundę
        /// </summary>
        /// <returns></returns>
        private Round AddFirstRound()
        {
            Round roundToRet = new Round();

            SortedList<int, Player> randomList = new SortedList<int, Player>();

            //Generowanie losowo miejsc w tabeli
            foreach (Player player in this.PointsTable)
            {
                if (player.Active == false || player.SuperBYE == true) continue;

                bool added = false;
                int index = 5;

                while (!added && index > 0)
                {
                    try
                    {
                        randomList.Add(RandomGenerator.Next(9999), player);
                        added = true;
                    }
                    catch { index--; continue; }
                }
            }

            //Przydzielanie miejsc w tabeli
            int place = this.pointstable.Where(p => p.SuperBYE).Count() + 1;
            foreach (KeyValuePair<int, Player> item in randomList)
            {
                item.Value.Place = place++;
            }

            //Generowanie par graczy
            for (int i = 0; i < randomList.Count; i++, i++)
            {
                //ostatni nieparzysty
                if (i + 1 == randomList.Count)
                {
                    Player player1 = randomList.Values[i];
                    IEnumerable<Game> gamesPlayers =
                        allGames.Where(g => (g.Player1Id == player1.Id && g.IsBYE == true));

                    roundToRet.Games.Add(gamesPlayers.ElementAt(0));
                    allGames.Remove(gamesPlayers.ElementAt(0));
                }
                else
                {
                    Player player1 = randomList.Values[i];
                    Player player2 = randomList.Values[i + 1];
                    IEnumerable<Game> gamesPlayers =
                        allGames.Where(g => ((g.Player1Id == player1.Id && g.Player2Id == player2.Id) ||
                                             (g.Player1Id == player2.Id && g.Player2Id == player1.Id)));

                    if (gamesPlayers.Count() > 0)
                    {
                        roundToRet.Games.Add(gamesPlayers.ElementAt(0));
                        allGames.Remove(gamesPlayers.ElementAt(0));
                    }
                }
            }

            int lp = 1;
            foreach (Game game in roundToRet.Games)
            {
                game.Number = lp++;
                game.DiceSystem(this);
            }

            return roundToRet;
        }
Ejemplo n.º 4
0
        private bool GetGame(IEnumerable<Player> playersToPair, ref Round round)
        {
            //warunek stopu
            if (playersToPair == null || playersToPair.Count() == 0) return true;

            //BYE
            if (playersToPair.Count() == 1)
            {
                Player player1 = playersToPair.First();

                IEnumerable<Game> gameBYE = allGames.Where(g => g.Player1Id == player1.Id && g.Player2Id == Guid.Empty);

                if (gameBYE.Count() > 0 && !player1.SuperBYE)
                {
                    //Opcja BYE tylko dla przegranych - jeśli ktoś nie grał nie dostaje BYE
                    if (App.Settings.BYEOnlyForLosers &&
                        this.rounds.Count > 0 &&
                        player1.GamesCount == 0)
                    {
                        return false;
                    }

                    round.Games.Add(gameBYE.First());
                    return true;
                }
                else
                {
                    return false;
                }
            }

            //Sparuj dwóch

            for (int indexPlayer1 = 0; indexPlayer1 < playersToPair.Count(); indexPlayer1++)
            {
                if (round.IsPlayerInGame(playersToPair.ElementAt(indexPlayer1).Id)) continue;

                for (int indexPlayer2 = indexPlayer1 + 1; indexPlayer2 < playersToPair.Count(); indexPlayer2++)
                {
                    if (round.IsPlayerInGame(playersToPair.ElementAt(indexPlayer2).Id)) continue;

                    Player player1 = playersToPair.ElementAt(indexPlayer1);
                    Player player2 = playersToPair.ElementAt(indexPlayer2);

                    IEnumerable<Game> gamesPlayers =
                        allGames.Where(g => ((g.Player1Id == player1.Id && g.Player2Id == player2.Id) ||
                                             (g.Player1Id == player2.Id && g.Player2Id == player1.Id)));

                    if (gamesPlayers.Count() > 0)
                    {
                        Game gameToAdd = gamesPlayers.ElementAt(0);
                        round.Games.Add(gameToAdd);

                        if (!this.GetGame(playersToPair.Where(p => p.Id != gameToAdd.Player1Id && p.Id != gameToAdd.Player2Id), ref round))
                        {
                            round.Games.Remove(gameToAdd);
                            continue;
                        }
                        else
                        {
                            return true;
                        }
                    }
                }
            }

            return false;
        }
Ejemplo n.º 5
0
        private Round GenerateAlternativeRound()
        {
            if (this.allGames.Count == 0) return null;

            IEnumerable<Player> activePlayers = null;

            if (App.Settings.RandomTieAfterPoints)
            {
                activePlayers = this.PointsTable.Where(p => p.Active == true)
                                                .OrderByDescending(p => p.Points)
                                                .ThenByDescending(p => p.LastTieBreak);
            }
            else
            {
                activePlayers = this.PointsTable.Where(p => p.Active == true)
                                                .OrderBy(p => p.Place);
            }

            Round roundToRet = new Round();
            if (!this.GetGame(activePlayers.ToList(), ref roundToRet))
                return null;
            else
                return roundToRet;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Pobiera
        /// </summary>
        /// <param name="round"></param>
        private Round GenerateNextRound()
        {
            if (this.allGames.Count == 0) return null;

            Round roundToRet = new Round();
            roundToRet = this.GenerateAlternativeRound();

            if (roundToRet != null)
            {
                int lp = 1;
                foreach (Game game in roundToRet.Games)
                {
                    allGames.Remove(game);
                    game.Number = lp++;

                    game.DiceSystem(this);
                }
            }

            return roundToRet;
        }
Ejemplo n.º 7
0
 private void bkgGenerateRound_DoWork(object sender, DoWorkEventArgs e)
 {
     roundToAdd = this.tournament.CreateNextRound();
 }
 public static void PrintRound(Round round)
 {
     if (round == null) return;
     IDocumentPaginatorSource flowDocument = XamlTemplatePrinter.RenderFlowDocumentTemplate(round);
     PrintDocument(flowDocument);
 }
        private static string GetRoundXamlString(Round round)
        {
            StringBuilder xamlString = new StringBuilder();

            xamlString.AppendLine("<FlowDocument xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" ");
            xamlString.AppendLine(" ColumnWidth=\"400\" FontSize=\"16\" FontFamily=\"Arial\">");

            //Header
            xamlString.AppendLine("<Paragraph TextAlignment=\"Center\" FontSize=\"16pt\" FontWeight=\"Bold\">");
            xamlString.AppendFormat("{1} {0} ", round.Number, StringTable.RoundControl_Runda);
            xamlString.AppendLine("</Paragraph>");

            //Tabela gier
            xamlString.AppendLine("<Table CellSpacing=\"10\">");
            xamlString.AppendLine("<Table.Columns><TableColumn Width=\"100\"/><TableColumn Width=\"200\"/><TableColumn Width=\"200\"/></Table.Columns>");
            xamlString.AppendLine("<TableRowGroup>");

            //Header tabeli
            xamlString.AppendLine("<TableRow>");
            xamlString.AppendFormat("<TableCell><Paragraph FontSize=\"16pt\" FontWeight=\"Bold\" TextAlignment=\"Right\">{0}</Paragraph></TableCell>", StringTable.RoundControl_Nr);
            xamlString.AppendLine();
            xamlString.AppendFormat("<TableCell><Paragraph FontSize=\"16pt\" FontWeight=\"Bold\">{0}</Paragraph></TableCell>", StringTable.RoundControl_Gracz1);
            xamlString.AppendLine();
            xamlString.AppendFormat("<TableCell><Paragraph FontSize=\"16pt\" FontWeight=\"Bold\">{0}</Paragraph></TableCell>", StringTable.RoundControl_Gracz2);
            xamlString.AppendLine();
            xamlString.AppendLine("</TableRow>");

            //wiersze tabeli
            int lp = 1;
            foreach (Game game in round.Games)
            {
                //co 10 pagebreak
                if (lp != 1 && (lp % 30) - 1 == 0)
                {
                    xamlString.AppendLine("</TableRowGroup>");
                    xamlString.AppendLine("</Table>");
                    xamlString.AppendLine("<Section BreakPageBefore=\"True\"/>");

                    //Header
                    xamlString.AppendLine("<Paragraph TextAlignment=\"Center\" FontSize=\"16pt\" FontWeight=\"Bold\">");
                    xamlString.AppendFormat("{1} {0} ", round.Number, StringTable.RoundControl_Runda);
                    xamlString.AppendLine("</Paragraph>");

                    //Tabela gier
                    xamlString.AppendLine("<Table CellSpacing=\"10\">");
                    xamlString.AppendLine("<Table.Columns><TableColumn Width=\"100\"/><TableColumn Width=\"200\"/><TableColumn Width=\"200\"/></Table.Columns>");
                    xamlString.AppendLine("<TableRowGroup>");

                    //Header tabeli
                    xamlString.AppendLine("<TableRow>");
                    xamlString.AppendFormat("<TableCell><Paragraph FontSize=\"16pt\" FontWeight=\"Bold\" TextAlignment=\"Right\">{0}</Paragraph></TableCell>", StringTable.RoundControl_Nr);
                    xamlString.AppendLine();
                    xamlString.AppendFormat("<TableCell><Paragraph FontSize=\"16pt\" FontWeight=\"Bold\">{0}</Paragraph></TableCell>", StringTable.RoundControl_Gracz1);
                    xamlString.AppendLine();
                    xamlString.AppendFormat("<TableCell><Paragraph FontSize=\"16pt\" FontWeight=\"Bold\">{0}</Paragraph></TableCell>", StringTable.RoundControl_Gracz2);
                    xamlString.AppendLine();
                    xamlString.AppendLine("</TableRow>");
                }


                xamlString.AppendFormat("<TableRow {0}>", lp % 2 == 0 ? " Background=\"LightGray\"" : string.Empty);
                xamlString.AppendFormat("<TableCell><Paragraph TextAlignment=\"Right\">{0}</Paragraph></TableCell>", game.Number.ToString());
                xamlString.AppendFormat("<TableCell><Paragraph>{0}</Paragraph></TableCell>", SecurityElement.Escape(game.Player1Alias));
                xamlString.AppendFormat("<TableCell><Paragraph>{0}</Paragraph></TableCell>", string.IsNullOrWhiteSpace(SecurityElement.Escape(game.Player2Alias)) ? "BYE" : SecurityElement.Escape(game.Player2Alias));
                xamlString.AppendLine("</TableRow>");
                lp++;
            }

            xamlString.AppendLine("</TableRowGroup>");
            xamlString.AppendLine("</Table>");

            //koniec dokumentu
            xamlString.AppendLine("</FlowDocument>");

            return xamlString.ToString();
        }