Own project · Stop 7 of 10

Flashcards

A flashcard app: front, back, right or wrong, and cards you do not know yet come up more often.

Flashcards

Goal

Build a learning tool that remembers which cards are already known.

Implementation

  • Cards with a front and a back, sorted into categories. A tap on the card turns it over.
  • Every card has points: "Wrong" raises them, "Right" lowers them, and the next card is drawn weighted by those points.
  • A start page with categories and the learning view; editing and settings are still in the works. The data is kept in SQLite.
  • I reworked the interface later: one color scheme for light and dark Windows, tiles for the categories and a large learning card.

Code

Drawing cards weighted by points

DatabaseService.cs
public async Task<Card?> GetRandomCardAsync(int categoryId)
{
    var cards = await _db.Table<Card>()
        .Where(c => c.CategoryId == categoryId)
        .ToListAsync();

    if (cards.Count == 0)
        return null;

    int totalWeight = cards.Sum(c => c.Points);

    if (totalWeight == 0)
        return cards[new Random().Next(cards.Count)];

    int randomValue = new Random().Next(0, totalWeight);
    int cumulative = 0;

    foreach (var card in cards)
    {
        cumulative += card.Points;
        if (randomValue < cumulative)
            return card;
    }

    return cards.Last();
}

The more points a card has, the more likely it comes up next.

What I learned

Using a data model with tables and relations in an app. The learning logic could start out simple.

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.