summaryrefslogtreecommitdiff
path: root/backend/src
diff options
context:
space:
mode:
authorphyscik <mynameisgennadiy@vk.com>2026-04-13 17:38:19 +0500
committerphyscik <mynameisgennadiy@vk.com>2026-04-13 17:38:19 +0500
commit6e83c903d2a63dd80b6eb7c4d9f363f7f164f210 (patch)
tree186c4c2886cc8d191ddd48613a0ce823430625de /backend/src
parentabf7e6ffd80ac6958d136d1be348afee8b094da6 (diff)
backend start
Diffstat (limited to 'backend/src')
-rw-r--r--backend/src/Models/RangedWeapon.zig48
-rw-r--r--backend/src/main.zig32
-rw-r--r--backend/src/root.zig23
-rw-r--r--backend/src/tests.zig7
4 files changed, 110 insertions, 0 deletions
diff --git a/backend/src/Models/RangedWeapon.zig b/backend/src/Models/RangedWeapon.zig
new file mode 100644
index 0000000..7ec1f01
--- /dev/null
+++ b/backend/src/Models/RangedWeapon.zig
@@ -0,0 +1,48 @@
+const std = @import("std");
+
+pub const RangedWeaponType = struct {
+ WeaponType: []const u8,
+ Accuracy: i8,
+ Concealability: []const u8,
+ Avaliability: []const u8,
+ Damage: []const u8,
+ Ammunition: []const u8,
+ NumberOfShots: u8,
+ RateOfFire: u8,
+ Reliability: []const u8,
+
+ pub fn GetCompactNotation(self: *RangedWeaponType, separator: u8) ![]const u8 {
+ var b: [64]u8 = undefined;
+ return try std.fmt.bufPrint(&b,
+ "{s}{c}{d}{c}{s}{c}{s}{c}{s}({s}){c}{d}{c}{d}{c}{s}",
+ .{
+ self.WeaponType, separator,
+ self.Accuracy, separator,
+ self.Concealability, separator,
+ self.Avaliability, separator,
+ self.Damage,
+ self.Ammunition, separator,
+ self.NumberOfShots, separator,
+ self.RateOfFire, separator,
+ self.Reliability,
+ });
+ }
+};
+
+test "CompactNotation" {
+ var testType: RangedWeaponType = .{
+ .WeaponType = "P",
+ .Accuracy = -1,
+ .Concealability = "P",
+ .Avaliability = "E",
+ .Damage = "1D6",
+ .Ammunition = "5mm",
+ .NumberOfShots = 8,
+ .RateOfFire = 2,
+ .Reliability = "ST"
+ };
+
+ try std.testing.expectEqualStrings(
+ "P/-1/P/E/1D6(5mm)/8/2/ST",
+ try testType.GetCompactNotation('/'));
+}
diff --git a/backend/src/main.zig b/backend/src/main.zig
new file mode 100644
index 0000000..d2f9a1f
--- /dev/null
+++ b/backend/src/main.zig
@@ -0,0 +1,32 @@
+const std = @import("std");
+const backend = @import("backend");
+const httpz = @import("httpz");
+const tests = @import("tests.zig");
+
+pub fn main() !void {
+ var gpa = std.heap.GeneralPurposeAllocator(.{}){};
+ const allocator = gpa.allocator();
+
+ var server = try httpz.Server(void).init(allocator, .{
+ .address = .all(6969),
+ }, {});
+
+ defer {
+ server.stop();
+ server.deinit();
+ }
+
+ var router = try server.router(.{});
+ router.get("/", index, .{});
+
+ try server.listen();
+}
+
+fn index(_: *httpz.Request, res: *httpz.Response) !void {
+ res.status = 200;
+ try res.json(.{.status = "OK"}, .{});
+}
+
+test "TestRunner" {
+ std.testing.refAllDecls(@This());
+}
diff --git a/backend/src/root.zig b/backend/src/root.zig
new file mode 100644
index 0000000..94c7cd0
--- /dev/null
+++ b/backend/src/root.zig
@@ -0,0 +1,23 @@
+//! By convention, root.zig is the root source file when making a library.
+const std = @import("std");
+
+pub fn bufferedPrint() !void {
+ // Stdout is for the actual output of your application, for example if you
+ // are implementing gzip, then only the compressed bytes should be sent to
+ // stdout, not any debugging messages.
+ var stdout_buffer: [1024]u8 = undefined;
+ var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
+ const stdout = &stdout_writer.interface;
+
+ try stdout.print("Run `zig build test` to run the tests.\n", .{});
+
+ try stdout.flush(); // Don't forget to flush!
+}
+
+pub fn add(a: i32, b: i32) i32 {
+ return a + b;
+}
+
+test "basic add functionality" {
+ try std.testing.expect(add(3, 7) == 10);
+}
diff --git a/backend/src/tests.zig b/backend/src/tests.zig
new file mode 100644
index 0000000..3c09b99
--- /dev/null
+++ b/backend/src/tests.zig
@@ -0,0 +1,7 @@
+const std = @import("std");
+const ranged = @import("Models/RangedWeapon.zig");
+
+
+test "Runner" {
+ std.testing.refAllDecls(@This());
+}