You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+32
Original file line number
Diff line number
Diff line change
@@ -55,6 +55,16 @@ Once logged in, you will see (in real time) who we are waiting on, and watch as
55
55
56
56
Once everyone has logged in, the board is presented, and the game begins !
57
57
58
+
## The Clock / Timer
59
+
60
+
Each phase has a clock timer - usually 30 seconds, which counts down to 0.
61
+
62
+
Each time a player completes their turn, the clock is reset.
63
+
64
+
If the clock ever gets down to 0, the game is terminated, and everyone loses.
65
+
66
+
The reason for this is to allow the game to run on a public server, and not get stuck in some mode where its waiting for a player to do something, and everyone runs, freezing the game forever in that waiting state.
67
+
58
68
## Winning the Game
59
69
60
70
Each player takes a turn, selecting an empty square to place their piece in.
@@ -87,3 +97,25 @@ after someone set us up the bomb.
87
97
This code is interesting for the following reasons :
88
98
89
99
- Its all written in Zig
100
+
- It uses the excellent http.zig library https://github.com/karlseguin/http.zig
101
+
- Note that the router is decorated inside the Game object ... the implications of this are that it is possible to create 'web components' using this
102
+
zig/htmx approach that are all self contained, and can be imported into other projects, without having to know about connecting up routes. Interesting.
103
+
- Uses SSE / Event Streams to keep it all realtime updates with pub/sub from multiple players
104
+
- No websockets needed
105
+
- There is pretty much NO JAVASCRIPT on the frontend. It uses HTMX https://htmx.org ... which is an alternative approach to web clients, where the frontend is pure hypertext, and everything is done on the backend
106
+
- There is a tiny bit of JS, to update the session ID, but im still thinking up a way of getting rid of that as well.
107
+
- Uses std.fmt.print() as the templating engine. I didnt know before, but you can used named tags inside the comptime format string, and use those to reference fields in the args param.
108
+
Actually makes for a half decent templating tool.
109
+
110
+
111
+
## HTMX thoughts
112
+
113
+
Yeah, its pretty cool, worth adding to your toolbelt. Not sure its really a 'replacement' for SPA type apps - I think it might be painful for larger apps. Not sure, havnt tried yet.
114
+
115
+
What it is 100% excellent for though is for doing apps where there is a lot of shared state between users. (Like a turn based game !) In that case, doing everything on the server, and not having any state
116
+
at all on the frontend to sync, is really ideal. Its a good fit to this sort of problem.
117
+
118
+
There are some very complex things you could do with a turn-based-multiplayer-game type of model though (doesnt have to be a game even) And being able to do that without touching JS, or
119
+
writing a tonne of code to synch state on the frontends is really nice.
120
+
121
+
Its also a reasonable model for doing shared state between GUI frontends, just using the HTTP/SSE protocol too.
0 commit comments