I’m extending my checkers game engine (built in Ruby) to the web using Sinatra.
I need to get two clicks (to and from squares) to construct a complete move and send back a correct board state. I have already got it to render squares, each looks like:
<td id=<%= "A3" class= "open-square"><a href="/gameplay/A3></a></td>
if empty and
<td id=<%= "A3" class= "open-square"><a href="/gameplay/A3><img checker></a></td>
if occupied (I’ve stripped out the ERB cause its irrelevant here)
I have a route that looks like this:
get '/gameplay/:location' do
erb :gameplay
end
It does a fine job of capturing individual clicks, but I need two. I got a great suggestion from Tom Anderson:
Checkers is 64 squares, each square in one of three states, so –
without using cookies – you can use javascript on the browser to
create your state – 64 characters that are like ‘br_bb___…’ for
black, red and blank, then send that 64 char string along with the
clicked square. The server then sends back a new state, which the
local js uses to display the squares.
But I think this would only work if I could get a complete move from one click, which I can’t. I’m new to this stuff, obviously naive, whatever advice you may have is appreciated.
I didn’t end up using JQuery to register the clicks. I basically created a querystring to register the locations of the clicks and used server-side programming to determine when to execute a move.