--- /dev/null
+/*
+ * TDef: small reader defense game
+ *
+ * Copyright (C) 2025 Niki Roo
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "cutils/cstring.h"
+#include "reader.h"
+
+
+command read_command(FILE *file) {
+ static cstring_t *line = NULL;
+
+ if (!line)
+ line = new_cstring();
+
+ if (cstring_readline(line, file)) {
+ if (!strcmp(".", line->string)) {
+ return TICK;
+ } else if (!strcmp("=", line->string)) {
+ return DISPLAY;
+ } else {
+ return UNKNOWN;
+ }
+ }
+
+ return QUIT;
+}
+
#include "any.h"
#include "map.h"
#include "engine.h"
+#include "reader.h"
void display(map_t *self) {
printf("==========\n\n");
engine_t *engine = new_engine(map);
printf("Paths: %d\n", map->paths->count);
- for (int i = 0 ; i < 11 ; i++) {
- printf("Tick is: %d\n", engine->current_tick);
- engine_tick(engine);
- display(map);
+
+ command cmd = read_command(stdin);
+ while (cmd != QUIT) {
+ switch(cmd) {
+ case TICK:
+ printf("Tick is: %d\n", engine->current_tick);
+ engine_tick(engine);
+ break;
+ case DISPLAY:
+ display(map);
+ break;
+ case UNKNOWN:
+ printf("Unrecognized command\n");
+ break;
+ case QUIT:
+ // cannot happen, but kept for warning purposes
+ break;
+ }
+
+ cmd = read_command(stdin);
}
+
free_engine(engine);
return 0;
}