Complete DJ-Window + "who's turn is it"
This commit is contained in:
parent
88fdac4cd2
commit
48a3bd6a93
11
game.py
11
game.py
|
@ -3,7 +3,7 @@ from __future__ import print_function
|
||||||
from PySide import QtCore, QtGui
|
from PySide import QtCore, QtGui
|
||||||
|
|
||||||
from player import Player, nobodyColor
|
from player import Player, nobodyColor
|
||||||
from windows import QuestionWindow, EditAnswersWindow, PlayerStartWindow, VictoryWindow
|
from windows import QuestionWindow, EditAnswersWindow, PlayerStartWindow, VictoryWindow, DoubleJeopardyWindow
|
||||||
from gamestate import QuestionAnswers
|
from gamestate import QuestionAnswers
|
||||||
|
|
||||||
class SeopardyGame(QtGui.QWidget):
|
class SeopardyGame(QtGui.QWidget):
|
||||||
|
@ -16,6 +16,7 @@ class SeopardyGame(QtGui.QWidget):
|
||||||
self.players = []
|
self.players = []
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
self.add_player()
|
self.add_player()
|
||||||
|
self.currentPlayer = None
|
||||||
|
|
||||||
self._inOtherWindow = False
|
self._inOtherWindow = False
|
||||||
self._createGui()
|
self._createGui()
|
||||||
|
@ -150,10 +151,11 @@ class SeopardyGame(QtGui.QWidget):
|
||||||
wasAnswered = (answers is not None and answers.is_answered())
|
wasAnswered = (answers is not None and answers.is_answered())
|
||||||
|
|
||||||
question = self.questions.get_question(section, number)
|
question = self.questions.get_question(section, number)
|
||||||
if question["Double-Jeopardy"]:
|
if not wasAnswered and question["Double-Jeopardy"]:
|
||||||
print("maunz")
|
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 = QuestionWindow(self.players, section, number, question, answers, self)
|
||||||
qwin.showFullScreen()
|
qwin.showFullScreen()
|
||||||
|
@ -168,6 +170,9 @@ class SeopardyGame(QtGui.QWidget):
|
||||||
|
|
||||||
self._set_player_points(answers)
|
self._set_player_points(answers)
|
||||||
|
|
||||||
|
if answers.get_winner():
|
||||||
|
self.currentPlayer = answers.get_winner()
|
||||||
|
|
||||||
# restyle the button
|
# restyle the button
|
||||||
self._restyle_button(section, number, answers)
|
self._restyle_button(section, number, answers)
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,12 @@ class QuestionAnswers(object):
|
||||||
def add_try(self, player, correct):
|
def add_try(self, player, correct):
|
||||||
self.tries.append((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):
|
def points(self):
|
||||||
return self.qnumber*100
|
return self.qnumber*100
|
||||||
|
|
||||||
|
|
87
windows.py
87
windows.py
|
@ -367,9 +367,15 @@ class VictoryWindow(QtGui.QDialog):
|
||||||
|
|
||||||
|
|
||||||
class DoubleJeopardyWindow(QtGui.QDialog):
|
class DoubleJeopardyWindow(QtGui.QDialog):
|
||||||
def __init__(self, player, parent=None):
|
def __init__(self, player, points, current_player=None, current_points=None, parent=None):
|
||||||
super(QuestionAnswerWindow, self).__init__(parent)
|
super(DoubleJeopardyWindow, self).__init__(parent)
|
||||||
self.player = player
|
self._player = player
|
||||||
|
self._currentPlayer = current_player
|
||||||
|
self._points = points
|
||||||
|
if current_points:
|
||||||
|
self._currentPoints = current_points
|
||||||
|
else:
|
||||||
|
self._currentPoints = points
|
||||||
|
|
||||||
self._setupGui()
|
self._setupGui()
|
||||||
|
|
||||||
|
@ -379,29 +385,72 @@ class DoubleJeopardyWindow(QtGui.QDialog):
|
||||||
cPos = self.rect()
|
cPos = self.rect()
|
||||||
self.move(g.width() - cPos.width(), g.height() - cPos.height())
|
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):
|
def _setupGui(self):
|
||||||
self.layout = QtGui.QVBoxLayout()
|
self.layout = QtGui.QVBoxLayout()
|
||||||
|
|
||||||
header = QtGui.QLabel("Double Jeopardy", self)
|
header = QtGui.QLabel("Double Jeopardy", self)
|
||||||
|
header.setStyleSheet("QLabel { font-size: 50px; }")
|
||||||
self.layout.addWidget(header, alignment=QtCore.Qt.AlignCenter)
|
self.layout.addWidget(header, alignment=QtCore.Qt.AlignCenter)
|
||||||
|
|
||||||
self.pbtn = QtGui.QPushButton(self.player.name)
|
self.pbtn = QtGui.QPushButton("", self)
|
||||||
self.plabel.setStyleSheet("QLabel { font-size: 60px; }")
|
self._stylePlayerButton()
|
||||||
self.layout.addWidget(self.plabel, alignment=QtCore.Qt.AlignCenter)
|
self.pbtn.installEventFilter(KeyGrabber((QtCore.Qt.Key.Key_Left, QtCore.Qt.Key.Key_Right), self))
|
||||||
|
self.layout.addWidget(self.pbtn)
|
||||||
|
|
||||||
btnbox = QtGui.QHBoxLayout()
|
self.pointsbtn = QtGui.QPushButton("% 5s" % self._currentPoints)
|
||||||
right = QtGui.QPushButton("Correct")
|
self.pointsbtn.setStyleSheet("QPushButton { font-size: 50px; border: none; }")
|
||||||
right.clicked.connect(lambda: self.done(self.CORRECT))
|
self.pointsbtn.installEventFilter(KeyGrabber((QtCore.Qt.Key.Key_Left, QtCore.Qt.Key.Key_Right), self))
|
||||||
btnbox.addWidget(right)
|
self.layout.addWidget(self.pointsbtn, alignment=QtCore.Qt.AlignCenter)
|
||||||
wrong = QtGui.QPushButton("Wrong")
|
self.pointsbtn.setFocus()
|
||||||
wrong.clicked.connect(lambda: self.done(self.WRONG))
|
|
||||||
btnbox.addWidget(wrong)
|
start = QtGui.QPushButton("Done", self)
|
||||||
btnbox.addStretch()
|
start.clicked.connect(self.close)
|
||||||
oops = QtGui.QPushButton("Oops")
|
self.layout.addWidget(start)
|
||||||
oops.clicked.connect(lambda: self.done(self.OOPS))
|
|
||||||
btnbox.addWidget(oops)
|
|
||||||
self.layout.addLayout(btnbox)
|
|
||||||
|
|
||||||
self.setLayout(self.layout)
|
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(),))
|
||||||
|
|
Loading…
Reference in New Issue