aboutsummaryrefslogtreecommitdiffstats
path: root/examples/widgets/state-machine/rogue/rogue.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/state-machine/rogue/rogue.py')
-rw-r--r--examples/widgets/state-machine/rogue/rogue.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/examples/widgets/state-machine/rogue/rogue.py b/examples/widgets/state-machine/rogue/rogue.py
index 67caef1f0..5bbc7dabc 100644
--- a/examples/widgets/state-machine/rogue/rogue.py
+++ b/examples/widgets/state-machine/rogue/rogue.py
@@ -51,6 +51,7 @@ class MovementTransition(QEventTransition):
def __init__(self, window):
super().__init__(window, QEvent.KeyPress)
self.window = window
+
def eventTest(self, event):
if event.type() == QEvent.StateMachineWrapped and \
event.event().type() == QEvent.KeyPress:
@@ -58,6 +59,7 @@ class MovementTransition(QEventTransition):
return key == Qt.Key_2 or key == Qt.Key_8 or \
key == Qt.Key_6 or key == Qt.Key_4
return False
+
def onTransition(self, event):
key = event.event().key()
if key == Qt.Key_4:
@@ -69,6 +71,7 @@ class MovementTransition(QEventTransition):
if key == Qt.Key_2:
self.window.move_player(self.window.down)
+
class Custom(QState):
def __init__(self, parent, mw):
super().__init__(parent)
@@ -77,6 +80,7 @@ class Custom(QState):
def onEntry(self, e):
print(self.mw.status)
+
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
@@ -98,6 +102,7 @@ class MainWindow(QMainWindow):
self.setup_map()
self.build_machine()
self.show()
+
def setup_map(self):
self.map = []
generator = QRandomGenerator().global_()
@@ -150,6 +155,7 @@ class MainWindow(QMainWindow):
metrics = QFontMetrics(self.font())
return QSize(metrics.horizontalAdvance('X') * self.width,
metrics.height() * (self.height + 1))
+
def paintEvent(self, event):
metrics = QFontMetrics(self.font())
painter = QPainter(self)
@@ -171,6 +177,7 @@ class MainWindow(QMainWindow):
painter.drawText(QPoint(x_pos, y_pos), self.map[x][y])
x_pos += font_width
painter.drawText(QPoint(self.pX * font_width, (self.pY + 2) * font_height), '@')
+
def move_player(self, direction):
if direction == self.left:
if self.map[self.pX - 1][self.pY] != '#':
@@ -185,8 +192,10 @@ class MainWindow(QMainWindow):
if self.map[self.pX][self.pY + 1] != '#':
self.pY += 1
self.repaint()
+
def get_status(self):
return self._status_str
+
def set_status(self, status):
self._status_str = status
self.repaint()
@@ -198,6 +207,7 @@ class MainWindow(QMainWindow):
width = 35
height = 20
+
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)