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); }
public static void ListGames(List <IGame> games, bool seeBorrow = false) { string message; if (games == null || games.Count == 0) { message = "No Games to show!"; Console.WriteLine('\t' + message); } else { if (seeBorrow) { foreach (var game in games) { var currentUserString = game.CurrentUser == null || !game.IsLent ? "-" : UserManagement.FindUserName((Guid)game.CurrentUser); var wantsToBorrow = game._userWhoWantsToBorrow == null ? "-" : UserManagement.FindUserName((Guid)game._userWhoWantsToBorrow); Console.WriteLine($"\t{game.Name}, borrowed by: {currentUserString}, wants to be borrowed by: {wantsToBorrow}"); } } else { games.ForEach(game => Console.WriteLine($"\t{game?.Name}")); } message = games.Last().Name; } Console.WriteLine(new string(' ', 8) + new string('ยบ', message.Length) + '\n'); }