main.qml Example File
scriptgame/assets/main.qml
import bb.cascades 1.0
Page {
Container {
layout: DockLayout {}
ImageView {
horizontalAlignment: HorizontalAlignment.Fill
verticalAlignment: verticalAlignment.Fill
imageSource: "asset:///images/background.png"
}
Container {
horizontalAlignment: HorizontalAlignment.Fill
verticalAlignment: verticalAlignment.Fill
leftPadding: 30
topPadding: 30
rightPadding: 30
bottomPadding: 30
Container {
horizontalAlignment: HorizontalAlignment.Center
layoutProperties: StackLayoutProperties {
spaceQuota: 1
}
layout: DockLayout {}
Maze {
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: verticalAlignment.Center
}
TextArea {
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: verticalAlignment.Center
preferredWidth: 400
preferredHeight: 400
opacity: _gameController.scriptError == "" ? 0.0 : 1.0
backgroundVisible: false
text: _gameController.scriptError
textStyle {
base: SystemDefaults.TextStyles.BigText
color: Color.White
textAlign: TextAlign.Center
}
}
}
Container {
horizontalAlignment: HorizontalAlignment.Fill
layoutProperties: StackLayoutProperties {
spaceQuota: 1
}
DropDown {
horizontalAlignment: HorizontalAlignment.Center
title: qsTr ("Scripts")
Option {
text: qsTr ("Simple moves")
onSelectedChanged: {
if (selected == true) {
scriptContent.text = "board.reset()\n" +
"player.turnLeft()\n" +
"player.go()\n" +
"player.turnRight()\n" +
"player.go()\n" +
"player.go()\n" +
"player.go()\n" +
"player.turnLeft()\n"
}
}
}
Option {
text: qsTr ("Random maze")
onSelectedChanged: {
if (selected == true) {
scriptContent.text = "board.staticBlockDistribution = false\n" +
"board.reset()\n" +
"board.staticBlockDistribution = true\n" +
"player.reset()\n"
}
}
}
Option {
text: qsTr ("New Player")
onSelectedChanged: {
if (selected == true) {
scriptContent.text = "board.reset()\n" +
"player.turnLeft()\n" +
"player.go()\n" +
"player.turnRight()\n" +
"player.go()\n" +
"var p = new Player(board)\n" +
"p.turnLeft()\n" +
"p.go()\n" +
"p.turnRight()\n" +
"p.go()\n" +
"p.go()\n" +
"p.go()"
}
}
}
Option {
text: qsTr ("Reset Engine")
onSelectedChanged: {
if (selected == true) {
scriptContent.text = "controller.reset()"
}
}
}
}
TextArea {
id: scriptContent
horizontalAlignment: HorizontalAlignment.Fill
layoutProperties: StackLayoutProperties {
spaceQuota: 1
}
hintText: ""
}
Button {
horizontalAlignment: HorizontalAlignment.Center
text: qsTr ("Run Script")
onClicked: _gameController.run(scriptContent.text)
}
}
}
}
}