Page 1 of 1

Updating gamedatas

Posted: 13 May 2016, 13:21
by locerol
Hi all,

I am trying to develop a game of token movement on a board. At one moment, I am checking possible movements on the client side, beacuse everytime the player selects a token, I want to show the possible moves that tokes has, without changing the state of the game. Each player has 8 tokens at the beggining, so they may select several of them to see their possible movements before deciding the actual movement to make.

How can I update the value of this.gamedatas where the board state is stored? On the "yourgamename.js" explanation it says:
"this.gamedatas
Contains your initial set of datas to init the game, created at game start or game refresh (F5)
You can update it as needed to keep an up to date reference of the game on the client side if you need it (most of the time you don't). "

But it does not say how.

I am also wondering if I should be doing the checking of possible moves on the server side, but is it possible to do it without changing the state of the game?

Thanks in advance for your help.

Re: Updating gamedatas

Posted: 13 May 2016, 23:02
by pikiou
this.gamedatas is just an object. Modifying it won't have an impact on the DOM, it's just there for you to keep track of the state of your board and pieces. Actually, if you develop your game as a thin client application, you won't even need this.gamedatas because there is no point of keeping track of your board. I know I didn't for my past 6 games and it made my life easier ^^

To show the possible moves, the best way is to pre-compute all the token moves and send them as a state argument. Try to make it lightweight so the whole thing doesn't go beyond more or less 128k once it's JSON.stringified.

Re: Updating gamedatas

Posted: 15 May 2016, 21:31
by locerol
Thank you pikiou for your help. I am going to change the structure of the game to calculate the possible moves on the server and send them as a state argument, as you suggested.