Exemplo n.º 1
0
        public static ICommand Configure(User currentUser)
        {
            IGame chosenGame;

            do
            {
                Console.WriteLine($"Please provide the command like this: \"[Command] [Name of the Game]\"");
                PrintUnderlined("or exit with \"Exit\". You can list all available games with \"list\"");

                List <string> inputList = Console.ReadLine()?.Split(' ').ToList();
                if (inputList == null || inputList.Count < 2)
                {
                    continue;
                }
                string   commandName = inputList[0].ToLower();
                string   gameName    = inputList[1];
                ICommand cmd         = null;

                if (commandName == "buy")
                {
                    chosenGame = GameManagement.ChooseGame(gameName, false, currentUser);
                    if (chosenGame != null)
                    {
                        if (currentUser.OwnedGames.Any(game => game.Name == chosenGame.Name))
                        {
                            Console.WriteLine("You already own that Game!");
                            break;
                        }
                        IGame gameCopy = UserManagement.AddGame(chosenGame);
                        cmd = new Buy(gameCopy);
                    }
                    break;
                }

                chosenGame = GameManagement.ChooseGame(gameName, true, currentUser);
                switch (inputList[0].ToLower())
                {
                case "download":
                {
                    cmd = new Download(chosenGame);
                    break;
                }

                case "install":
                {
                    cmd = new Install(chosenGame);
                    break;
                }

                case "start":
                {
                    cmd = new Start(chosenGame);
                    break;
                }

                case "uninstall":
                {
                    cmd = new Uninstall(chosenGame);
                    break;
                }

                case "update":
                {
                    cmd = new Update(chosenGame);
                    break;
                }

                case "exit":
                {
                    return(null);
                }

                case "list":
                {
                    ListGames(GameManagement.AllAvailableGames);
                    break;
                }
                }

                return(cmd);
            } while (true);

            return(null);
        }