0

I really dont know if this kind of diffuse question is suited here, but i'll give it a go anyhow.

I'm building a turn-based (Yatzee)game in Django, where i have a rally simple model for the user/player and a bit more complex one for each users scoreboard.

A new game generates a new scoreboard, which basically consists of a number of int-fields and boolean-fields, one for each score (for example, if you get a two-pair, there is a field that will hold the score and a field that will set it as 'assigned')

The thing is that with this approach, where i save the score to the db(sqlite) after each turn, i'll be able to 'pause' a game and continue it later.

What i now would like to start looking into, without really knowing where to start looking is how to 'host' a game, for two or more playsre, over the web. If they're all sitting at the same computer there is no problem, since i can control the number of players/scoreboards through javascript.

To accomplish this, i'm thinking in the terms of assigning the scoreboards that belong 'togheter' to a session somehow, but how and where i'm supposed to do this is kinda out of my scope at the moment.

I've read a bit about the Django middleware, but cant really figure out if that wolud be a better way than trying to solve it from the model-layer (which a belive will be kinda hard..?).

BSG
  • 1,382
  • 4
  • 14
  • 25

2 Answers2

1

One way to accomplish this is to build a javascript framework that polls the backend for player activity. There are a number of player activities to track:

  1. New game
  2. Player leaves the game / timeout
  3. Remote player's turn to roll the dice
  4. Local player's turn to roll the dice

I would recommend have an AJAX function with a timer that polls the server for updates or posts local player activity.

When I say javascript framework, I am referring to a way to handle the automatic polling and updating on the client side.

Note that you cannot rely on the javascript to handle game rules, dice rolling etc. all that has to be done on the server. The javascript should only update the GUI for the player to show the current status.

So you would have AJAX calls for actions like: Start new game, Check remote activity, Roll dice, Save player option (the player chose to save 3* sixes as a pair etc.) and so on.

Mikael
  • 3,148
  • 22
  • 20
  • Also a player should be able to start a session (New game) and other players should be able to search for games where that player is in to be able to join. – Mikael Jun 01 '12 at 09:15
  • Lots of good input, thanks. I'll look in to them asap, AJAX sounds like the way to go tough. I was acctually hoping i colud keep the 'game' part of the game strictly client-side, since it's only the result of the dices that is of interest, how to get the result isn't THAT important, but i could be wrong. – BSG Jun 01 '12 at 11:07
  • Well if the dice logic is on the client side of things, cheating would be possible. A technical player would be able to fake dice rolls and tell your system that a given combination of dices were rolled without any control of it. – Mikael Jun 01 '12 at 11:13
  • Bit out of my leauge i guess, but would it matter if i use csrf, to check if the input-source (to the db) is correct? – BSG Jun 01 '12 at 11:21
  • Nope I don't think so. The csrf could be read on the client and used to fake a call. – Mikael Jun 01 '12 at 11:34
0

I've no idea what middleware has to do with this.

The easiest way would surely be to have foreignkeys from the game model pointing to the auth.User model for Player1 and Player2.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895