Complete DJ-Window + "who's turn is it"

This commit is contained in:
Sebastian Lohff 2013-11-27 01:16:44 +01:00
parent 88fdac4cd2
commit 48a3bd6a93
3 changed files with 82 additions and 22 deletions

11
game.py
View File

@ -3,7 +3,7 @@ from __future__ import print_function
from PySide import QtCore, QtGui
from player import Player, nobodyColor
from windows import QuestionWindow, EditAnswersWindow, PlayerStartWindow, VictoryWindow
from windows import QuestionWindow, EditAnswersWindow, PlayerStartWindow, VictoryWindow, DoubleJeopardyWindow
from gamestate import QuestionAnswers
class SeopardyGame(QtGui.QWidget):
@ -16,6 +16,7 @@ class SeopardyGame(QtGui.QWidget):
self.players = []
for i in range(3):
self.add_player()
self.currentPlayer = None
self._inOtherWindow = False
self._createGui()
@ -150,10 +151,11 @@ class SeopardyGame(QtGui.QWidget):
wasAnswered = (answers is not None and answers.is_answered())
question = self.questions.get_question(section, number)
if question["Double-Jeopardy"]:
if not wasAnswered and question["Double-Jeopardy"]:
print("maunz")
return
dwin = DoubleJeopardyWindow(self.players, number*100, self.currentPlayer, parent=self)
dwin.exec_()
qwin = QuestionWindow(self.players, section, number, question, answers, self)
qwin.showFullScreen()
@ -168,6 +170,9 @@ class SeopardyGame(QtGui.QWidget):
self._set_player_points(answers)
if answers.get_winner():
self.currentPlayer = answers.get_winner()
# restyle the button
self._restyle_button(section, number, answers)

View File

@ -48,6 +48,12 @@ class QuestionAnswers(object):
def add_try(self, player, correct):
self.tries.append((player, correct))
def get_winner(self):
for player, correct in self.tries:
if correct:
return player
return None
def points(self):
return self.qnumber*100

View File

@ -367,9 +367,15 @@ class VictoryWindow(QtGui.QDialog):
class DoubleJeopardyWindow(QtGui.QDialog):
def __init__(self, player, parent=None):
super(QuestionAnswerWindow, self).__init__(parent)
self.player = player
def __init__(self, player, points, current_player=None, current_points=None, parent=None):
super(DoubleJeopardyWindow, self).__init__(parent)
self._player = player
self._currentPlayer = current_player
self._points = points
if current_points:
self._currentPoints = current_points
else:
self._currentPoints = points
self._setupGui()
@ -379,29 +385,72 @@ class DoubleJeopardyWindow(QtGui.QDialog):
cPos = self.rect()
self.move(g.width() - cPos.width(), g.height() - cPos.height())
def get_chosen_points(self):
return self._currentPoints
def get_player(self):
return self._currentPlayer
def _setupGui(self):
self.layout = QtGui.QVBoxLayout()
header = QtGui.QLabel("Double Jeopardy", self)
header.setStyleSheet("QLabel { font-size: 50px; }")
self.layout.addWidget(header, alignment=QtCore.Qt.AlignCenter)
self.pbtn = QtGui.QPushButton(self.player.name)
self.plabel.setStyleSheet("QLabel { font-size: 60px; }")
self.layout.addWidget(self.plabel, alignment=QtCore.Qt.AlignCenter)
self.pbtn = QtGui.QPushButton("", self)
self._stylePlayerButton()
self.pbtn.installEventFilter(KeyGrabber((QtCore.Qt.Key.Key_Left, QtCore.Qt.Key.Key_Right), self))
self.layout.addWidget(self.pbtn)
btnbox = QtGui.QHBoxLayout()
right = QtGui.QPushButton("Correct")
right.clicked.connect(lambda: self.done(self.CORRECT))
btnbox.addWidget(right)
wrong = QtGui.QPushButton("Wrong")
wrong.clicked.connect(lambda: self.done(self.WRONG))
btnbox.addWidget(wrong)
btnbox.addStretch()
oops = QtGui.QPushButton("Oops")
oops.clicked.connect(lambda: self.done(self.OOPS))
btnbox.addWidget(oops)
self.layout.addLayout(btnbox)
self.pointsbtn = QtGui.QPushButton("% 5s" % self._currentPoints)
self.pointsbtn.setStyleSheet("QPushButton { font-size: 50px; border: none; }")
self.pointsbtn.installEventFilter(KeyGrabber((QtCore.Qt.Key.Key_Left, QtCore.Qt.Key.Key_Right), self))
self.layout.addWidget(self.pointsbtn, alignment=QtCore.Qt.AlignCenter)
self.pointsbtn.setFocus()
start = QtGui.QPushButton("Done", self)
start.clicked.connect(self.close)
self.layout.addWidget(start)
self.setLayout(self.layout)
def _
def keyPressEvent(self, e):
if e.key() == QtCore.Qt.Key_Escape or e.key() == QtCore.Qt.Key_Enter:
self.close()
elif e.key() == QtCore.Qt.Key_Left or e.key() == QtCore.Qt.Key_Right:
if self.focusWidget() == self.pbtn:
if e.key() == QtCore.Qt.Key_Right:
if self._currentPlayer == None:
self._currentPlayer = self._player[0]
elif self._currentPlayer == self._player[-1]:
self._currentPlayer = None
else:
self._currentPlayer = self._player[self._player.index(self._currentPlayer)+1]
elif e.key() == QtCore.Qt.Key_Left:
if self._currentPlayer == None:
self._currentPlayer = self._player[-1]
elif self._currentPlayer == self._player[0]:
self._currentPlayer = None
else:
self._currentPlayer = self._player[self._player.index(self._currentPlayer)-1]
self._stylePlayerButton()
elif self.focusWidget() == self.pointsbtn:
if e.key() == QtCore.Qt.Key_Right and self._currentPoints < self._points*2:
self._currentPoints += 50
elif e.key() == QtCore.Qt.Key_Left and self._currentPoints > self._points/2:
self._currentPoints += -50
self.pointsbtn.setText("% 4s" % self._currentPoints)
def _stylePlayerButton(self):
player = None
color = None
if self._currentPlayer == None:
player = "nobody"
color = nobodyColor
else:
player = self._currentPlayer.name
color = self._currentPlayer.color
self.pbtn.setText(player)
self.pbtn.setStyleSheet("QPushButton { background-color: %s; color: white; font-size: 50px; border: none; }" % (color.name(),))