Flask of Rum - Slot Game
import Felgo 4.0
import QtQuick 2.0
import "../config"
Item {
id: winningLine
anchors.fill: parent
property alias image: lineImage
property string color
property var positions: []
property int winAmount
property var __winningPositions: []
property var __winningTypes: []
property var __lineSymbols: []
Image {
id: lineImage
anchors.fill: parent
}
Item {
id: symbolArea
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
Text {
id: winText
x: 15
color: "black"
text: winAmount
font.pixelSize: 10
z: 2
}
Rectangle {
width: winText.width + 20
height: winText.height + 4
anchors.centerIn: winText
color: winningLine.color
z: 1
}
}
function drawLineSymbols(machine) {
removeLineSymbols()
symbolArea.width = machine.width
symbolArea.height = machine.height
var yOffset = 5
for(var i = 0; i < winningLine.__winningPositions.length; i++) {
var properties = {
color: winningLine.color,
x: Math.round((machine.defaultReelWidth * winningLine.__winningPositions[i].reel)),
y: Math.round((machine.defaultItemHeight * winningLine.__winningPositions[i].row) + yOffset),
width: machine.defaultReelWidth,
height: machine.defaultItemHeight - 10,
type: winningLine.__winningTypes[i]
}
var component = Qt.createComponent(Qt.resolvedUrl("LineSymbol.qml"))
var symbol = component.createObject(symbolArea, properties)
winningLine.__lineSymbols.push(symbol)
}
if(__winningPositions[0].row === 0) {
winText.y = winningLine.__lineSymbols[0].y + winningLine.__lineSymbols[0].height
}
else {
winText.y = winningLine.__lineSymbols[0].y - winText.height
}
}
function removeLineSymbols() {
for(var i = 0; i < winningLine.__lineSymbols.length; i++) {
winningLine.__lineSymbols[i].destroy()
}
winningLine.__lineSymbols = []
}
function validate(machine) {
var length = 0
var currentType = null
__winningPositions = []
__winningTypes = []
for(var i = 0; i < positions.length; i++) {
var pos = positions[i]
if(pos === null)
return false
var symbol = machine.getItemData(pos.reel, pos.row)
if(symbol === null)
return false
if(i == 0) {
currentType = symbol.type
length = 1
}
else {
if(currentType !== symbol.type && symbol.type !== "rum" && currentType !== "rum") {
break;
}
if(currentType === "rum")
currentType = symbol.type
length++;
}
__winningPositions.push(pos)
__winningTypes.push(symbol.type)
}
if(length < 3)
return false
var winFactor = SymbolConfig.getWinFactor(currentType, length)
winAmount = scene.betAmount * winFactor
winningLine.drawLineSymbols(machine)