|
|
|
@ -13,9 +13,11 @@ class SeopardyGame(QtGui.QWidget):
|
|
|
|
|
self.questions = questions
|
|
|
|
|
self.gamestate = gamestate
|
|
|
|
|
#self.players = [Player.gen_player(i, parent=self) for i in range(1, 4)]
|
|
|
|
|
self.players = []
|
|
|
|
|
for i in range(3):
|
|
|
|
|
self.add_player()
|
|
|
|
|
self.players = self.gamestate.get_players()
|
|
|
|
|
if len(self.players) == 0:
|
|
|
|
|
for i in range(3):
|
|
|
|
|
self.add_player()
|
|
|
|
|
|
|
|
|
|
self.currentPlayer = None
|
|
|
|
|
|
|
|
|
|
self._inOtherWindow = False
|
|
|
|
@ -23,7 +25,8 @@ class SeopardyGame(QtGui.QWidget):
|
|
|
|
|
self.showFullScreen()
|
|
|
|
|
|
|
|
|
|
# initiate starting the game!
|
|
|
|
|
QtCore.QCoreApplication.postEvent(self, GameStartEvent())
|
|
|
|
|
if self.gamestate.get_state() == "start":
|
|
|
|
|
QtCore.QCoreApplication.postEvent(self, GameStartEvent())
|
|
|
|
|
|
|
|
|
|
def add_player(self):
|
|
|
|
|
self.players.append(Player.gen_player(len(self.players)+1, self))
|
|
|
|
@ -40,22 +43,22 @@ class SeopardyGame(QtGui.QWidget):
|
|
|
|
|
|
|
|
|
|
# create board
|
|
|
|
|
#board = QtGui.QGridLayout(6, len(self.questions.get_sections()))
|
|
|
|
|
board = QtGui.QGridLayout()
|
|
|
|
|
board.setSizeConstraint(QtGui.QLayout.SetMaximumSize)
|
|
|
|
|
self.board = QtGui.QGridLayout()
|
|
|
|
|
self.board.setSizeConstraint(QtGui.QLayout.SetMaximumSize)
|
|
|
|
|
for i, sec in enumerate(self.questions.get_sections()):
|
|
|
|
|
seclabel = QtGui.QLabel(sec, alignment=QtCore.Qt.AlignCenter)
|
|
|
|
|
seclabel.setStyleSheet("QLabel { font-size: 30px; }")
|
|
|
|
|
board.addWidget(seclabel, 0, i)
|
|
|
|
|
self.board.addWidget(seclabel, 0, i)
|
|
|
|
|
for j in range(5):
|
|
|
|
|
b = QtGui.QPushButton(str((j+1)*100))
|
|
|
|
|
b.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
|
|
|
|
|
b.setAutoDefault(False)
|
|
|
|
|
b.setStyleSheet("QPushButton { font-size: 60px; }")
|
|
|
|
|
#b.setStyleSheet("QPushButton { font-size: 60px; }")
|
|
|
|
|
b.installEventFilter(FocusKeyGrabber(i+1, j+1, self))
|
|
|
|
|
b.clicked.connect(lambda sec=sec, j=j: self.go_to_question(sec, j+1))
|
|
|
|
|
board.addWidget(b, j+1, i)
|
|
|
|
|
layout.addLayout(board)
|
|
|
|
|
self.board = board
|
|
|
|
|
self.board.addWidget(b, j+1, i)
|
|
|
|
|
self._restyle_button(sec, j+1, self.gamestate.get_answers(sec, j+1))
|
|
|
|
|
layout.addLayout(self.board)
|
|
|
|
|
|
|
|
|
|
# create player bar
|
|
|
|
|
self.playerBar = QtGui.QHBoxLayout()
|
|
|
|
@ -81,6 +84,8 @@ class SeopardyGame(QtGui.QWidget):
|
|
|
|
|
x = PlayerStartWindow(self.players, self)
|
|
|
|
|
x.exec_()
|
|
|
|
|
self._inOtherWindow = False
|
|
|
|
|
self.gamestate.set_state("playing")
|
|
|
|
|
self.gamestate.save()
|
|
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
@ -136,6 +141,7 @@ class SeopardyGame(QtGui.QWidget):
|
|
|
|
|
self._set_player_points(newAnswers)
|
|
|
|
|
self.gamestate.set_answers(section, number, newAnswers)
|
|
|
|
|
self._restyle_button(section, number, newAnswers)
|
|
|
|
|
self.gamestate.save()
|
|
|
|
|
|
|
|
|
|
def show_victory_window(self):
|
|
|
|
|
self._inOtherWindow = True
|
|
|
|
@ -176,6 +182,23 @@ class SeopardyGame(QtGui.QWidget):
|
|
|
|
|
# restyle the button
|
|
|
|
|
self._restyle_button(section, number, answers)
|
|
|
|
|
|
|
|
|
|
# safe current gamestate
|
|
|
|
|
self.gamestate.save()
|
|
|
|
|
|
|
|
|
|
# check if we are done
|
|
|
|
|
foundUnanswered = False
|
|
|
|
|
for sec in self.questions.get_sections():
|
|
|
|
|
for j in range(5):
|
|
|
|
|
boardAnswers = self.gamestate.get_answers(sec, j+1)
|
|
|
|
|
if boardAnswers is None or not answers.is_answered():
|
|
|
|
|
foundUnanswered = True
|
|
|
|
|
if foundUnanswered:
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
if not foundUnanswered:
|
|
|
|
|
self.show_victory_window()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _set_player_points(self, answers, rollback=False):
|
|
|
|
|
for i, (player, correct) in enumerate(answers.get_tries()):
|
|
|
|
|
prefix = 1
|
|
|
|
@ -199,8 +222,8 @@ class SeopardyGame(QtGui.QWidget):
|
|
|
|
|
btnstr = ""
|
|
|
|
|
btncolor = None
|
|
|
|
|
|
|
|
|
|
if not answers.is_answered():
|
|
|
|
|
btn.setText(str(answers.points()))
|
|
|
|
|
if answers is None or not answers.is_answered():
|
|
|
|
|
btn.setText(str(qno*100))
|
|
|
|
|
btn.setStyleSheet("QPushButton { font-size: 60px; }")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|