i am writing a porker game in typescript.
and i create a GameLogic class which have some methods to handle game flow.
eg. sendCards, shuffleCards …etc.
and also have some property eg, cards, currentPlayer …etc.
so i save this GameLogic instance in the match state like this.
state={
gameLogic: new GameLogic()
}
and access it in whole match lifecycle handles
however, it is not support, it looks the state object must be a simple object that can be serialized by JSON。
so what can i do, the GameLogic class is copied from my old project that use socket.js. i perfer to use it directly, otherthan hardcore translate and inject into match handles.
or can i just save the GameLogic as a constant on the top of all handles, but i wonder how the handlers work. is it seperated by each match? what i want is one match with one GameLogic instance to manage.
thanks for reply.
yes, that’s what i did so far too.
i made my GameLogic class be stateless too, and re-create it in each match handler hooks, and serialize it into plain object and store in state.
i also defined a tick method in gameLogic, and in each loop hooks, it would be called.
so far it looks fine, however, i have no idea about how to log out some debug infomation. as the console.log can not be used, and i try to set the logger object form the paramater of match handler to gameLogic, however it is not work too.
do u have any bette idea to print out logs in gameLogic ?