🎮 Mini-Games Collection - Koda För Kul! 🎮

Marcus visar ett exempel → NI BYGGER SPEL SOM GALNINGAR! 🚀

20+ mini-spel att välja mellan! Perfekt för att träna programmering medan ni har kul! 🔥

🎲 DICE & CARD GAMES

4. Yahtzee Lite

20 min: Tärningsspel med strategi


class DiceGame
{
    Random rand = new Random();
    int[] dice = new int[5];

    public void RollDice(bool[] keep)
    {
        for (int i = 0; i < 5; i++)
        {
            if (!keep[i])
                dice[i] = rand.Next(1, 7);
        }
    }

    public void ShowDice()
    {
        Console.WriteLine($"Tärningar: [{string.Join(", ", dice)}]");
    }

    // ADD: Scoring combinations, multiple rounds, strategy tips!
}

5. Blackjack Trainer

25 min: Lär dig räkna kort… lagligt!


class Card
{
    public string Suit { get; set; }    // ♠♥♦♣
    public string Rank { get; set; }    // A, 2-10, J, Q, K
    public int Value { get; set; }      // Blackjack value
}

class BlackjackGame
{
    List<Card> deck = new List<Card>();
    List<Card> playerHand = new List<Card>();
    List<Card> dealerHand = new List<Card>();

    // Implement: dealing, hit/stand, card counting practice!
}

6. Lottery Simulator

8 min: Visa sannolikheter på riktigt!


int[] winningNumbers = GenerateLotteryNumbers();
int tickets = 0;
double spent = 0;
double won = 0;
int draws = 0;

Console.WriteLine("🎰 LOTTO SIMULATOR - Se hur ofta du vinner!");

while (won == 0 || draws < 1000) // Keep playing until big win
{
    int[] myNumbers = GenerateLotteryNumbers();
    tickets++;
    spent += 3; // 3kr per ticket
    draws++;

    int matches = CountMatches(winningNumbers, myNumbers);
    double prize = CalculatePrize(matches);
    won += prize;

    if (matches >= 4)
    {
        Console.WriteLine($"🎉 {matches} rätt! Vann {prize}kr!");
    }

    if (draws % 100 == 0)
    {
        Console.WriteLine($"After {draws} draws: Spent {spent}kr, Won {won}kr");
        Console.WriteLine($"Net result: {won - spent:F2}kr");
    }
}

⚡ ACTION GAMES (TEXT-BASED)

10. Snake Game ASCII

25 min: Classic snake i konsolen


class SnakeGame
{
    int width = 20, height = 10;
    List<(int x, int y)> snake = new List<(int, int)> { (10, 5) };
    (int x, int y) food = (15, 7);
    string direction = "RIGHT";
    int score = 0;

    public void DrawGame()
    {
        Console.Clear();

        // Draw borders
        for (int i = 0; i <= width + 1; i++) Console.Write("█");
        Console.WriteLine();

        for (int y = 0; y < height; y++)
        {
            Console.Write("█");
            for (int x = 0; x < width; x++)
            {
                if (snake.Contains((x, y)))
                    Console.Write("🐍");
                else if (food == (x, y))
                    Console.Write("🍎");
                else
                    Console.Write(" ");
            }
            Console.WriteLine("█");
        }

        for (int i = 0; i <= width + 1; i++) Console.Write("█");
        Console.WriteLine($"\nScore: {score}");
    }

    // ADD: Movement, collision detection, growth, high scores!
}

11. Text Adventure RPG

30+ min: Klassisk text-äventyr


class Player
{
    public int Health { get; set; } = 100;
    public int Attack { get; set; } = 20;
    public int Gold { get; set; } = 50;
    public List<string> Inventory { get; set; } = new List<string>();
}

class TextAdventure
{
    Player player = new Player();
    string currentLocation = "forest";

    public void StartGame()
    {
        Console.WriteLine("🗡️ VÄLKOMMEN TILL ÄVENTYRET!");
        Console.WriteLine("Du vaknar upp i en mörk skog...");

        while (player.Health > 0)
        {
            ShowLocation();
            ShowOptions();
            ProcessChoice(Console.ReadLine());
        }
    }

    void ShowLocation()
    {
        switch (currentLocation)
        {
            case "forest":
                Console.WriteLine("🌲 Du står i en tät skog. Du hör konstiga ljud...");
                break;
            case "village":
                Console.WriteLine("🏘️ Ett litet by med vänliga invånare.");
                break;
            case "dungeon":
                Console.WriteLine("💀 En mörk grotta. Det känns farligt här...");
                break;
        }
    }

    // EXPAND: Combat system, items, multiple endings, save/load!
}

12. Space Invaders ASCII

20 min: Retro arcade action


class SpaceInvaders
{
    int playerX = 10;
    List<(int x, int y)> bullets = new List<(int, int)>();
    List<(int x, int y)> enemies = new List<(int, int)>();
    int score = 0;
    int level = 1;

    public void InitializeEnemies()
    {
        enemies.Clear();
        for (int y = 2; y < 5; y++)
        {
            for (int x = 2; x < 18; x += 2)
            {
                enemies.Add((x, y));
            }
        }
    }

