import sys
from PyQt4 import QtGui, QtCore, uic
import random
field = [[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1],[0,1,0,1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1,0,1,0]]
class Window(QtGui.QWidget):
def __init__(self, parent=None):
super(Window, self).__init__()
QtGui.QWidget.__init__(self, parent)
QtGui.QMainWindow.__init__(self)
self.setGeometry(300, 100, 250, 150)
self.setFixedHeight(600)
self.setFixedWidth(600)
self.center()
self.setWindowTitle('Пентикс')
self.setWindowIcon(QtGui.QIcon('ico.png'))
label = QtGui.QLabel('Следующая фигура:', self)
label.move(15, 10)
Figure(self)
Button(self)
def drawall(self):
for i in range(len(field)):
for j in range(len(field[0])):
field[i][j] = random.randint(0,1)
return field
def paintEvent(self, event):
paint = QtGui.QPainter(self)
pen = QtGui.QPen(QtCore.Qt.black, 1, QtCore.Qt.SolidLine)
paint.setPen(pen)
for i in range(len(field)+1):
paint.drawLine(150, (i+1)*24+10, 540, (i+1)*24+10)
for i in range(len(field[0])+1):
paint.drawLine((i+1)*30+120, 34, (i+1)*30+120, 562)
color = QtGui.QColor(0, 0, 0)
color.setNamedColor('#d4d4d4')
paint.setPen(color)
paint.setBrush(QtGui.QColor(255, 0, 0, 100))
self.drawrectangles(paint)
paint.end()
def drawrectangles(self, paint):
for i in range(len(field)):
for j in range(len(field[i])):
if field[i][j] == 1:
paint.drawRect((j+1)*30+122, (i+1)*24+12, 26, 20)
def center(self):
screen = QtGui.QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2)
class Figure(QtGui.QWidget):
def __init__(self, parent):
QtGui.QWidget.__init__(self, parent)
class Button(QtGui.QWidget):
def __init__(self, parent):
QtGui.QWidget.__init__(self, parent)
quit = QtGui.QPushButton('Выход', self)
quit.setGeometry(10, 550, 70, 35)
self.connect(quit, QtCore.SIGNAL('clicked()'),
QtGui.qApp, QtCore.SLOT('quit()'))
pause = QtGui.QPushButton('Пауза', self)
pause.setGeometry(10,500,70,35)
self.connect(pause, QtCore.SIGNAL("clicked()"),
self.pause)
newGame = QtGui.QPushButton('Новая игра', self)
newGame.setGeometry(10,450,70,35)
self.connect(newGame, QtCore.SIGNAL("clicked()"),
self.newGame)
def pause(self):
print('пауза')
Window().drawall()
def newGame(self):
print('Новая игра')
app = QtGui.QApplication(sys.argv)
wd = Window()
wd.show()
sys.exit(app.exec_())