Implementing input system...
This commit is contained in:
parent
4c7f0ce66a
commit
254a6c46c9
48
xerbia.c
48
xerbia.c
@ -2,6 +2,7 @@
|
||||
|
||||
enum { wheat, gold, wood, stone, resources };
|
||||
enum { granary, mine, storehouse, quarry, constructions };
|
||||
enum { reply_invalid, reply_build, reply_report, reply_status, replies };
|
||||
|
||||
static int population = 0;
|
||||
static int reputation = 0;
|
||||
@ -13,6 +14,7 @@ static int construction [constructions] = { 0 };
|
||||
|
||||
static char * resource_name [] = { "wheat", "gold", "wood", "stone" };
|
||||
static char * construction_name [] = { "granary", "mine", "storehouse", "quarry" };
|
||||
static char * reply_name [] = { "--", "build", "report", "status" };
|
||||
|
||||
static int construction_price [constructions] [resources] = {
|
||||
{ 0, 10, 60, 30 },
|
||||
@ -89,8 +91,36 @@ static void print_statistics (void) {
|
||||
separate ();
|
||||
}
|
||||
|
||||
static int query (void) {
|
||||
char input [1024] = "";
|
||||
|
||||
int index;
|
||||
|
||||
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) {
|
||||
print ("-- /2%s/-\n", reply_name [index]);
|
||||
return (index);
|
||||
}
|
||||
}
|
||||
|
||||
print ("/1Unknown kind of reply, type 'help' to see valid replies./-\n");
|
||||
|
||||
return (reply_invalid);
|
||||
}
|
||||
|
||||
int main (void) {
|
||||
int index;
|
||||
int reply;
|
||||
|
||||
reputation = random (0, 10);
|
||||
monthly_immigration = random (0, 10);
|
||||
@ -105,17 +135,19 @@ int main (void) {
|
||||
construction [index] = random (1, 2);
|
||||
}
|
||||
|
||||
separate ();
|
||||
for (reply = replies; reply != reply_invalid; reply = query ()) {
|
||||
separate ();
|
||||
|
||||
print_resources ();
|
||||
print_constructions ();
|
||||
print_resources ();
|
||||
print_constructions ();
|
||||
|
||||
build_construction (granary);
|
||||
build_construction (mine);
|
||||
build_construction (storehouse);
|
||||
build_construction (quarry);
|
||||
build_construction (granary);
|
||||
build_construction (mine);
|
||||
build_construction (storehouse);
|
||||
build_construction (quarry);
|
||||
|
||||
print_statistics ();
|
||||
print_statistics ();
|
||||
}
|
||||
|
||||
print ("The end!\n");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user