Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.7 kB
7
Indexable
using System;

namespace LaborationCC
{
    class UserInterface
    {
        private readonly IGame game;

        public UserInterface(IGame game)
        {
            this.game = game;
        }

        public void Run()
        {
            Console.WriteLine("Welcome to the game!");

            bool running = true;
            while (running)
            {
                Console.WriteLine("Select an option:");
                Console.WriteLine("1. Play");
                Console.WriteLine("2. Clear Player Data");
                Console.WriteLine("3. Exit");

                string input = Console.ReadLine();

                switch (input)
                {
                    case "1":
                        PlayGame();
                        break;
                    case "2":
                        ClearPlayerData();
                        break;
                    case "3":
                        running = false;
                        break;
                    default:
                        Console.WriteLine("Invalid option. Please try again.");
                        break;
                }
            }

            Console.WriteLine("Thank you for playing!");
        }

        private void PlayGame()
        {
            Console.WriteLine("Enter your username:");
            string name = Console.ReadLine();

            game.Play();
        }

        private void ClearPlayerData()
        {
            Console.WriteLine("Are you sure you want to clear all player data? (y/n)");
            string input = Console.ReadLine();

            if (input?.ToLower() == "y")
            {
                // Clear the player data
                // Assuming playerDataStorage is an instance of IPlayerDataStorage
                playerDataStorage.ClearData();
                Console.WriteLine("Player data cleared successfully.");
            }
            else
            {
                Console.WriteLine("Player data was not cleared.");
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            string resultFilePath = "result.txt";
            IGoalGeneratorFactory generatorFactory = new RandomGoalGeneratorFactory();
            IGuessCheckerFactory checkerFactory = new GuessCheckerFactory();
            IPlayerDataStorage storage = new PlayerDataStorage(resultFilePath);
            IGame game = new MainClass(generatorFactory, checkerFactory, storage);

            UserInterface ui = new UserInterface(game);
            ui.Run();
        }
    }
}