Mein 1stes Spiel

- Veröffentlicht unter Felix von

using System;
using System.Threading;

namespace LogoDestroyerGame
{
    class Program
    {
        static int money = 0;
        static int playerAttackPower = 1;
        static int playerSpeed = 1;
        static int logosDestroyed = 0;
        static NPC currentEmployee = null;  // Nur einen Mitarbeiter
        static Logo currentLogo = null;     // Nur ein Logo
        static Random rnd = new Random();
        static bool gameRunning = true;

        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("Willkommen beim Logo Destroyer Game!");
            Console.WriteLine("Zerstöre Logos und verdiene Geld, um Ausrüstung und Mitarbeiter zu kaufen!");

            // Ein Logo spawnt zu Beginn
            SpawnNewLogo();

            // Starte den Spiel-Loop in einem separaten Thread
            Thread gameLoop = new Thread(GameLoop) { IsBackground = true };
            gameLoop.Start();

            while (gameRunning)
            {
                ShowMenu();
                string input = Console.ReadLine();
                if (input == "1") // Hand benutzen, um Logos zu zerstören
                {
                    DestroyLogoWithHand();
                }
                else if (input == "2") // Mitarbeiter einstellen
                {
                    HireEmployee();
                }
                else if (input == "3") // Ausrüstung kaufen
                {
                    BuyEquipment();
                }
                else if (input == "4") // Spiel beenden
                {
                    gameRunning = false;
                }
                else
                {
                    Console.WriteLine("Ungültige Auswahl. Bitte versuche es erneut.");
                }
            }
        }

        static void GameLoop()
        {
            while (gameRunning)
            {
                // Nur das aktuelle Logo anzeigen, ohne es neu zu erstellen
                if (currentLogo != null)
                {
                    DrawLogo(currentLogo);
                }

                Thread.Sleep(1000); // Alle 1 Sekunde das Logo erneut anzeigen
            }
        }

        static void SpawnNewLogo()
        {
            // Erstellt nur ein Logo, wenn keines existiert
            if (currentLogo == null)
            {
                string logoName = "Logo_" + rnd.Next(1000, 9999); // Zufälliger Name für das Logo
                currentLogo = new Logo { Name = logoName, Health = rnd.Next(5, 20), Value = rnd.Next(10, 50) };
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Ein neues Logo erscheint!");
            }
        }

        static void ShowMenu()
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Geld: $" + money);
            Console.WriteLine("Zerstörte Logos: " + logosDestroyed);
            Console.WriteLine("1. Logos mit der Hand zerstören");
            Console.WriteLine("2. Mitarbeiter einstellen (Kosten: $100)");
            Console.WriteLine("3. Ausrüstung kaufen");
            Console.WriteLine("4. Spiel beenden");
            Console.Write("Wähle eine Option: ");
        }

        static void DestroyLogoWithHand()
        {
            if (currentLogo == null)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Keine Logos zum Zerstören!");
                Thread.Sleep(1000);
                return;
            }

            Logo logo = currentLogo;
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine($"Du zerstörst das Logo mit {playerAttackPower} Angriffskraft!");

            // Der Spieler zerstört das Logo
            logo.Health -= playerAttackPower;

            if (logo.Health <= 0)
            {
                logosDestroyed++;
                money += logo.Value;
                currentLogo = null; // Entferne das zerstörte Logo
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine($"Logo zerstört! Du bekommst ${logo.Value}!");
                DrawLogoDestroyed();
                SpawnNewLogo(); // Spawn ein neues Logo, nachdem das alte zerstört wurde
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine($"Logo hat noch {logo.Health} Lebenspunkte.");
            }

            Thread.Sleep(500); // Kleine Verzögerung für die Aktion
        }

        static void HireEmployee()
        {
            if (money >= 100)
            {
                money -= 100;
                currentEmployee = new NPC
                {
                    AttackPower = 3, // Der Mitarbeiter verursacht 3 Schaden alle 5 Sekunden
                    Name = "Mitarbeiter #" + (currentEmployee != null ? 2 : 1)
                };
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.WriteLine($"Mitarbeiter {currentEmployee.Name} wurde eingestellt!");
                DrawEmployeeHired();

                // Starte den Mitarbeiter-Thread, falls er noch nicht läuft
                Thread employeeActionThread = new Thread(EmployeeAction);
                employeeActionThread.IsBackground = true; // Setze den Thread als Hintergrund-Thread
                employeeActionThread.Start();
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Nicht genug Geld, um einen Mitarbeiter einzustellen.");
            }

            Thread.Sleep(1000);
        }

        static void BuyEquipment()
        {
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Ausrüstung kaufen:");
            Console.WriteLine("1. Verbesserte Hand (Kosten: $50) - Angriffsleistung +1");
            Console.WriteLine("2. Schnellere Hand (Kosten: $75) - Geschwindigkeit +1");
            Console.WriteLine("3. Zurück");
            Console.Write("Wähle eine Option: ");

            string input = Console.ReadLine();

            if (input == "1" && money >= 50)
            {
                money -= 50;
                playerAttackPower++;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Du hast eine verbesserte Hand gekauft. Angriffsleistung +1");
            }
            else if (input == "2" && money >= 75)
            {
                money -= 75;
                playerSpeed++;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Du hast eine schnellere Hand gekauft. Geschwindigkeit +1");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Nicht genug Geld oder ungültige Auswahl.");
            }

            Thread.Sleep(1000);
        }

        static void DrawLogo(Logo logo)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine(@"
      _________
     /         \
    |   " + logo.Name + @"   |
    |  [####]  |
     \_________/
            ");
            Console.WriteLine($"Logo: {logo.Name} | Lebenspunkte: {logo.Health}");
        }

        static void DrawLogoDestroyed()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Logo zerstört!");
            Console.WriteLine(@"
      _________
     /    X    \
    |    X     |
    |   [X]    |
     \_________/
            ");
        }

        static void DrawEmployeeHired()
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("Mitarbeiter wurde erfolgreich eingestellt!");
            Console.WriteLine(@"
         /| 
        //\\
       //  \\ 
      //    \\
     /______\\
    (  o  o  )
     \    ^   /
      \______/
            ");
        }

        static void EmployeeAction()
        {
            while (gameRunning)
            {
                if (currentEmployee != null && currentLogo != null)
                {
                    // Alle 5 Sekunden Schaden an einem Logo verursachen
                    Thread.Sleep(5000); // Warte 5 Sekunden
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine($"{currentEmployee.Name} greift das Logo an!");
                    // Mitarbeiter macht Schaden an einem Logo
                    currentLogo.Health -= currentEmployee.AttackPower;

                    // Wenn das Logo zerstört ist, stoppe die Aktionen und spawn ein neues Logo
                    if (currentLogo.Health <= 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine($"{currentEmployee.Name} hat das Logo zerstört!");
                        money += currentLogo.Value; // Geld hinzufügen
                        currentLogo = null; // Zerstöre das Logo
                        SpawnNewLogo(); // Spawn ein neues Logo
                    }
                }
            }
        }

        class Logo
        {
            public string Name { get; set; }
            public int Health { get; set; }
            public int Value { get; set; }
        }

        class NPC
        {
            public string Name { get; set; }
            public int AttackPower { get; set; }
        }
    }
}