Flask of Rum - Slot Game
import Felgo 4.0
import QtQuick 2.0
import "slotmachine"
GameWindow {
id: gameWindow
activeScene: scene
screenWidth: 960
screenHeight: 640
Scene {
id: scene
width: 480
height: 320
property int betAmount: 4
property int creditAmount: 400
Behavior on creditAmount {
PropertyAnimation { duration: scene.betAmount * 50 }
}
Rectangle {
anchors.fill: scene.gameWindowAnchorItem
color: "#400000"
}
FlaskOfRumMachine {
id: slotMachine
anchors.horizontalCenter: scene.horizontalCenter
anchors.top: topBar.bottom
anchors.topMargin: -10
height: scene.gameWindowAnchorItem.height - (topBar.height + anchors.topMargin) - (bottomBar.height - 10)
defaultItemHeight: Math.round(slotMachine.height / slotMachine.rowCount)
defaultReelWidth: Math.round(defaultItemHeight / 80 * 67)
spinVelocity: Math.round(defaultItemHeight / 80 * 750)
onSpinEnded: scene.spinEnded()
onSpinStarted: {
slotMachine.reelStopDelay = utils.generateRandomValueBetween(350, 700)
}
}
WinValidator {
id: winValidator
height: slotMachine.height
width: Math.round(height / 240 * 408)
anchors.centerIn: scene.gameWindowAnchorItem
}
TopBar {
id: topBar
width: scene.gameWindowAnchorItem.width
anchors.top: scene.gameWindowAnchorItem.top
anchors.horizontalCenter: scene.gameWindowAnchorItem.horizontalCenter
}
BottomBar {
id: bottomBar
width: scene.gameWindowAnchorItem.width
anchors.bottom: scene.gameWindowAnchorItem.bottom
anchors.horizontalCenter: scene.gameWindowAnchorItem.horizontalCenter
onStartClicked: scene.startSlotMachine()
onAutoClicked: scene.autoPlaySlotMachine()
onIncreaseBetClicked: scene.increaseBetAmount()
onDecreaseBetClicked: scene.decreaseBetAmount()
onMaxBetClicked: scene.maxBetAmount()
}
function increaseBetAmount() {
if(bottomBar.startActive)
return
if (betAmount < 5 && creditAmount >= 5)
betAmount = 5
else if (betAmount < 8 && creditAmount >= 8)
betAmount = 8
else if (betAmount < 10 && creditAmount >= 10)
betAmount = 10
else if (betAmount < 15 && creditAmount >= 15)
betAmount = 15
else if (betAmount < 20 && creditAmount >= 20)
betAmount = 20
}
function decreaseBetAmount() {
if(bottomBar.startActive)
return
if (betAmount > 15 && creditAmount >= 15)
betAmount = 15
else if (betAmount > 10 && creditAmount >= 10)
betAmount = 10
else if (betAmount > 8 && creditAmount >= 8)
betAmount = 8
else if (betAmount > 5 && creditAmount >= 5)
betAmount = 5
else if (betAmount > 4)
betAmount = 4
}
function maxBetAmount() {
if(bottomBar.startActive)
return
if(creditAmount >= 20)
betAmount = 20
else if(creditAmount >= 15)
betAmount = 15
else if(creditAmount >= 10)
betAmount = 10
else if(creditAmount >= 8)
betAmount = 8
else if(creditAmount >= 5)
betAmount = 5
else if(creditAmount >= 4)
betAmount = 4
}
function autoPlaySlotMachine() {
bottomBar.autoActive = !bottomBar.autoActive
if(bottomBar.autoActive)
startSlotMachine()
}
function startSlotMachine() {
if(!slotMachine.spinning && scene.creditAmount >= scene.betAmount) {
bottomBar.startActive = true
scene.creditAmount -= scene.betAmount
winValidator.reset()
var stopInterval = utils.generateRandomValueBetween(500, 1000)
slotMachine.spin(stopInterval)
}
}
function spinEnded() {
bottomBar.startActive = false
var won = winValidator.validate(slotMachine)
if(won)
winValidator.showWinningLines()
else if(bottomBar.autoActive)
startSlotMachine()