public static CoachModel CreateCoach() { Console.Clear(); string[] descriptionLines = { "Hello coach!", "Before you continue, please insert your information" }; var options = new List <string>(); options.Add("[1] Name: "); //coach properties CoachSpeciality speciality = CoachSpeciality.DefaultNone; var nameInput = (name : "", done : false); var ageInput = (ageString : "", done : false); var specialityInput = (speciality : speciality, done : false); bool allInfoDone = false; Console.CursorVisible = false; do { Console.Clear(); OptionMenuTableUnicodeAlt(descriptionLines, options.ToArray()); ConsoleKey input = Console.ReadKey(true).Key; // update table options if (input == ConsoleKey.Enter) { // age if (!nameInput.done && nameInput.name.Length > 2) { options.Add("[2] Age: "); nameInput.done = true; } // speciality else if (!ageInput.done && ageInput.ageString.Length > 1) { options.Add("[3] Speciality: "); ageInput.done = true; string[] title = { "Please select your Speciality:" }; string[] specialities = { "AGRESSIVE", "DEFENCIVE", "BALANCED" }; int especialityChoiceIndex = OptionChoice(false, title, specialities); options[2] = "[3] Speciality: " + specialities[especialityChoiceIndex]; options.Add(""); options.Add("Press Enter to continue..."); switch (especialityChoiceIndex) { case 0: specialityInput.speciality = CoachSpeciality.Agressive; break; case 1: specialityInput.speciality = CoachSpeciality.Defencive; break; case 2: specialityInput.speciality = CoachSpeciality.Balanced; break; } ; } // all info else if (!specialityInput.done && specialityInput.speciality != CoachSpeciality.DefaultNone) { allInfoDone = true; } } // get input values else { // name if (!nameInput.done) { switch (input) { case ConsoleKey.Backspace: if (String.IsNullOrEmpty(nameInput.name)) { break; } nameInput.name = nameInput.name.Remove(nameInput.name.Length - 1); break; case ConsoleKey.Spacebar: nameInput.name += " "; break; default: nameInput.name += input.ToString(); break; } ; options[0] = "[1] Name: " + nameInput.name; } // Age else if (!ageInput.done) { switch (input) { case ConsoleKey.Backspace: if (String.IsNullOrEmpty(ageInput.ageString)) { break; } ageInput.ageString = ageInput.ageString.Remove(ageInput.ageString.Length - 1); break; default: string inputValueString = input.ToString().Replace("D", ""); if (int.TryParse(inputValueString, out _)) { if (ageInput.ageString.Length == 2) { break; } ageInput.ageString += inputValueString; } else { //TODO TABLE WARNING } break; } ; options[1] = "[2] Age: " + ageInput.ageString; } } } while (!allInfoDone); int ageInt = Int32.Parse(ageInput.ageString); return(new CoachModel( name: nameInput.name, age: ageInt, speciality: specialityInput.speciality)); }
public CoachModel(string name, int age, CoachSpeciality speciality) { this.name = name; this.age = age; this.speciality = speciality; }