Query changes...

This commit is contained in:
Ognjen Milan Robovic 2024-06-16 15:47:45 -04:00
parent 511f55fbad
commit c6d1bcc7ab

View File

@ -45,6 +45,31 @@ static void separate (void) {
print ("/0------------------------------------------------------------------------------------------/-\n");
}
static int query (char * names [], int count) {
char input [1024] = "";
int index = reply_help;
requery: for (index = 0; index < 1024; ++index) {
in (& input [index], 1);
if (input [index] == '\n') {
break;
}
}
input [index] = '\0';
for (index = 0; index < count; ++index) {
if (string_compare (input, names [index]) == true) {
return (index);
}
}
print ("Incorrect /1reply/-, type '/3help/-' to list replies or look at message above.\n");
goto requery;
}
static void print_help (void) {
int index;
@ -96,54 +121,36 @@ static void print_statistics (void) {
separate ();
}
static void build_construction (int index) {
int price;
static void build_construction (void) {
int index;
int reply;
for (price = 0; price < resources; ++price) {
if (resource [price] < construction_price [index] [price]) {
print ("You don't have enough /1%s/-, need /1%i/- more.\n", resource_name [price], construction_price [index] [price] - resource [price]);
print ("Your architect humbly refused to build /1%s/-.\n", construction_name [index]);
for (index = 0; index < constructions; ++index) {
print ("/0->/- build /3%s/- ()\n", construction_name [index]);
}
reply = query (construction_name, constructions);
for (index = 0; index < resources; ++index) {
if (resource [index] < construction_price [reply] [index]) {
print ("You don't have enough /1%s/-, need /1%i/- more.\n", resource_name [index], construction_price [reply] [index] - resource [index]);
print ("Your architect humbly refused to build /1%s/-.\n", construction_name [reply]);
separate ();
return;
}
}
for (price = 0; price < resources; ++price) {
resource [price] -= construction_price [index] [price];
for (index = 0; index < resources; ++index) {
resource [index] -= construction_price [reply] [index];
}
construction [index] += 1;
construction [reply] += 1;
print ("Construction of /2%s/- was completed successfully.\n", construction_name [index]);
print ("Construction of /2%s/- was completed successfully.\n", construction_name [reply]);
separate ();
}
static int query (void) {
char input [1024] = "";
int index = reply_help;
requery: for (index = 0; index < 1024; ++index) {
in (& input [index], 1);
if (input [index] == '\n') {
break;
}
}
input [index] = '\0';
for (index = 0; index < replies; ++index) {
if (string_compare (input, reply_name [index]) == true) {
return (index);
}
}
print ("Incorrect /1reply/-, type '/3help/-' to list replies.\n");
goto requery;
}
int main (void) {
int index;
int reply;
@ -161,18 +168,18 @@ int main (void) {
construction [index] = random (1, 2);
}
for (reply = reply_help; reply != reply_quit; reply = query ()) {
for (reply = reply_help; reply != reply_quit; reply = query (reply_name, replies)) {
separate ();
switch (reply) {
case reply_help: print_help (); break;
case reply_report: print_resources (); break;
case reply_status: print_statistics (); break;
default: break;
case reply_help: print_help (); break;
case reply_report: print_resources (); break;
case reply_status: print_statistics (); break;
case reply_build: build_construction (); break;
default: break;
}
}
build_construction (granary);
print_constructions ();
separate ();