Own project · Stop 6 of 10

Jeopardina

A quiz game in the style of Jeopardy: teams pick categories and point levels, answer questions against the clock and collect points.

Jeopardina

Goal

Build a game for several teams where questions can be added and removed.

Implementation

  • Desktop interface with WPF: pages for setting up a game, for adding and removing questions and the game board itself.
  • Two windows per game: the board for the teams (for example on a second screen) and a moderator window, which is still empty.
  • The board has 3 to 5 categories with five levels each, from 100 to 500 points, plus a time limit per question and the teams' scores.
  • Questions, answers, points and categories are kept in an SQLite database. Custom controls and templates, for example a flip card.

Code

Building the game board from the database

StartGamePage.xaml.cs
var questionsCommand = connection.CreateCommand();
questionsCommand.CommandText = "SELECT Fragen, Antwort, Punkte FROM fragen WHERE KategorieID = @CategoryId;";
questionsCommand.Parameters.AddWithValue("@CategoryId", categoryId);

var allQuestionsForCategory = new List<QuestionData>();
using (var reader = questionsCommand.ExecuteReader())
{
    while (reader.Read())
    {
        allQuestionsForCategory.Add(new QuestionData
        {
            QuestionText = reader.GetString(0),
            AnswerText = reader.GetString(1),
            Points = reader.GetInt32(2)
        });
    }
}

var categoryData = new CategoryAndQuestions { CategoryName = categoryName };
for (int j = 0; j < 5; j++)
{
    int points = (j + 1) * 100;
    var questionsForPoints = allQuestionsForCategory.Where(q => q.Points == points).ToList();
    if (questionsForPoints.Count > 0)
    {
        int randomIndex = random.Next(questionsForPoints.Count);
        categoryData.Questions[j] = questionsForPoints[randomIndex];
    }
    else
    {
        categoryData.Questions[j] = new QuestionData { QuestionText = "N/A", AnswerText = "N/A", Points = points };
    }
}

For every level from 100 to 500 points a matching question of the category is drawn at random; if there is none, the field says "N/A".

What I learned

WPF with XAML, templates and data binding, and how to connect a database to a desktop app.

An unexpected error has occurred. Reload 🗙

Reconnecting to the server …

Connection failed. Trying again in seconds.

Connection failed. Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session. Please retry or reload the page.