Permalink
Browse files

Merge branch 'master' of https://github.com/elegion/setwith.me

  • Loading branch information...
2 parents 0af71d2 + 8f28793 commit e146b3bba36b0ade9a7d00e34f5a85bfd6f1c51a @alarin alarin committed Jul 31, 2011
Showing with 28 additions and 2 deletions.
  1. +13 −1 setwithme/apps/game/constants.py
  2. +14 −0 setwithme/apps/game/models.py
  3. +1 −1 setwithme/apps/game/views.py
@@ -30,7 +30,19 @@
CARDS_ON_DESK = getattr(
settings,
"CARDS_ON_DESK",
- 16)
+ 12)
+
+MAX_ADDITIONAL_CARDS = getattr(
+ settings,
+ "MAX_ADDITIONAL_CARDS",
+ 3
+)
+
+CARD_ADD_INTERVAL = getattr(
+ settings,
+ "CARD_ADD_INTERVAL",
+ 60
+)
CANCEL_SET_CHECK = getattr(
settings,
@@ -95,6 +95,20 @@ def pop_cards(self, quantity=3):
self.desk_cards_list = dcl
return res
+ @property
+ def cards_to_pop(self):
+ cards_to_pop = constants.CARDS_ON_DESK
+ now = datetime.datetime.now()
+ gss = self.gamesession_set
+ time_since_start = now - self.start
+ if len(gss.all()) == gss.filter(set_pressed_dt__isnull=True).count()\
+ and now - self.start > datetime.timedelta(seconds=constants.CARD_ADD_INTERVAL):
+ cards_to_pop += min(
+ constants.MAX_ADDITIONAL_CARDS,
+ int(time_since_start.seconds / float(constants.CARD_ADD_INTERVAL))
+ )
+ return cards_to_pop
+
def has_sets(self):
#FIXME: cache that and update on cards removal
cards = sorted(self.desk_cards_list)
@@ -72,7 +72,7 @@ def get_status(request, game_id):
users = [gs.serialize(request.user.id) for gs in \
game.gamesession_set.all()]
desc_cards = game.desk_cards_list
- desc_cards.extend(game.pop_cards(quantity=constants.CARDS_ON_DESK - len(desc_cards)))
+ desc_cards.extend(game.pop_cards(quantity=game.cards_to_pop - len(desc_cards)))
rem_cards_cnt = len(game.rem_cards_list)
return {'users': users,
'cards': [{'id': card_id,

0 comments on commit e146b3b

Please sign in to comment.