]> git.cworth.org Git - lmno.games/commit
tictactoe: Implement a minimally-functional multi-player game
authorCarl Worth <cworth@cworth.org>
Wed, 27 May 2020 04:13:49 +0000 (21:13 -0700)
committerCarl Worth <cworth@cworth.org>
Wed, 27 May 2020 04:13:49 +0000 (21:13 -0700)
commit9d201384db591cc94d872c4046a2bc67d1c57133
tree86b2b0eed4882dd4d4cc9f603578ba148e3aa9c9
parent673e4f0696496aa8bd6267d06f9f372da735bc70
tictactoe: Implement a minimally-functional multi-player game

Now that there's a server implemented at lmno.games/tictactoe/LMNO/
it's a simple matter to break the call chain at handleClick() to
not do any state updates, but instead hit the /move API, then wait
for data to come back from the /events API and only when the server
returns with that, _then_ to update the state.

So, with multiple clients connected, each client will now seem the
game state updated with each move.

As far as the gameplay of Tic Tac Toe, the only major feature missing
is that players are not yet restricted to play as either X or O but
can instead send events for either player. Obviously, that won't be
hard to fix.

Then, as far as implementation, this code copies the add_message()
function from lmno.js, so we'll want to find a better way to do
that. And there may be some refactoring to be done for event handling
as well, (to reduce code duplication between game implementations).

But this code does use the fetch() API which does seem easier to use
than XMLHttpRequest so that's something we will probably want to
switch to in existing code.
tictactoe/tictactoe.jsx