    // ADD: Player movement, shooting, enemy movement, collision!
}

🎪 PARTY GAMES

16. Reaction Time Tester

8 min: Hur snabba är dina reflexer?


class ReactionGame
{
    public void PlayGame()
    {
        Console.WriteLine("⚡ REAKTIONSTEST!");
        Console.WriteLine("Tryck SPACE så fort du ser 'NU!'");
        Console.WriteLine("Vänta...");

        Random rand = new Random();
        await Task.Delay(rand.Next(2000, 8000)); // Wait 2-8 seconds

        Console.WriteLine("🚨 NU!");
        DateTime startTime = DateTime.Now;

        while (Console.ReadKey().Key != ConsoleKey.Spacebar) { }

        DateTime endTime = DateTime.Now;
        double reactionMs = (endTime - startTime).TotalMilliseconds;

        Console.WriteLine($"\n⏱️ Din reaktionstid: {reactionMs:F0} ms");

        if (reactionMs < 200)
            Console.WriteLine("🏆 NINJA-REFLEXER!");
        else if (reactionMs < 300)
            Console.WriteLine("⚡ Mycket bra!");
        else if (reactionMs < 500)
            Console.WriteLine("👍 Genomsnitt");
        else
            Console.WriteLine("🐌 Träna mer!");
    }
}

17. Memory Pattern Game

10 min: Kom ihåg sekvensen!


List<int> pattern = new List<int>();
Random rand = new Random();
int level = 1;
bool gameOver = false;

Console.WriteLine("🧠 MINNESTEST!");
Console.WriteLine("Kom ihåg siffersekvensen!");

while (!gameOver && level <= 10)
{
    // Add new number to pattern
    pattern.Add(rand.Next(0, 10));

    // Show pattern briefly
    Console.Clear();
    Console.WriteLine($"Level {level}: Kom ihåg denna sekvens:");
    Console.WriteLine(string.Join(" - ", pattern));
    await Task.Delay(level * 800); // Longer sequences shown longer

    // Clear and ask for input
    Console.Clear();
    Console.WriteLine("Skriv sekvensen (separera med mellanslag):");

    // Check player input
    string[] input = Console.ReadLine().Split(' ');

    gameOver = !CheckSequence(input, pattern);

    if (!gameOver)
    {
        Console.WriteLine("✅ Rätt! Nästa level...");
        level++;
        await Task.Delay(1000);
    }
    else
    {
        Console.WriteLine($"❌ Fel! Du klarade {level - 1} levels!");
    }
}

18. Word Association Chain

6 min: Bygg associationskedjor


string startWord = "PROGRAMMING";
List<string> wordChain = new List<string> { startWord };
HashSet<string> usedWords = new HashSet<string> { startWord.ToUpper() };

Console.WriteLine("🔗 ORDASSOCIATION!");
Console.WriteLine($"Börja med: {startWord}");
Console.WriteLine("Nästa ord måste börja med samma bokstav som förra slutade!");

while (true)
{
    Console.Write($"({wordChain.Last().Last()}) → ");
    string nextWord = Console.ReadLine().ToUpper();

    if (string.IsNullOrEmpty(nextWord))
        break;

    if (usedWords.Contains(nextWord))
    {
        Console.WriteLine("❌ Ordet redan använt!");
        continue;
    }

    if (nextWord[0] != wordChain.Last().Last())
    {
        Console.WriteLine("❌ Fel startbokstav!");
        continue;
    }

    wordChain.Add(nextWord);
    usedWords.Add(nextWord);
    Console.WriteLine($"✅ Kedja längd: {wordChain.Count}");
}

Console.WriteLine($"🏆 Final kedja: {string.Join(" → ", wordChain)}");

🚀 EXPANSION IDEAS:

🎨 Visual Enhancements:

  • Colored text with Console.ForegroundColor
  • ASCII art animations
  • Progress bars and health meters
  • Screen layouts and borders

🔊 Audio Effects:

  • Console.Beep() for sounds
  • Different beep patterns for events
  • Background “music” with loops

💾 Persistence:

  • High score files
  • Game save states
  • Player profiles
  • Statistics tracking

🌐 Multiplayer Features:

  • Turn-based local play
  • Network games (advanced)
  • Tournaments and leaderboards

🤖 AI Features:

  • Adaptive difficulty
  • Machine learning opponents
  • Pattern recognition
  • Strategic analysis

🏆 ACHIEVEMENT SYSTEM:

  • First Blood: Complete your first game
  • Code Warrior: Implement AI opponent
  • Artist: Add ASCII art animations
  • Perfectionist: Add save/load system
  • Social Gamer: Create multiplayer features
  • Game Master: Build 5+ complete games

BYGG SPEL OCH HA KULL! 🎮🚀

Tips: Börja enkelt, lägg till features gradvis, och testa ofta!


Upp

Upp


Licens: Apache 2.0 | © 2023 Marcus Medina, Campus Mölndal. Alla rättigheter förbehållna.
Du får använda och modifiera detta verk enligt villkoren i Apache License, Version 2.0. Du får inte använda detta verk för kommersiella ändamål utan tillstånd från upphovsmannen.