Game rounds, swapping templates and preserving data


#1

I’m building a multiplayer game that includes rounds. Players are given options to choose and after each finishes picking, the template changes to a voting template. This template shows each players individual choice (option). Players vote for their favorite and then a scoreboard template renders, showing each vote and calculating scores based on vote count. So 3 templates in all - gameplay, voting, scores.

What’s the best way to swap out templates after choices/votes and also preserve the scores? I’ve been using sessions and if statements in the template so when a choice is made a session is changed as well as the template, but this only works client side so player templates aren’t synced up.

From my research it seems like there are many ways to go about doing this - using Iron Router’s route controllers and hooks, template.dynamic, reactive var and dict, - so I’m looking to be pointed in the right direction (best practice?). Maybe put all info in my game collection, update accordingly and use tracker to render templates somehow?


#2

You should probably have a Games or Rounds collection.

Then only store the user’s current game or round ID in session. You can tack timers,hooks,cron jobs etc. onto a collection that will be able to manage the game. This way your state is somewhat easier to keep syncronised and managed. Please don’t store too much in Session variables. Think of them more as cookies.

A router does sound like a good idea yes but if the URL is too obvious players might be able to cheat. So re-rendering a template into a container might work out better

It sounds like you are trying to make you’re own jackbox.tv style games. Which would be fantastic. Please keep us supplied with updates on how it goes!