Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit e146b3bba36b0ade9a7d00e34f5a85bfd6f1c51a 2 parents 0af71d2 + 8f28793
@alarin alarin authored
View
14 setwithme/apps/game/constants.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,
View
14 setwithme/apps/game/models.py
@@ -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)
View
2  setwithme/apps/game/views.py
@@ -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,
Please sign in to comment.
Something went wrong with that request. Please try again.