comparison frontends/src/quick_frontend/quick_app.py @ 362:208107419b17

Quiz game: buzzer, timer, answer management
author Goffi <goffi@goffi.org>
date Sun, 12 Jun 2011 22:34:15 +0200
parents 141eeb7cd9e6
children 0806a65a5fa9
comparison
equal deleted inserted replaced
361:141eeb7cd9e6 362:208107419b17
64 self.bridge.register("tarotGameCardsPlayed", self.tarotCardsPlayed) 64 self.bridge.register("tarotGameCardsPlayed", self.tarotCardsPlayed)
65 self.bridge.register("tarotGameInvalidCards", self.tarotInvalidCards) 65 self.bridge.register("tarotGameInvalidCards", self.tarotInvalidCards)
66 self.bridge.register("quizGameStarted", self.quizGameStarted) 66 self.bridge.register("quizGameStarted", self.quizGameStarted)
67 self.bridge.register("quizGameNew", self.quizGameNew) 67 self.bridge.register("quizGameNew", self.quizGameNew)
68 self.bridge.register("quizGameQuestion", self.quizGameQuestion) 68 self.bridge.register("quizGameQuestion", self.quizGameQuestion)
69 self.bridge.register("quizGamePlayerBuzzed", self.quizGamePlayerBuzzed)
70 self.bridge.register("quizGamePlayerSays", self.quizGamePlayerSays)
71 self.bridge.register("quizGameAnswerResult", self.quizGameAnswerResult)
72 self.bridge.register("quizGameTimerExpired", self.quizGameTimerExpired)
73 self.bridge.register("quizGameTimerRestarted", self.quizGameTimerRestarted)
69 self.bridge.register("subscribe", self.subscribe) 74 self.bridge.register("subscribe", self.subscribe)
70 self.bridge.register("paramUpdate", self.paramUpdate) 75 self.bridge.register("paramUpdate", self.paramUpdate)
71 self.bridge.register("contactDeleted", self.contactDeleted) 76 self.bridge.register("contactDeleted", self.contactDeleted)
72 self.bridge.register("updatedValue", self.updatedValue, "request") 77 self.bridge.register("updatedValue", self.updatedValue, "request")
73 self.bridge.register("askConfirmation", self.askConfirmation, "request") 78 self.bridge.register("askConfirmation", self.askConfirmation, "request")
375 if self.chat_wins.has_key(room_jid): 380 if self.chat_wins.has_key(room_jid):
376 self.chat_wins[room_jid].getGame("Tarot").invalidCards(phase, played_cards, invalid_cards) 381 self.chat_wins[room_jid].getGame("Tarot").invalidCards(phase, played_cards, invalid_cards)
377 382
378 def quizGameStarted(self, room_jid, referee, players, profile): 383 def quizGameStarted(self, room_jid, referee, players, profile):
379 if not self.check_profile(profile): 384 if not self.check_profile(profile):
380 print "gof: NOT CHECK PROFILE", profile
381 return 385 return
382 debug (_("Quiz Game Started \o/")) 386 debug (_("Quiz Game Started \o/"))
383 if self.chat_wins.has_key(room_jid): 387 if self.chat_wins.has_key(room_jid):
384 self.chat_wins[room_jid].startGame("Quiz", referee, players) 388 self.chat_wins[room_jid].startGame("Quiz", referee, players)
385 debug (_("new Quiz game started by [%(referee)s] in room [%(room_jid)s] with %(players)s") % {'referee':referee, 'room_jid':room_jid, 'players':[str(player) for player in players]}) 389 debug (_("new Quiz game started by [%(referee)s] in room [%(room_jid)s] with %(players)s") % {'referee':referee, 'room_jid':room_jid, 'players':[str(player) for player in players]})
396 if not self.check_profile(profile): 400 if not self.check_profile(profile):
397 return 401 return
398 debug (_(u"Quiz: new question: %s") % question) 402 debug (_(u"Quiz: new question: %s") % question)
399 if self.chat_wins.has_key(room_jid): 403 if self.chat_wins.has_key(room_jid):
400 self.chat_wins[room_jid].getGame("Quiz").quizGameQuestion(question_id, question, timer) 404 self.chat_wins[room_jid].getGame("Quiz").quizGameQuestion(question_id, question, timer)
405
406 def quizGamePlayerBuzzed(self, room_jid, player, pause, profile):
407 """Called when a player pushed the buzzer"""
408 if not self.check_profile(profile):
409 return
410 if self.chat_wins.has_key(room_jid):
411 self.chat_wins[room_jid].getGame("Quiz").quizGamePlayerBuzzed(player, pause)
412
413 def quizGamePlayerSays(self, room_jid, player, text, delay, profile):
414 """Called when a player say something"""
415 if not self.check_profile(profile):
416 return
417 if self.chat_wins.has_key(room_jid):
418 self.chat_wins[room_jid].getGame("Quiz").quizGamePlayerSays(player, text, delay)
419
420 def quizGameAnswerResult(self, room_jid, player, good_answer, score, profile):
421 """Called when a player say something"""
422 if not self.check_profile(profile):
423 return
424 if self.chat_wins.has_key(room_jid):
425 self.chat_wins[room_jid].getGame("Quiz").quizGameAnswerResult(player, good_answer, score)
426
427 def quizGameTimerExpired(self, room_jid, profile):
428 """Called when nobody answered the question in time"""
429 if not self.check_profile(profile):
430 return
431 if self.chat_wins.has_key(room_jid):
432 self.chat_wins[room_jid].getGame("Quiz").quizGameTimerExpired()
433
434 def quizGameTimerRestarted(self, room_jid, time_left, profile):
435 """Called when the question is not answered, and we still have time"""
436 if not self.check_profile(profile):
437 return
438 if self.chat_wins.has_key(room_jid):
439 self.chat_wins[room_jid].getGame("Quiz").quizGameTimerRestarted(time_left)
401 440
402 def _subscribe_cb(self, answer, data): 441 def _subscribe_cb(self, answer, data):
403 entity, profile = data 442 entity, profile = data
404 if answer: 443 if answer:
405 self.bridge.subscription("subscribed", entity.short, profile_key = profile) 444 self.bridge.subscription("subscribed", entity.short, profile_key = profile)