Skip to content

Instantly share code, notes, and snippets.

@CollinAlpert
Last active May 28, 2024 19:06
Show Gist options
  • Save CollinAlpert/f114a241f95c9a135e990f2f5bf63a2e to your computer and use it in GitHub Desktop.
Save CollinAlpert/f114a241f95c9a135e990f2f5bf63a2e to your computer and use it in GitHub Desktop.
Bingo-Generator
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
namespace Test;
internal static class Bingo
{
private const int GridSize = 5;
private const int GridMiddle = GridSize / 2;
public static void Run(string[] items, int numberOfCards, string title = "Bingo", bool freeSpace = false, string freeSpaceText = "Free Space")
{
if (numberOfCards <= 0)
{
Console.Error.WriteLine("Es muss mindestens eine Karte erzeugt werden.");
return;
}
if (items.Length < GridSize * GridSize - 1 && !freeSpace)
{
Console.Error.WriteLine($"Du benötigst mindestens {GridSize * GridSize - 1} Begriffe, um eine Bingo-Karte mit freien Feld zu erstellen.");
return;
}
if (items.Length < GridSize * GridSize && freeSpace)
{
Console.Error.WriteLine($"Du benötigst mindestens {GridSize * GridSize} Begriffe, um eine Bingo-Karte zu erstellen.");
return;
}
QuestPDF.Settings.License = LicenseType.Community;
Random.Shared.Shuffle(items);
if (numberOfCards == 1)
{
GenerateBingo("bingo_card.pdf", items, title, freeSpace, freeSpaceText);
return;
}
for (int i = 1; i < numberOfCards + 1; i++)
GenerateBingo($"bingo_card_{i}.pdf", items, title, freeSpace, freeSpaceText);
}
private static void GenerateBingo(string fileName, string[] items, string title, bool freeSpace, string freeSpaceText)
{
var document = Document.Create(container =>
{
container.Page(page =>
{
page.Size(PageSizes.A4);
page.Header().Height(50, Unit.Millimetre);
page.Content().AlignCenter().AlignMiddle().Column(column =>
{
column.Item().Text(title).FontFamily("Helvetica-Bold").AlignCenter().FontSize(18);
column.Item().Padding(20, Unit.Millimetre).Table(table =>
{
table.ColumnsDefinition(columnDefinition =>
{
for (int i = 0; i < GridSize; i++)
columnDefinition.RelativeColumn();
});
for (int x = 0; x < GridSize; x++)
for (int y = 0; y < GridSize; y++)
{
string text;
if (freeSpace && x == GridMiddle && y == GridMiddle)
{
text = freeSpaceText;
}
else
{
int reducer = x > GridMiddle || y > GridMiddle
? 1
: 0;
text = items[x * GridSize + y - reducer];
}
table.Cell()
.Column((uint)x + 1)
.Row((uint)y + 1)
.Element(Block)
.Padding(1, Unit.Millimetre)
.Text(text)
.FontFamily("Helvetica")
.FontSize(14);
}
});
});
page.Footer().Height(50, Unit.Millimetre);
});
});
document.GeneratePdf(fileName);
}
private static IContainer Block(IContainer container)
{
return container
.Border(1)
.MinWidth(50)
.MinHeight(50)
.AlignCenter()
.AlignMiddle();
}
}
namespace Test;
internal class Program
{
private static readonly string[] Items =
[
"Tarifvertrag wird erwähnt",
"Jemand anderes wiederholt (fast) wortgetreu etwas bereits Gesagtes",
"»… wir sind stark …«",
"Betriebsrat wird erwähnt",
"Witz, über den keiner lacht",
"Es wird betont, dass OSP nur rein formal/rechtlich die Hülle bildet",
"»… Learning rausziehen …",
"Synergie(-effekte)",
"Wir wollen Raum zum Austausch geben",
"Vision",
"Verhandlung",
"Frage/Kommentar zum Thema Nachhaltigkeit",
"»… wir wollen uns breiter aufstellen …«",
"»Kulturwandel«",
"»NewCo«",
"»Transformation«",
"»strategische Ausrichtung«",
"»… im Wesentlichen …«",
"»TechFusion«",
"Erwähnung der Differenz von 37,5 und 40 Std. Arbeitszeit",
"Irgendetwas ist »Prio 1«",
"»Betriebsteilübergang«",
"»Tech Powerhouse«",
"»Wir haben das auf dem Schirm«",
"»… auf Augenhöhe …«",
"Jemand stellt eine Frage, die komplett am Thema vorbeigeht"
];
private static void Main()
{
Bingo.Run(Items, 10, "Bingo", true, "Freies\nFeld");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment