seopardy/game.py

73 lines
2.1 KiB
Python

from __future__ import print_function
from PySide import QtCore, QtGui
from player import Player
from windows import QuestionWindow
class SeopardyGame(QtGui.QWidget):
def __init__(self, questions, gamestate, parent=None):
super(SeopardyGame, self).__init__(parent)
self.questions = questions
self.gamestate = gamestate
self.players = [Player.gen_player(i) for i in range(1, 4)]
self._createGui()
self.showFullScreen()
def _createGui(self):
""" Create the board from questions. """
layout = QtGui.QVBoxLayout()
headerLayout = QtGui.QHBoxLayout()
header = QtGui.QLabel("Header")
headerLayout.addWidget(header)
headerLayout.setSizeConstraint(QtGui.QLayout.SetMinimumSize)
layout.addWidget(header, alignment=QtCore.Qt.AlignCenter)
# create board
#board = QtGui.QGridLayout(6, len(self.questions.get_sections()))
board = QtGui.QGridLayout()
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)
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.clicked.connect(lambda sec=sec, j=j: self.tfunc(sec, j+1))
board.addWidget(b, j+1, i)
layout.addLayout(board)
# create player bar
self.playerBar = QtGui.QHBoxLayout()
for i, player in enumerate(self.players):
self.playerBar.addWidget(player)
if i != len(self.players)-1:
self.playerBar.addStretch()
layout.addLayout(self.playerBar)
self.setLayout(layout)
def keyPressEvent(self, e):
print("Mainwindow", e)
if e.key() == QtCore.Qt.Key_Escape:
self.close()
def tfunc(self, section, number):
print("question window", section, number)
qwin = QuestionWindow(self.players, section, number, self.questions.get_question(section, number), self)
qwin.showFullScreen()
qwin.exec_()
results = qwin.get_results()
for result in results:
print("result", result)