Browse Source

Double-Jeopardy works in questions

Sebastian Lohff 6 years ago
parent
commit
324423371f
3 changed files with 28 additions and 7 deletions
  1. 13
    5
      game.py
  2. 8
    1
      gamestate.py
  3. 7
    1
      windows.py

+ 13
- 5
game.py View File

@@ -151,13 +151,13 @@ class SeopardyGame(QtGui.QWidget):
151 151
 		wasAnswered = (answers is not None and answers.is_answered())
152 152
 
153 153
 		question = self.questions.get_question(section, number)
154
+		dj = None
154 155
 		if not wasAnswered and question["Double-Jeopardy"]:
155
-			print("maunz")
156
-
157 156
 			dwin = DoubleJeopardyWindow(self.players, number*100, self.currentPlayer, parent=self)
158 157
 			dwin.exec_()
158
+			dj = (dwin.get_player(), dwin.get_chosen_points())
159 159
 
160
-		qwin = QuestionWindow(self.players, section, number, question, answers, self)
160
+		qwin = QuestionWindow(self.players, section, number, question, answers, dj, self)
161 161
 		qwin.showFullScreen()
162 162
 		qwin.exec_()
163 163
 
@@ -177,13 +177,21 @@ class SeopardyGame(QtGui.QWidget):
177 177
 		self._restyle_button(section, number, answers)
178 178
 
179 179
 	def _set_player_points(self, answers, rollback=False):
180
-		for player, correct in answers.get_tries():
180
+		for i, (player, correct) in enumerate(answers.get_tries()):
181 181
 			prefix = 1
182 182
 			if rollback:
183 183
 				prefix *= -1
184 184
 			if not correct:
185 185
 				prefix *= -1
186
-			player.add_points(answers.points()*prefix)
186
+
187
+			points = 0
188
+			print(i, answers.get_dj_points())
189
+			if i == 0 and answers.get_dj_points() is not None:
190
+				points = answers.get_dj_points()
191
+			else:
192
+				points = answers.points()
193
+
194
+			player.add_points(prefix*points)
187 195
 
188 196
 	def _restyle_button(self, sec, qno, answers):
189 197
 

+ 8
- 1
gamestate.py View File

@@ -38,13 +38,17 @@ class GameState(object):
38 38
 		pass
39 39
 
40 40
 class QuestionAnswers(object):
41
-	def __init__(self, section, qnumber):
41
+	def __init__(self, section, qnumber, dj_points=None):
42 42
 		self.section = section
43 43
 		self.qnumber = qnumber
44 44
 		self.nobody_answered = False
45
+		self.dj_points = dj_points
45 46
 
46 47
 		self.tries = []
47 48
 
49
+	def set_dj_points(self, points):
50
+		self.dj_points = points
51
+
48 52
 	def add_try(self, player, correct):
49 53
 		self.tries.append((player, correct))
50 54
 
@@ -57,6 +61,9 @@ class QuestionAnswers(object):
57 61
 	def points(self):
58 62
 		return self.qnumber*100
59 63
 
64
+	def get_dj_points(self):
65
+		return self.dj_points
66
+
60 67
 	def nobody_knew(self):
61 68
 		self.nobody_answered = True
62 69
 

+ 7
- 1
windows.py View File

@@ -6,7 +6,7 @@ from gamestate import QuestionAnswers
6 6
 from player import Player, ButtonEvent, nobodyColor
7 7
 
8 8
 class QuestionWindow(QtGui.QDialog):
9
-	def __init__(self, players, section, qnumber, question, answers=None, parent=None):
9
+	def __init__(self, players, section, qnumber, question, answers=None, dj=None, parent=None):
10 10
 		super(QuestionWindow, self).__init__(parent)
11 11
 
12 12
 		self.players = players
@@ -18,6 +18,12 @@ class QuestionWindow(QtGui.QDialog):
18 18
 		else:
19 19
 			self.answers = QuestionAnswers(self.section, self.qnumber)
20 20
 
21
+		self.dj = dj
22
+		if self.dj and not self.answers.is_answered():
23
+			self.answers.set_dj_points(self.dj[1])
24
+			playerNo = self.players.index(self.dj[0])+1
25
+			QtCore.QCoreApplication.postEvent(self, ButtonEvent(playerNo))
26
+
21 27
 		self._setupGui()
22 28
 		self.setWindowTitle("Seopardy - %s - %d" % (section, qnumber*100))
23 29
 		self._inWindow = False

Loading…
Cancel
Save