end 019
This commit is contained in:
parent
3c751c6a2f
commit
34afc69172
@ -136,20 +136,33 @@ int availability(string[,] animals) {
|
|||||||
return slots;
|
return slots;
|
||||||
}
|
}
|
||||||
|
|
||||||
string get_input(string text = "Please enter your text: ", bool integer = false) {
|
string get_input(string text = "Please enter your text: ",
|
||||||
|
bool integer = false,
|
||||||
|
string[]? opts = null) {
|
||||||
bool invalid = true;
|
bool invalid = true;
|
||||||
while (invalid) {
|
while (invalid) {
|
||||||
print(text, false);
|
print(text, false);
|
||||||
string? usr_in = Console.ReadLine();
|
string? usr_in = Console.ReadLine();
|
||||||
if (!string.IsNullOrEmpty(usr_in) && usr_in.Trim() != "") {
|
if (!string.IsNullOrEmpty(usr_in) && usr_in.Trim() != "") {
|
||||||
if (integer) {
|
|
||||||
string resp = usr_in.Trim();
|
string resp = usr_in.Trim();
|
||||||
|
if (integer) {
|
||||||
int temp_int;
|
int temp_int;
|
||||||
if (int.TryParse(resp, out temp_int)) {
|
if (int.TryParse(resp, out temp_int)) {
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
} else if (opts != null) {
|
||||||
|
resp = resp.ToLower();
|
||||||
|
if (opts.Contains(resp)) {
|
||||||
|
return resp;
|
||||||
} else {
|
} else {
|
||||||
return usr_in.Trim();
|
print($"Please enter a valid option (", false);
|
||||||
|
foreach (string opt in opts) {
|
||||||
|
print($" {opt} ", false);
|
||||||
|
}
|
||||||
|
print(")");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return resp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,7 +172,7 @@ string get_input(string text = "Please enter your text: ", bool integer = false)
|
|||||||
void add_new_pet(string[,] animals, int slots) {
|
void add_new_pet(string[,] animals, int slots) {
|
||||||
int at_indx = max_pets - slots;
|
int at_indx = max_pets - slots;
|
||||||
string id = $"{rand_str(abcd)}{rand_int(nums)}";
|
string id = $"{rand_str(abcd)}{rand_int(nums)}";
|
||||||
string specie = get_input("Enter pet specie: ");
|
string specie = get_input("Enter pet specie: ", false, species);
|
||||||
string name = get_input("Enter the pet name (? if unknown): ");
|
string name = get_input("Enter the pet name (? if unknown): ");
|
||||||
int age = Int32.Parse(get_input("Enter pet age (-1 if unknown): ", true));
|
int age = Int32.Parse(get_input("Enter pet age (-1 if unknown): ", true));
|
||||||
string desc = get_input("Enter the physical description (? if unknown): ");
|
string desc = get_input("Enter the physical description (? if unknown): ");
|
||||||
@ -182,7 +195,9 @@ void ask_new_pet() {
|
|||||||
if (slots > 0) {
|
if (slots > 0) {
|
||||||
bool another = false;
|
bool another = false;
|
||||||
do {
|
do {
|
||||||
string resp = get_input("Do you want to enter info for another pet?: ");
|
string resp = get_input(
|
||||||
|
"Do you want to enter info for another pet?: "
|
||||||
|
);
|
||||||
bool invalid = true;
|
bool invalid = true;
|
||||||
if (resp != "") {
|
if (resp != "") {
|
||||||
while (invalid) {
|
while (invalid) {
|
||||||
|
Loading…
Reference in New Issue
Block a user