Double-Jeopardy works in questions
This commit is contained in:
parent
15e18fb270
commit
324423371f
18
game.py
18
game.py
|
@ -151,13 +151,13 @@ class SeopardyGame(QtGui.QWidget):
|
|||
wasAnswered = (answers is not None and answers.is_answered())
|
||||
|
||||
question = self.questions.get_question(section, number)
|
||||
dj = None
|
||||
if not wasAnswered and question["Double-Jeopardy"]:
|
||||
print("maunz")
|
||||
|
||||
dwin = DoubleJeopardyWindow(self.players, number*100, self.currentPlayer, parent=self)
|
||||
dwin.exec_()
|
||||
dj = (dwin.get_player(), dwin.get_chosen_points())
|
||||
|
||||
qwin = QuestionWindow(self.players, section, number, question, answers, self)
|
||||
qwin = QuestionWindow(self.players, section, number, question, answers, dj, self)
|
||||
qwin.showFullScreen()
|
||||
qwin.exec_()
|
||||
|
||||
|
@ -177,13 +177,21 @@ class SeopardyGame(QtGui.QWidget):
|
|||
self._restyle_button(section, number, answers)
|
||||
|
||||
def _set_player_points(self, answers, rollback=False):
|
||||
for player, correct in answers.get_tries():
|
||||
for i, (player, correct) in enumerate(answers.get_tries()):
|
||||
prefix = 1
|
||||
if rollback:
|
||||
prefix *= -1
|
||||
if not correct:
|
||||
prefix *= -1
|
||||
player.add_points(answers.points()*prefix)
|
||||
|
||||
points = 0
|
||||
print(i, answers.get_dj_points())
|
||||
if i == 0 and answers.get_dj_points() is not None:
|
||||
points = answers.get_dj_points()
|
||||
else:
|
||||
points = answers.points()
|
||||
|
||||
player.add_points(prefix*points)
|
||||
|
||||
def _restyle_button(self, sec, qno, answers):
|
||||
|
||||
|
|
|
@ -38,13 +38,17 @@ class GameState(object):
|
|||
pass
|
||||
|
||||
class QuestionAnswers(object):
|
||||
def __init__(self, section, qnumber):
|
||||
def __init__(self, section, qnumber, dj_points=None):
|
||||
self.section = section
|
||||
self.qnumber = qnumber
|
||||
self.nobody_answered = False
|
||||
self.dj_points = dj_points
|
||||
|
||||
self.tries = []
|
||||
|
||||
def set_dj_points(self, points):
|
||||
self.dj_points = points
|
||||
|
||||
def add_try(self, player, correct):
|
||||
self.tries.append((player, correct))
|
||||
|
||||
|
@ -57,6 +61,9 @@ class QuestionAnswers(object):
|
|||
def points(self):
|
||||
return self.qnumber*100
|
||||
|
||||
def get_dj_points(self):
|
||||
return self.dj_points
|
||||
|
||||
def nobody_knew(self):
|
||||
self.nobody_answered = True
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ from gamestate import QuestionAnswers
|
|||
from player import Player, ButtonEvent, nobodyColor
|
||||
|
||||
class QuestionWindow(QtGui.QDialog):
|
||||
def __init__(self, players, section, qnumber, question, answers=None, parent=None):
|
||||
def __init__(self, players, section, qnumber, question, answers=None, dj=None, parent=None):
|
||||
super(QuestionWindow, self).__init__(parent)
|
||||
|
||||
self.players = players
|
||||
|
@ -18,6 +18,12 @@ class QuestionWindow(QtGui.QDialog):
|
|||
else:
|
||||
self.answers = QuestionAnswers(self.section, self.qnumber)
|
||||
|
||||
self.dj = dj
|
||||
if self.dj and not self.answers.is_answered():
|
||||
self.answers.set_dj_points(self.dj[1])
|
||||
playerNo = self.players.index(self.dj[0])+1
|
||||
QtCore.QCoreApplication.postEvent(self, ButtonEvent(playerNo))
|
||||
|
||||
self._setupGui()
|
||||
self.setWindowTitle("Seopardy - %s - %d" % (section, qnumber*100))
|
||||
self._inWindow = False
|
||||
|
|
Loading…
Reference in New Issue