sw-battle-test-c

Interesting test task in C instead of C++
git clone git://bsandro.tech/sw-battle-test-c
Log | Files | Refs | README

commit dd49fee77cf0e9109de6b8b9f087a6be14ac1be1
parent c60256ea518d42ca0a2247b3c229becf58efaa1a
Author: bsandro <email@bsandro.tech>
Date:   Fri, 21 Aug 2026 08:41:16 +0300

commands are variadic functions now

Diffstat:
Mcommands/CREATE_MAP.c | 2+-
Mcommands/MARCH.c | 2+-
Mcommands/SPAWN_HUNTER.c | 2+-
Mcommands/SPAWN_SWORDSMAN.c | 2+-
Mcore/command.h | 3++-
Mcore/map.h | 2++
Mcore/world.h | 2++
Mmain.c | 3++-
8 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/commands/CREATE_MAP.c b/commands/CREATE_MAP.c @@ -1,5 +1,5 @@ #include "core/command.h" -void cmd_create_map() { +void cmd_create_map(World *w, ...) { puts("create map"); } diff --git a/commands/MARCH.c b/commands/MARCH.c @@ -1,5 +1,5 @@ #include "core/command.h" -void cmd_march() { +void cmd_march(World *w, ...) { puts("march"); } diff --git a/commands/SPAWN_HUNTER.c b/commands/SPAWN_HUNTER.c @@ -1,5 +1,5 @@ #include "core/command.h" -void cmd_spawn_hunter() { +void cmd_spawn_hunter(World *w, ...) { puts("spawn hunter"); } diff --git a/commands/SPAWN_SWORDSMAN.c b/commands/SPAWN_SWORDSMAN.c @@ -1,5 +1,5 @@ #include "core/command.h" -void cmd_spawn_swordsman() { +void cmd_spawn_swordsman(World *w, ...) { puts("spawn swordsman"); } diff --git a/core/command.h b/core/command.h @@ -1,8 +1,9 @@ #pragma once #include <stdio.h> +#include "core/world.h" -typedef void Command_Func(void); +typedef void Command_Func(World *w, ...); typedef struct Command { const char *name; diff --git a/core/map.h b/core/map.h @@ -1,3 +1,5 @@ +#pragma once + typedef struct Map { int w; int h; diff --git a/core/world.h b/core/world.h @@ -1,3 +1,5 @@ +#pragma once + #include "map.h" typedef struct World { diff --git a/main.c b/main.c @@ -11,10 +11,11 @@ int main(int argc, char **argv) { if (argc>1) { for (int i=0;i<COMMANDS_COUNT;++i) { if (strcmp(COMMANDS[i].name, argv[1])==0) { - COMMANDS[i].func(); + COMMANDS[i].func(&w, "ehlo"); break; } } + puts("unknown command"); } return 0; }