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() != "") {
|
||||||
|
string resp = usr_in.Trim();
|
||||||
if (integer) {
|
if (integer) {
|
||||||
string resp = usr_in.Trim();
|
|
||||||
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 {
|
||||||
|
print($"Please enter a valid option (", false);
|
||||||
|
foreach (string opt in opts) {
|
||||||
|
print($" {opt} ", false);
|
||||||
|
}
|
||||||
|
print(")");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return usr_in.Trim();
|
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) {
|
||||||
@ -218,7 +233,7 @@ void check_age_and_desc(string[,] animals) {
|
|||||||
int pet_count = max_pets - (availability(animals));
|
int pet_count = max_pets - (availability(animals));
|
||||||
for (int j = 0; j < pet_count; j++) {
|
for (int j = 0; j < pet_count; j++) {
|
||||||
if (animals[j, 3] == "-1") {
|
if (animals[j, 3] == "-1") {
|
||||||
print("\n"+separator);
|
print("\n" + separator);
|
||||||
string[] animal = {
|
string[] animal = {
|
||||||
animals[j,0], animals[j,1], animals[j,2],
|
animals[j,0], animals[j,1], animals[j,2],
|
||||||
animals[j,3], animals[j,4], animals[j,5]
|
animals[j,3], animals[j,4], animals[j,5]
|
||||||
@ -226,21 +241,21 @@ void check_age_and_desc(string[,] animals) {
|
|||||||
print_pet(animal);
|
print_pet(animal);
|
||||||
int age = Int32.Parse(
|
int age = Int32.Parse(
|
||||||
get_input(
|
get_input(
|
||||||
$"Enter an age for ID: {animals[j,1]}" +
|
$"Enter an age for ID: {animals[j, 1]}" +
|
||||||
" (-1 if unknown): ", true
|
" (-1 if unknown): ", true
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
animals[j, 3] = age.ToString();
|
animals[j, 3] = age.ToString();
|
||||||
}
|
}
|
||||||
if (animals[j, 2] == "?") {
|
if (animals[j, 2] == "?") {
|
||||||
print("\n"+separator);
|
print("\n" + separator);
|
||||||
string[] animal = {
|
string[] animal = {
|
||||||
animals[j,0], animals[j,1], animals[j,2],
|
animals[j,0], animals[j,1], animals[j,2],
|
||||||
animals[j,3], animals[j,4], animals[j,5]
|
animals[j,3], animals[j,4], animals[j,5]
|
||||||
};
|
};
|
||||||
print_pet(animal);
|
print_pet(animal);
|
||||||
string desc = get_input(
|
string desc = get_input(
|
||||||
$"Enter a physical description for ID: {animals[j,1]}" +
|
$"Enter a physical description for ID: {animals[j, 1]}" +
|
||||||
" (? if unknown): "
|
" (? if unknown): "
|
||||||
);
|
);
|
||||||
animals[j, 2] = desc;
|
animals[j, 2] = desc;
|
||||||
@ -256,27 +271,27 @@ void check_nick_and_perso(string[,] animals) {
|
|||||||
int pet_count = max_pets - (availability(animals));
|
int pet_count = max_pets - (availability(animals));
|
||||||
for (int j = 0; j < pet_count; j++) {
|
for (int j = 0; j < pet_count; j++) {
|
||||||
if (animals[j, 5] == "?") {
|
if (animals[j, 5] == "?") {
|
||||||
print("\n"+separator);
|
print("\n" + separator);
|
||||||
string[] animal = {
|
string[] animal = {
|
||||||
animals[j,0], animals[j,1], animals[j,2],
|
animals[j,0], animals[j,1], animals[j,2],
|
||||||
animals[j,3], animals[j,4], animals[j,5]
|
animals[j,3], animals[j,4], animals[j,5]
|
||||||
};
|
};
|
||||||
print_pet(animal);
|
print_pet(animal);
|
||||||
string nick = get_input(
|
string nick = get_input(
|
||||||
$"Enter a nickname for ID: {animals[j,1]}" +
|
$"Enter a nickname for ID: {animals[j, 1]}" +
|
||||||
"(? if unknown): "
|
"(? if unknown): "
|
||||||
);
|
);
|
||||||
animals[j, 5] = nick;
|
animals[j, 5] = nick;
|
||||||
}
|
}
|
||||||
if (animals[j, 4] == "?") {
|
if (animals[j, 4] == "?") {
|
||||||
print("\n"+separator);
|
print("\n" + separator);
|
||||||
string[] animal = {
|
string[] animal = {
|
||||||
animals[j,0], animals[j,1], animals[j,2],
|
animals[j,0], animals[j,1], animals[j,2],
|
||||||
animals[j,3], animals[j,4], animals[j,5]
|
animals[j,3], animals[j,4], animals[j,5]
|
||||||
};
|
};
|
||||||
print_pet(animal);
|
print_pet(animal);
|
||||||
string perso = get_input(
|
string perso = get_input(
|
||||||
$"Enter a personality description for ID: {animals[j,1]}" +
|
$"Enter a personality description for ID: {animals[j, 1]}" +
|
||||||
"(? if unknown): "
|
"(? if unknown): "
|
||||||
);
|
);
|
||||||
animals[j, 4] = perso;
|
animals[j, 4] = perso;
|
||||||
|
Loading…
Reference in New Issue
Block a user