DEV Community

Cover image for Rethinking Gameboards

Rethinking Gameboards

Toby Parent on October 04, 2021

The Plan This is an evolution of an idea. At first, I wanted to see if it would be possible to use grid-areas to set up a minimalist che...
Collapse
 
grahamthedev profile image
GrahamTheDev • Edited

Why didn't you name the areas A1 to H8 - that way it becomes exactly like chess and makes it even easier to implement moves according to normal chess rules (B2 to B4) etc.

Anyway that is only a minor point, this is a great way to do it using grid! ❤

Collapse
 
parenttobias profile image
Toby Parent

Done and done. Easier change than I'd expected - update the CSS grid-template-areas, then update the class to calculate the clicked grid-area (using Math.ceil() rather than Math.floor()), and working fine.

Thank you again!

Collapse
 
parenttobias profile image
Toby Parent

I had actually realized this yesterday, I'm working on this very thing. It's a great point, and thanks to the flexibility of grid-template-area, easily implemented.

Thanks for the feedback!

Collapse
 
marvinbrouwer profile image
Marvin Brouwer

I guess this also has support for CSS animations perhaps?

Collapse
 
parenttobias profile image
Toby Parent

I was working on that, and not as easy as I'd first thought. I can't figure if transitions are available from one grid-area to another, as that's not necessarily a numeric (quantitative) transform. But I might find a workaround, if I do I'll mention it here.

Collapse
 
mattcale profile image
Matthew Cale

I had the same thought and see no reason it wouldn’t be able to achieve pretty cool animations with very little overhead.

Collapse
 
parenttobias profile image
Toby Parent

So I had put this aside for a long while, moved on to other ideas and projects, but recently working through the logic of the Knight's Travels problems, and the fact that this was still in issue bugged the crap out of me. So I did a little digging, and found github.com/aholachek/animate-css-grid - which very cleanly, easily handles the animation between grid-areas!

The nice thing about it is, I can remove the static CSS initial values, and it was a seamless, modular update. The replit is using the animation, check it out!

Collapse
 
fanweixiao profile image
C.C.

Cool

Collapse
 
parenttobias profile image
Toby Parent

Glad you like it! The fun bit comes with the javascript, to my mind. Though when I get there, I find I'm already rethinking some of the Piece factory functionality. Never satisfied, me.

Collapse
 
mattcale profile image
Matthew Cale

Very clearly thought out. Love the design.

Collapse
 
parenttobias profile image
Toby Parent

It was an evolution, like I said. I first just wanted to see if the grid thing works. Then Eric Elliot's book really got me thinking and wanting to do more with functional, composed objects, and it grew from there.

It is still in a state of flux, I can see a few improvements I'd like to make - I'll likely continue this series with those improvements. :D